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
IAICallerinterface - 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:
-
Network Failures: Timeout during InitiateCall or GetCallStatus
- Retry logic with exponential backoff
- Maximum retry attempts configurable
- After max retries, mark as Failed and escalate
-
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
-
Invalid Numbers: Lead phone number fails validation
- Detect before API call
- Mark as Failed with specific error code
- Flag for data quality review
-
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:
- Create a new task in the manual staff assignment queue
- Set task priority based on failure reason
- Assign to available telecaller based on load balancing
- Link original lead and failed call attempt for context
Configuration
The AI Auto-Caller Pipeline requires the following configuration settings:
| Setting | Description | Example |
|---|---|---|
AICallerProviderType | Fully qualified class name of provider | MMS.TeleCallers.AICallers.MillisAIAutoCaller |
AICallerSchedulerInterval | Scheduler polling interval in seconds | 30 |
AICallStatusPollInterval | Status polling interval in seconds | 5 |
AICallMaxPollingDuration | Maximum time to poll status in minutes | 30 |
AICallMaxRetries | Maximum retry attempts for failed calls | 3 |
AICallRetryBackoffMultiplier | Exponential backoff multiplier | 2.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
Statuscolumn 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
Leadmodel: Defines lead data passed to AI callerIAICallerinterface: Contract for all AI provider implementationsMillisAIAutoCaller: Reference implementation for Millis AI servicePostPendingLeadsToAIScheduler: Periodic task that triggers the pipeline