Telecaller & Leads
AI Auto-Caller
Auto-Caller Pipeline

AI Auto-Caller Pipeline

The AI Auto-Caller Pipeline is the core orchestration system that manages the entire lifecycle of AI-powered outbound calls in the telecaller module. It uses a factory pattern to instantiate appropriate AI caller providers and coordinates lead routing from initial qualification through call completion and fallback handling.

Overview

The pipeline automates the routing of qualified leads to AI callers with built-in status tracking, error handling, and fallback mechanisms for manual staff assignment. The system runs asynchronously, checking for pending leads at regular intervals and maintaining detailed call status records.

Architecture

Factory Pattern

The AIAutoCallerFactory class manages the instantiation and caching of AI caller provider instances:

  • Provider Class Resolution: The factory reads the provider class name from application configuration
  • Reflection-Based Instantiation: Uses .NET reflection to dynamically create instances of the configured provider class
  • Instance Caching: Caches instantiated providers to avoid repeated reflection calls
  • Interface Compliance: All providers must implement the common IAICaller interface
  • Configuration-Driven: The factory enables switching between different AI providers without code changes

Provider Interface

All AI caller implementations conform to the IAICaller interface with the following contract:

interface IAICaller
{
    Task<CallInitiationResponse> InitiateCall(Lead lead, string script);
    Task<CallStatusResponse> GetCallStatus(string callId);
    Task<CallRecordingResponse> GetCallRecording(string callId);
}

Status Tracking System

The AI call lifecycle is tracked through distinct status states:

  • Pending_AI_Call: Lead qualifies for AI calling, awaiting scheduler pickup
  • Processing: Call has been initiated, awaiting completion
  • Completed: Call successfully completed
  • Failed: Call failed or was not completed successfully

Pipeline Flow

Detailed Sequence Diagram

The following sequence diagram shows the factory instantiation and call initiation process:

AI Call Status State Diagram

Error Handling and Resilience

Failure Scenarios

The pipeline handles multiple failure modes:

  1. Network Failures: Timeout during InitiateCall or GetCallStatus

    • Retry logic with exponential backoff
    • Maximum retry attempts configurable
    • After max retries, mark as Failed and escalate
  2. API Errors: Millis AI API returns error response

    • Log error details and response code
    • Determine if retryable (5xx) or terminal (4xx) error
    • Escalate terminal errors to manual assignment
  3. Invalid Numbers: Lead phone number fails validation

    • Detect before API call
    • Mark as Failed with specific error code
    • Flag for data quality review
  4. Status Unknown: GetCallStatus returns uncertain state

    • Query again after brief delay
    • Maximum wait time before marking as failed
    • Prevents infinite polling

Fallback to Manual Staff

When an AI call fails:

  1. Create a new task in the manual staff assignment queue
  2. Set task priority based on failure reason
  3. Assign to available telecaller based on load balancing
  4. Link original lead and failed call attempt for context

Configuration

The AI Auto-Caller Pipeline requires the following configuration settings:

SettingDescriptionExample
AICallerProviderTypeFully qualified class name of providerMMS.TeleCallers.AICallers.MillisAIAutoCaller
AICallerSchedulerIntervalScheduler polling interval in seconds30
AICallStatusPollIntervalStatus polling interval in seconds5
AICallMaxPollingDurationMaximum time to poll status in minutes30
AICallMaxRetriesMaximum retry attempts for failed calls3
AICallRetryBackoffMultiplierExponential backoff multiplier2.0

Performance Considerations

  • Batch Processing: The scheduler processes multiple pending leads in each cycle
  • Async/Await: All API calls are non-blocking to prevent scheduler thread starvation
  • Connection Pooling: HTTP client reused across multiple InitiateCall requests
  • Caching: Provider instances cached to avoid repeated reflection
  • Database Indexing: Ensure Status column is indexed for fast querying of pending leads

Monitoring and Observability

Key metrics to monitor:

  • Leads processed per scheduler cycle
  • Success rate of InitiateCall
  • Average polling duration until completion
  • Failure rate by error type
  • Manual escalation rate
  • API response time percentiles (p50, p95, p99)

Related Components

  • Lead model: Defines lead data passed to AI caller
  • IAICaller interface: Contract for all AI provider implementations
  • MillisAIAutoCaller: Reference implementation for Millis AI service
  • PostPendingLeadsToAIScheduler: Periodic task that triggers the pipeline