### Complete Example Configuration File Source: https://github.com/microsoft/call-center-ai/blob/main/_autodocs/03-configuration.md A comprehensive example of a configuration file (config.yaml) showing all available settings for various services like AI Search, Translation, Cognitive Services, Communication Services, Database, LLM, Queue, SMS, Conversation, App Configuration, and Resources. ```yaml # config.yaml public_domain: "https://example.com" version: "1.0.0" ai_search: endpoint: "https://example.search.windows.net" api_key: "${AI_SEARCH_API_KEY}" index_name: "documents" ai_translation: endpoint: "https://api.cognitive.microsofttranslator.com" api_key: "${AI_TRANSLATION_API_KEY}" region: "westeurope" cognitive_service: endpoint: "https://westeurope.tts.speech.microsoft.com" api_key: "${COGNITIVE_SERVICE_API_KEY}" region: "westeurope" communication_services: endpoint: "https://xxx.communication.azure.com" access_key: "${COMMUNICATION_SERVICES_ACCESS_KEY}" phone_number: "+33612345678" resource_id: "/subscriptions/xxx/resourceGroups/xxx/providers/Microsoft.Communication/communicationServices/xxx" database: endpoint: "https://xxx.documents.azure.com:443/" api_key: "${COSMOS_DB_API_KEY}" database: "call-center" container: "calls" llm: fast: endpoint: "https://xxx.openai.azure.com" api_key: "${LLM_FAST_API_KEY}" deployment: "gpt-4-1-mini" max_tokens: 2000 slow: endpoint: "https://yyy.openai.azure.com" api_key: "${LLM_SLOW_API_KEY}" deployment: "gpt-4-1" max_tokens: 4000 queue: connection_string: "${AZURE_STORAGE_CONNECTION_STRING}" call_queue_name: "call-events" post_queue_name: "post-events" sms_queue_name: "sms-events" training_queue_name: "training-events" sms: mode: "azure" conversation: initiate: bot_name: "Amélie" bot_company: "Contoso" agent_phone_number: "+33698765432" task: "Help the customer with their insurance claim" lang: default_short_code: "fr-FR" app_configuration: connection_string: "${APP_CONFIGURATION_CONNECTION_STRING}" ttl_sec: 60 resources: sounds_container_url: "https://xxx.blob.core.windows.net/sounds" recordings_container_url: "https://xxx.blob.core.windows.net/recordings" ``` -------------------------------- ### Configuration Example Source: https://github.com/microsoft/call-center-ai/blob/main/_autodocs/README.md Example of AI Search configuration settings in YAML format. This includes the endpoint and API key required for connecting to the AI Search service. ```yaml # Configuration example ai_search: endpoint: "https://example.search.windows.net" api_key: "xxx" ``` -------------------------------- ### REST API Example Source: https://github.com/microsoft/call-center-ai/blob/main/_autodocs/README.md Example of how to make a POST request to the REST API for call management. Ensure to set the Content-Type header and provide a JSON payload. ```bash # REST API example curl -X POST http://localhost:8080/call \ -H "Content-Type: application/json" \ -d '{...}' ``` -------------------------------- ### Start the Call Center AI Server Source: https://github.com/microsoft/call-center-ai/blob/main/_autodocs/00-index.md Run the main application module using Python to start the server. The server will be accessible at `http://localhost:8080`. ```bash python -m app.main # Server runs on http://localhost:8080 ``` -------------------------------- ### Install Python Packages Source: https://github.com/microsoft/call-center-ai/blob/main/examples/blocklist.ipynb Install the required Azure SDKs and pandas library for the project. This command ensures specific versions are used for compatibility. ```python %pip install azure-identity==1.15.0 azure-ai-contentsafety==1.0.0 pandas==2.2.0 ``` -------------------------------- ### Python: Handle Play Started Event Source: https://github.com/microsoft/call-center-ai/blob/main/_autodocs/05-workflows-and-handlers.md Records that audio playback has started and updates the call state. Triggered by the `Microsoft.Communication.PlayStarted` CloudEvent. ```python async def on_play_started( call: CallStateModel, scheduler: Scheduler, ) -> None: # Records that audio playback started # Updates call state pass ``` -------------------------------- ### Start Azure Dev Tunnel Source: https://github.com/microsoft/call-center-ai/blob/main/README.md Starts a tunnel for connecting to your local development environment. This must be run in a separate terminal and kept running. ```zsh # Start the tunnel make tunnel ``` -------------------------------- ### AI Search Configuration Example Source: https://github.com/microsoft/call-center-ai/blob/main/_autodocs/03-configuration.md Example YAML configuration for Azure AI Search, specifying endpoint, API key, index name, and search parameters. ```yaml ai_search: endpoint: https://example.search.windows.net api_key: "xxxx" index_name: documents search_top_k: 5 strictness: 0.5 expansion_n_messages: 3 ``` -------------------------------- ### System Prompt Template Example Source: https://github.com/microsoft/call-center-ai/blob/main/_autodocs/07-advanced-topics.md Defines a system prompt template using Jinja2 for placeholder substitution. Placeholders like bot name, company, date, and phone number can be dynamically inserted. ```yaml prompts: llm: default_system_tpl: | Assistant is called {bot_name} and works for {bot_company}. Today is {date}. Customer is calling from {phone_number}. ``` -------------------------------- ### Custom Prompt Templates Example Source: https://github.com/microsoft/call-center-ai/blob/main/_autodocs/07-advanced-topics.md Illustrates defining multiple custom prompt templates for text-to-speech. One template is randomly selected for each call, allowing for varied greetings. ```yaml prompts: tts: hello_tpl: - "Hello, I'm {bot_name} from {bot_company}!" - "Hi, this is {bot_name} speaking." ``` -------------------------------- ### Get Deployment Logs Source: https://github.com/microsoft/call-center-ai/blob/main/README.md Retrieve the deployment logs for the Call Center AI project using the Make command. Specify the resource group name. ```zsh make logs name=my-rg-name ``` -------------------------------- ### Python PhoneNumber Example Source: https://github.com/microsoft/call-center-ai/blob/main/_autodocs/README.md Example demonstrating the usage of the PhoneNumber class in Python to extract timezone information. This requires the PhoneNumber library to be installed. ```python # Python example phone = PhoneNumber("+33612345678") tz = PhoneNumber.tz(phone) ``` -------------------------------- ### Run Development Server with Hot-Reloading Source: https://github.com/microsoft/call-center-ai/blob/main/README.md Starts the development server with automatic code reloading on file changes. The API server will be accessible at http://localhost:8080. ```zsh make dev ``` -------------------------------- ### Example Error Response Source: https://github.com/microsoft/call-center-ai/blob/main/_autodocs/02-types.md Illustrates the JSON format for an error response, including a summary message and specific details about the error. This example is useful for understanding how to parse and handle API errors. ```json { "error": { "message": "Validation error", "details": ["Invalid phone number format"] } } ``` -------------------------------- ### Search Training Documents Source: https://github.com/microsoft/call-center-ai/blob/main/_autodocs/04-persistence-api.md Example of searching for training documents using the ISearch interface. Specify language, query text, and optionally use cache_only. ```python docs = await search.training_search_all( lang="fr-FR", text="Comment résilier mon contrat?", ) if docs: for doc in docs: print(f"[{doc.score}] {doc.title}: {doc.content}") ``` -------------------------------- ### Start Audio Streaming from Call Source: https://github.com/microsoft/call-center-ai/blob/main/_autodocs/06-helpers-and-utilities.md Initiates the capture of audio streams from an active call. Requires a CallAutomationClient and call connection ID. ```python async def start_audio_streaming( client: CallAutomationClient, call_connection_id: str, ) -> None: ... ``` -------------------------------- ### Message Merging Example Source: https://github.com/microsoft/call-center-ai/blob/main/_autodocs/07-advanced-topics.md Demonstrates how consecutive messages from the same persona with the same action are merged. This reduces LLM context size when streaming responses in multiple chunks. ```python [ MessageModel(persona=ASSISTANT, action=TALK, content="Hello"), MessageModel(persona=ASSISTANT, action=TALK, content="How are you?"), MessageModel(persona=HUMAN, action=TALK, content="I'm fine"), ] ``` ```python [ MessageModel(persona=ASSISTANT, action=TALK, content="Hello How are you?"), MessageModel(persona=HUMAN, action=TALK, content="I'm fine"), ] ``` -------------------------------- ### API Reference Documentation Source: https://github.com/microsoft/call-center-ai/blob/main/_autodocs/MANIFEST.txt This section outlines the structure and content of the generated API documentation, including details on type signatures, parameter descriptions, return types, usage examples, and error conditions. ```APIDOC ## API Documentation Structure ### Description Provides detailed information for every exported symbol, ensuring comprehensive coverage of the API surface. ### Content: - Full type signature - Parameter descriptions with types - Return type and description - Usage examples (code samples) - Source file location with line numbers - Related types and cross-references - Configuration examples (where applicable) - Error conditions and exceptions - Performance considerations ### Format: - Markdown with clear hierarchy - Code syntax highlighting - Tables for quick reference - Runnable examples - YAML configuration examples - Architecture diagrams - State machine diagrams ### Completeness: - COMPREHENSIVE: All public APIs documented. - PRECISE: Signatures verified against source code. - PRACTICAL: Includes runnable examples and patterns. - ORGANIZED: Cross-referenced and logically structured. - ACCURATE: Generated directly from source analysis. - USEFUL: Standalone reference. ### Navigation: - Table of contents with 9 documents - Cross-references between documents - Index with quick lookup - Source code location references - Related topics links ### Usage Guidelines: - **API Users**: Start with `01-rest-api.md`, `02-types.md` - **Developers**: Start with `00-index.md`, then specialized docs - **Operations**: Start with `03-configuration.md`, `07-advanced-topics.md` - **Architects**: Start with `00-index.md`, `05-workflows-and-handlers.md`, `07-advanced-topics.md` ``` -------------------------------- ### Get Service Readiness Status JSON Source: https://github.com/microsoft/call-center-ai/blob/main/_autodocs/01-rest-api.md This JSON response indicates the status of various services checked during the readiness probe. ```json { "status": "ok", "checks": [ { "id": "cache", "status": "ok" }, { "id": "store", "status": "ok" }, { "id": "startup", "status": "ok" }, { "id": "search", "status": "ok" }, { "id": "sms", "status": "ok" } ] } ``` -------------------------------- ### Validating Incoming Claim Data Source: https://github.com/microsoft/call-center-ai/blob/main/_autodocs/07-advanced-topics.md Example of validating incoming claim data against a dynamically generated Pydantic model. ```python claim_entry = claim_model.model_validate(data) ``` -------------------------------- ### GET /health/readiness Source: https://github.com/microsoft/call-center-ai/blob/main/_autodocs/01-rest-api.md Checks if the service is ready to serve requests. This includes validating the status of cache, database, search, and SMS services. ```APIDOC ## GET /health/readiness ### Description Check if the service is ready to serve requests, including validation of cache, database, search, and SMS services. ### Method GET ### Endpoint /health/readiness ### Parameters None ### Response #### Success Response (200 OK) - **status** (string) - Indicates the overall status of the readiness check. - **checks** (array) - An array of objects, each detailing the status of a specific service check. - **id** (string) - The identifier of the service being checked. - **status** (string) - The status of the service check ('ok' or other). #### Error Response (503 Service Unavailable) Indicates that the service is not ready to serve requests. ### Request Example ```bash curl http://localhost:8080/health/readiness ``` ### Response Example ```json { "status": "ok", "checks": [ { "id": "cache", "status": "ok" }, { "id": "store", "status": "ok" }, { "id": "startup", "status": "ok" }, { "id": "search", "status": "ok" }, { "id": "sms", "status": "ok" } ] } ``` ``` -------------------------------- ### Override Per-Call Claim Schema Source: https://github.com/microsoft/call-center-ai/blob/main/_autodocs/07-advanced-topics.md Example of initiating a call via a POST request with a custom, per-call claim schema defined in the request body. ```bash curl -X POST http://localhost:8080/call \ -H "Content-Type: application/json" \ -d '{ \ "phone_number": "+33612345678", \ "bot_name": "Support", \ "bot_company": "Contoso", \ "agent_phone_number": "+33698765432", \ "claim": [ \ { \ "name": "order_id", \ "type": "text", \ "description": "Order ID" \ }, \ { \ "name": "issue_type", \ "type": "text", \ "description": "Type of issue" \ } \ ] \ }' ``` -------------------------------- ### Create Azure Blob Storage Container Source: https://github.com/microsoft/call-center-ai/blob/main/_autodocs/07-advanced-topics.md Command to create a new blob container in Azure Storage for storing call recordings. Ensure you have the Azure CLI installed and are logged in. ```bash az storage container create \ --name recordings \ --account-name myaccount ``` -------------------------------- ### Get or Create Shared Async HTTP Session Source: https://github.com/microsoft/call-center-ai/blob/main/_autodocs/06-helpers-and-utilities.md This function provides a shared `aiohttp.ClientSession` for making HTTP requests. It ensures connection pooling and graceful shutdown, beneficial for SDK clients. ```python import aiohttp async def get_session() -> aiohttp.ClientSession: # Implementation details for getting or creating the session pass # Usage example: session = await get_session() ``` -------------------------------- ### CosmosDbStore Initialization Source: https://github.com/microsoft/call-center-ai/blob/main/_autodocs/04-persistence-api.md Illustrates the initialization of the CosmosDbStore, which requires an ICache instance and CosmosDbModel configuration. ```python class CosmosDbStore(IStore): def __init__(self, cache: ICache, config: CosmosDbModel): ... ``` -------------------------------- ### Initialize Persistence Backends Source: https://github.com/microsoft/call-center-ai/blob/main/_autodocs/04-persistence-api.md Instantiate backends like cache, database, search, SMS, and call queue from the application configuration. This pattern allows for easy swapping of implementations via configuration without code modifications. ```python from app.helpers.config import CONFIG # Instantiate backends from config cache = CONFIG.cache.instance db = CONFIG.database.instance search = CONFIG.ai_search.instance sms = CONFIG.sms.instance call_queue = CONFIG.queue.call ``` -------------------------------- ### CONFIG Source: https://github.com/microsoft/call-center-ai/blob/main/_autodocs/06-helpers-and-utilities.md Global configuration singleton that is loaded on startup. Provides access to application settings. ```APIDOC ## CONFIG ### Description Global configuration singleton loaded on startup. ### Type `RootModel` ### Access ```python from app.helpers.config import CONFIG endpoint = CONFIG.communication_services.endpoint ``` ``` -------------------------------- ### GET /call Source: https://github.com/microsoft/call-center-ai/blob/main/_autodocs/01-rest-api.md Retrieves a list of all calls, with an option to filter by a specific phone number. ```APIDOC ## GET /call ### Description List all calls (optionally filtered by phone number). ### Method GET ### Endpoint /call ### Parameters #### Query Parameters - **phone_number** (string) - Optional - Filter by phone number (URL-encoded, e.g., `%2B33612345678`) ### Response #### Success Response (200 OK) - **Array of CallGetModel objects** ### Request Example ```bash curl 'http://localhost:8080/call?phone_number=%2B33612345678' ``` ``` -------------------------------- ### Configure System with Azure Credentials Source: https://github.com/microsoft/call-center-ai/blob/main/_autodocs/00-index.md Create a `config.yaml` file to store your Azure resource credentials and endpoints. Ensure all required fields are populated for the services to function correctly. ```yaml public_domain: "https://yourname.com" ai_search: endpoint: "https://xxx.search.windows.net" api_key: "xxx" index_name: "documents" database: endpoint: "https://xxx.documents.azure.com" api_key: "xxx" database: "call-center" container: "calls" communication_services: endpoint: "https://xxx.communication.azure.com" access_key: "xxx" phone_number: "+33612345678" resource_id: "/subscriptions/.../providers/Microsoft.Communication/communicationServices/xxx" # ... (see Configuration Reference for full spec) ``` -------------------------------- ### GET /health/liveness Source: https://github.com/microsoft/call-center-ai/blob/main/_autodocs/01-rest-api.md Checks the basic liveness of the service. It's a simple probe to determine if the service is running. ```APIDOC ## GET /health/liveness ### Description Check if the service is running (basic liveness probe). ### Method GET ### Endpoint /health/liveness ### Parameters None ### Response #### Success Response (200 OK) No body ### Request Example ```bash curl http://localhost:8080/health/liveness ``` ``` -------------------------------- ### Access Global Configuration Source: https://github.com/microsoft/call-center-ai/blob/main/_autodocs/06-helpers-and-utilities.md Access the global configuration singleton, which is loaded on startup. Import the CONFIG object to retrieve settings. ```python from app.helpers.config import CONFIG endpoint = CONFIG.communication_services.endpoint ``` -------------------------------- ### GET /report Source: https://github.com/microsoft/call-center-ai/blob/main/_autodocs/01-rest-api.md Retrieves a list of all calls, with an option to filter by phone number. The output is provided as an HTML web interface. ```APIDOC ## GET /report ### Description Display a list of all calls in an HTML web interface (optionally filtered by phone number). ### Method GET ### Endpoint /report #### Query Parameters - **phone_number** (string) - Optional - Filter by phone number ### Response #### Success Response (200 OK) **Content-Type:** text/html ### Request Example ```bash curl 'http://localhost:8080/report?phone_number=%2B33612345678' ``` ``` -------------------------------- ### GET /call/{call_id_or_phone_number} Source: https://github.com/microsoft/call-center-ai/blob/main/_autodocs/01-rest-api.md Retrieves details of a specific call using its unique call ID or the associated phone number. ```APIDOC ## GET /call/{call_id_or_phone_number} ### Description Retrieve a specific call by call ID or phone number. ### Method GET ### Endpoint /call/{call_id_or_phone_number} ### Parameters #### Path Parameters - **call_id_or_phone_number** (string) - The UUID of the call or the phone number (URL-encoded) to identify the call. ### Response #### Success Response (200 OK) - **CallGetModel** (object) - See [Call Model](#call-model) for details. ### Request Example ```bash curl 'http://localhost:8080/call/123e4567-e89b-12d3-a456-426614174000' curl 'http://localhost:8080/call/%2B33612345678' ``` ``` -------------------------------- ### Make a Test Call via API Source: https://github.com/microsoft/call-center-ai/blob/main/_autodocs/00-index.md Use `curl` to send a POST request to the `/call` endpoint to initiate a test call. Provide the necessary parameters such as phone numbers, bot name, and company. ```bash curl -X POST http://localhost:8080/call \ -H "Content-Type: application/json" \ -d '{ "phone_number": "+33612345678", "bot_name": "Amélie", "bot_company": "Contoso", "agent_phone_number": "+33698765432" }' ``` -------------------------------- ### Check Service Readiness Source: https://github.com/microsoft/call-center-ai/blob/main/_autodocs/01-rest-api.md Use this endpoint to verify if the service is ready to handle requests, including checks for cache, database, search, and SMS services. ```bash curl http://localhost:8080/health/readiness ``` -------------------------------- ### Resources Configuration Settings Source: https://github.com/microsoft/call-center-ai/blob/main/_autodocs/03-configuration.md Configure resource paths for blob storage containers. Specifies URLs for sounds and call recordings. ```yaml resources: sounds_container_url: "https://xxx.blob.core.windows.net/sounds" recordings_container_url: "https://xxx.blob.core.windows.net/recordings" ``` -------------------------------- ### Get Resource Directory Path Source: https://github.com/microsoft/call-center-ai/blob/main/_autodocs/06-helpers-and-utilities.md Retrieves the absolute path to a specified resource directory. Useful for accessing templates or data files. ```python from app.helpers.resources import resources_dir template_dir = resources_dir("public_website") ``` -------------------------------- ### GET /report/{call_id} Source: https://github.com/microsoft/call-center-ai/blob/main/_autodocs/01-rest-api.md Retrieves a detailed report for a specific call, identified by its UUID. The report is presented in an HTML web interface. ```APIDOC ## GET /report/{call_id} ### Description Display a detailed call report in an HTML web interface. ### Method GET ### Endpoint /report/{call_id} #### Path Parameters - **call_id** (string) - Required - UUID of the call ### Response #### Success Response (200 OK) **Content-Type:** text/html #### Error Response (404 Not Found) ### Request Example ```bash curl 'http://localhost:8080/report/123e4567-e89b-12d3-a456-426614174000' ``` ``` -------------------------------- ### TrainingModel Excluded Fields Method Source: https://github.com/microsoft/call-center-ai/blob/main/_autodocs/02-types.md Instance method for TrainingModel to get a set of fields that should be excluded from LLM processing. Supports sorting by score. ```python def excluded_fields_for_llm() -> set[str]: # Get fields to exclude from LLM (id, score) return {"id", "score"} ``` -------------------------------- ### Load and Validate Configuration Source: https://github.com/microsoft/call-center-ai/blob/main/_autodocs/06-helpers-and-utilities.md Load configuration from environment variables or a YAML file. The configuration is validated against a RootModel. Raises ValueError if invalid or not found. ```python from app.helpers.config import load_config config = load_config() ``` -------------------------------- ### load_config() Source: https://github.com/microsoft/call-center-ai/blob/main/_autodocs/06-helpers-and-utilities.md Loads and validates configuration from environment variables or a configuration file. Raises an error if the configuration is invalid or not found. ```APIDOC ## load_config() ### Description Load and validate configuration from environment or file. Returns validated configuration. ### Signature ```python def load_config() -> RootModel ``` ### Returns Validated `RootModel` ### Sources (in order) 1. `CONFIG_JSON` environment variable (JSON string) 2. `config.yaml` file (YAML) ### Raises `ValueError` if config is invalid or not found ``` -------------------------------- ### Load JSON Configuration from Environment Variable Source: https://github.com/microsoft/call-center-ai/blob/main/_autodocs/03-configuration.md Sets the entire application configuration using a single environment variable `CONFIG_JSON` containing a JSON string. This method offers the highest precedence for configuration loading. ```python # Single CONFIG_JSON env var with entire config as JSON CONFIG_JSON='{"ai_search": {...}, "database": {...}}' ``` -------------------------------- ### start_audio_streaming Source: https://github.com/microsoft/call-center-ai/blob/main/_autodocs/06-helpers-and-utilities.md Initiates the capture of audio from an ongoing call. Requires the call automation client and the call connection ID. ```APIDOC ## start_audio_streaming() Begin capturing audio from call. ### Method Signature ```python async def start_audio_streaming( client: CallAutomationClient, call_connection_id: str, ) -> None ``` ### Parameters - **client** (CallAutomationClient) - The client for call automation. - **call_connection_id** (str) - The ID of the call connection. ``` -------------------------------- ### Get All Calls Report (Filtered) Source: https://github.com/microsoft/call-center-ai/blob/main/_autodocs/01-rest-api.md Use this endpoint to retrieve an HTML report of all calls, optionally filtered by a specific phone number. The phone number should be URL-encoded. ```bash curl 'http://localhost:8080/report?phone_number=%2B33612345678' ``` -------------------------------- ### Load YAML Configuration from File Source: https://github.com/microsoft/call-center-ai/blob/main/_autodocs/03-configuration.md Loads configuration from a `config.yaml` file located in the project root or current directory. This method is used when environment variables are not sufficient or for more structured configuration. ```yaml # config.yaml ai_search: endpoint: https://example.search.windows.net api_key: xxx database: ... ``` -------------------------------- ### Initialize Content Safety Blocklist Client Source: https://github.com/microsoft/call-center-ai/blob/main/examples/blocklist.ipynb Initializes the BlocklistClient with your Azure Content Safety endpoint and API key. Ensure you have the necessary Azure credentials. ```python import pandas as pd from azure.ai.contentsafety import BlocklistClient from azure.ai.contentsafety.models import ( AddOrUpdateTextBlocklistItemsOptions, TextBlocklist, TextBlocklistItem, ) from azure.core.credentials import AzureKeyCredential key = AzureKeyCredential("xxx") client = BlocklistClient( "https://ccai-clesne-contentsafety.cognitiveservices.azure.com/", key ) ``` -------------------------------- ### Configure Azure Storage Queues Source: https://github.com/microsoft/call-center-ai/blob/main/_autodocs/03-configuration.md Set up Azure Storage Queues for asynchronous processing of call events, post-call tasks, SMS events, and training data. ```yaml queue: connection_string: "DefaultEndpointsProtocol=https;..." call_queue_name: "call-events" post_queue_name: "post-events" sms_queue_name: "sms-events" training_queue_name: "training-events" ``` -------------------------------- ### Get Specific Call Report Source: https://github.com/microsoft/call-center-ai/blob/main/_autodocs/01-rest-api.md Retrieve a detailed HTML report for a specific call using its UUID. This endpoint returns a 404 Not Found if the call ID is invalid. ```bash curl 'http://localhost:8080/report/123e4567-e89b-12d3-a456-426614174000' ``` -------------------------------- ### Sync Local Configuration from Azure Source: https://github.com/microsoft/call-center-ai/blob/main/README.md Copies the application configuration from a remote Azure deployment to your local machine. Replace 'my-rg-name' with your resource group name. ```zsh make name=my-rg-name sync-local-config ``` -------------------------------- ### Fallback LLM Model Strategy Source: https://github.com/microsoft/call-center-ai/blob/main/_autodocs/07-advanced-topics.md This illustrates a fallback strategy where a faster, less capable LLM is tried first with a short timeout. If it fails, a slower, more capable LLM is attempted with a longer timeout. If both fail, an error message is returned. ```text Try fast LLM (gpt-4.1-mini) with 4-second timeout ↓ fails Try slow LLM (gpt-4.1) with 15-second timeout ↓ fails Return error message to caller ``` -------------------------------- ### Deploy Azure Resources Locally Source: https://github.com/microsoft/call-center-ai/blob/main/README.md Deploys the necessary Azure resources for the solution without the API server, enabling local testing. Replace 'my-rg-name' with your resource group name. ```zsh make deploy-bicep deploy-post name=my-rg-name ``` -------------------------------- ### Call Get Model Source: https://github.com/microsoft/call-center-ai/blob/main/_autodocs/01-rest-api.md Represents the complete call data returned by the API. Includes call ID, timestamps, status, initiation parameters, gathered claims, messages, and potential next actions or reminders. ```python class CallGetModel(BaseModel): call_id: UUID # Immutable created_at: datetime # Immutable in_progress: bool # Whether the call is actively ongoing initiate: CallInitiateModel # Call initiation parameters claim: dict[str, Any] # Gathered claim data messages: list[MessageModel] # Conversation messages next: NextModel | None # Recommended action after call reminders: list[ReminderModel] # Generated reminders synthesis: SynthesisModel | None # Call summary ``` -------------------------------- ### Check Service Liveness Source: https://github.com/microsoft/call-center-ai/blob/main/_autodocs/01-rest-api.md Use this endpoint to perform a basic liveness probe and check if the service is running. ```bash curl http://localhost:8080/health/liveness ``` -------------------------------- ### Call Model Instance Methods Source: https://github.com/microsoft/call-center-ai/blob/main/_autodocs/01-rest-api.md Provides utility methods for interacting with call data, such as retrieving RAG documents, determining timezone, identifying assistant voice style, and checking for human interaction. ```python trainings(cache_only: bool) tz() last_assistant_style() had_interaction() ``` -------------------------------- ### Call Center AI Data Structure Example Source: https://github.com/microsoft/call-center-ai/blob/main/README.md This JSON object represents the data stored during a call, including claim details, conversation messages, and reminders. It is used to track incident information and customer interactions. ```json { "claim": { "incident_description": "Collision avec un autre véhicule, voiture dans le fossé, pas de blessés", "incident_location": "Nationale 17", "involved_parties": "Dujardin, Madame Lesné", "policy_number": "DEC1748" }, "messages": [ { "created_at": "2024-12-10T15:51:04.566727Z", "action": "talk", "content": "Non, je pense que c'est pas mal. Vous avez répondu à mes questions et là j'attends la dépaneuse. Merci beaucoup.", "persona": "human", "style": "none", "tool_calls": [] }, { "created_at": "2024-12-10T15:51:06.040451Z", "action": "talk", "content": "Je suis ravi d'avoir pu vous aider! Si vous avez besoin de quoi que ce soit d'autre, n'hésitez pas à nous contacter. Je vous souhaite une bonne journée et j'espère que tout se passera bien avec la dépanneuse. Au revoir!", "persona": "assistant", "style": "none", "tool_calls": [] } ], "next": { "action": "case_closed", "justification": "The customer has provided all necessary information for the insurance claim, and a reminder has been set for a follow-up call. The customer is satisfied with the assistance provided and is waiting for the tow truck. The case can be closed for now." }, "reminders": [ { "created_at": "2024-12-10T15:50:09.507903Z", "description": "Rappeler le client pour faire le point sur l'accident et l'avancement du dossier.", "due_date_time": "2024-12-11T14:30:00", "owner": "assistant", "title": "Rappel client sur l'accident" } ], "synthesis": { "long": "During our call, you reported an accident involving your vehicle on the Nationale 17. You mentioned that there were no injuries, but both your car and the other vehicle ended up in a ditch. The other party involved is named Dujardin, and your vehicle is a 4x4 Ford. I have updated your claim with these details, including the license plates: yours is U837GE and the other vehicle's is GA837IA. A reminder has been set for a follow-up call tomorrow at 14:30 to discuss the progress of your claim. If you need further assistance, please feel free to reach out.", "satisfaction": "high", "short": "the accident on Nationale 17", "improvement_suggestions": "To improve the customer experience, it would be beneficial to ensure that the call connection is stable to avoid interruptions. Additionally, providing a clear step-by-step guide on what information is needed for the claim could help streamline the process and reduce any confusion for the customer." } ... } ``` -------------------------------- ### Async Job Scheduler Source: https://github.com/microsoft/call-center-ai/blob/main/_autodocs/06-helpers-and-utilities.md Obtain or create an asynchronous job scheduler for the current context. Use it within an async context manager to spawn background tasks. ```python from app.helpers.scheduler import get_scheduler async with get_scheduler() as scheduler: await scheduler.spawn(background_task()) ``` -------------------------------- ### Automatic LLM Request Retries with Exponential Backoff Source: https://github.com/microsoft/call-center-ai/blob/main/_autodocs/07-advanced-topics.md This Python snippet demonstrates how to automatically retry LLM requests that fail. It uses exponential backoff to increase wait times between retries and stops after a specified number of attempts. Ensure the `retry` library is installed. ```python from tenacity import retry, wait_exponential, stop_after_attempt @retry( wait=wait_exponential(multiplier=1, min=2, max=10), stop=stop_after_attempt(3), reraise=True, ) async def call_llm(): ... ``` -------------------------------- ### Configure TTS and LLM Prompts Source: https://github.com/microsoft/call-center-ai/blob/main/_autodocs/03-configuration.md Customize Text-to-Speech (TTS) and Large Language Model (LLM) prompts using templates. Supports various placeholders for dynamic content. ```yaml prompts: tts: hello_tpl: - "Hello, I'm {bot_name}!" - "Hi, I'm {bot_name} from {bot_company}" llm: default_system_tpl: | Assistant is called {bot_name}... chat_system_tpl: | # Objective Provide support... ``` -------------------------------- ### IStore.readiness Source: https://github.com/microsoft/call-center-ai/blob/main/_autodocs/04-persistence-api.md Validates the health of the database by performing a CRUD test. Returns ReadinessEnum.OK if healthy, otherwise ReadinessEnum.FAIL. ```APIDOC ## readiness() ### Description Validate that the database is healthy (performs CRUD test). ### Returns `ReadinessEnum.OK` or `ReadinessEnum.FAIL` ### Example ```python status = await db.readiness() assert status == ReadinessEnum.OK ``` ``` -------------------------------- ### Run Local Tests Source: https://github.com/microsoft/call-center-ai/blob/main/_autodocs/00-index.md Execute local tests for the LLM and workflows without requiring Azure Communication Services. ```bash python -m tests.local ``` -------------------------------- ### Audio Processing Pipeline Flowchart Source: https://github.com/microsoft/call-center-ai/blob/main/_autodocs/05-workflows-and-handlers.md Details the steps involved in processing audio from raw input to streamed output. ```text Raw audio (WebSocket) ↓ Speech-to-text (Azure Cognitive Services) ↓ Text → Message model ↓ LLM chat completion (Azure OpenAI) ↓ Extract style (voice tone) and tool calls ↓ Text-to-speech (Azure Cognitive Services) ↓ Audio → WebSocket (back to caller) ``` -------------------------------- ### TTS Hello Prompt Templates Source: https://github.com/microsoft/call-center-ai/blob/main/README.md Customize the initial greeting prompts for Text-to-Speech (TTS). These templates use placeholders like {bot_name} and {bot_company} and are provided as a list to offer variety. ```yaml prompts: tts: hello_tpl: - : | Hello, I'm {bot_name}, from {bot_company}! I'm an IT support specialist. Here's how I work: when I'm working, you'll hear a little music; then, at the beep, it's your turn to speak. You can speak to me naturally, I'll understand. What's your problem? - : | Hi, I'm {bot_name} from {bot_company}. I'm here to help. You'll hear music, then a beep. Speak naturally, I'll understand. What's the issue? ``` -------------------------------- ### Azure CLI Login Source: https://github.com/microsoft/call-center-ai/blob/main/README.md Log in to your Azure environment using the Azure CLI. This is a prerequisite for deploying Azure resources. ```zsh az login ``` -------------------------------- ### Initiate Outbound Call Source: https://github.com/microsoft/call-center-ai/blob/main/_autodocs/01-rest-api.md Initiate a new outbound call by providing the target phone number, bot details, agent transfer number, and optional task or claim schema. ```bash curl -X POST http://localhost:8080/call \ -H "Content-Type: application/json" \ -d '{ "phone_number": "+33612345678", "bot_name": "Amélie", "bot_company": "Contoso", "agent_phone_number": "+33698765432", "task": "Help the customer with their insurance claim", "claim": [ { "name": "policy_number", "type": "text", "description": "Policy number" } ] }' ``` -------------------------------- ### POST /call Source: https://github.com/microsoft/call-center-ai/blob/main/_autodocs/01-rest-api.md Initiates a new outbound call to a specified phone number, configuring the AI assistant and call objective. ```APIDOC ## POST /call ### Description Initiate a new outbound call to a phone number. ### Method POST ### Endpoint /call ### Parameters #### Request Body - **phone_number** (string (E164)) - Required - Target phone number (E164 format, e.g., `+33612345678`) - **bot_name** (string) - Required - Name of the AI assistant - **bot_company** (string) - Required - Company name for the assistant - **agent_phone_number** (string (E164)) - Required - Phone number for transferring to human agent - **task** (string) - Optional - Description of the call objective - **claim** (array) - Optional - Custom claim schema for this call (array of field definitions) ### Request Example ```bash curl -X POST http://localhost:8080/call \ -H "Content-Type: application/json" \ -d { "phone_number": "+33612345678", "bot_name": "Amélie", "bot_company": "Contoso", "agent_phone_number": "+33698765432", "task": "Help the customer with their insurance claim", "claim": [ { "name": "policy_number", "type": "text", "description": "Policy number" } ] } ``` ### Response #### Success Response (201 Created) - **CallGetModel** (object) - See [Call Model](#call-model) for details. ``` -------------------------------- ### Handle Text-to-Speech via Azure Automation Source: https://github.com/microsoft/call-center-ai/blob/main/_autodocs/06-helpers-and-utilities.md Plays pre-synthesized speech using the Azure Automation API. Supports custom voice styles and languages. ```python async def handle_automation_tts( client: CallAutomationClient, call_connection_id: str, text: str, style: StyleEnum = StyleEnum.NONE, language: str = "fr-FR", ) -> None: ... ``` -------------------------------- ### Deploy Call Center AI Source: https://github.com/microsoft/call-center-ai/blob/main/README.md Run the deployment automation for the Call Center AI project. Specify the resource group name. The image version can also be specified. ```zsh make deploy name=my-rg-name ``` -------------------------------- ### LLM Configuration for Azure OpenAI Source: https://github.com/microsoft/call-center-ai/blob/main/_autodocs/03-configuration.md Configure primary and fallback Azure OpenAI endpoints, including API keys, deployment names, and token limits. Use the 'fast' configuration for general use and 'slow' for fallback scenarios. ```yaml llm: fast: api_key: "xxxx" deployment: "gpt-4-1-mini" endpoint: "https://xxx.openai.azure.com" max_tokens: 2000 slow: api_key: "xxxx" deployment: "gpt-4-1" endpoint: "https://yyy.openai.azure.com" max_tokens: 4000 ``` -------------------------------- ### RAG Query Expansion Logic Source: https://github.com/microsoft/call-center-ai/blob/main/_autodocs/07-advanced-topics.md Illustrates the process of expanding queries for RAG by using recent messages, combining results, and filtering by relevance. ```text Last 3 messages: ["Help with claim", "Policy number?", "ABC123"] ↓ Search AI Search with each message as query ↓ Combine and deduplicate results ↓ Sort by relevance score ↓ Filter by strictness threshold (e.g., 0.5) ↓ Inject top K results (default: 5) into LLM context ``` -------------------------------- ### Root Configuration Model Definition Source: https://github.com/microsoft/call-center-ai/blob/main/_autodocs/03-configuration.md Defines the main `RootModel` for application configuration, inheriting from `BaseSettings`. It specifies all required and optional configuration fields with their types and default values. ```python class RootModel(BaseSettings): public_domain: str # Required version: str # Default: "0.0.0-unknown" ai_search: AiSearchModel ai_translation: AiTranslationModel cache: CacheModel cognitive_service: CognitiveServiceModel communication_services: CommunicationServicesModel database: DatabaseModel llm: LlmModel monitoring: MonitoringModel prompts: PromptsModel resources: ResourcesModel sms: SmsModel conversation: ConversationModel app_configuration: AppConfigurationModel queue: QueueModel ``` -------------------------------- ### CallInitiateModel Definition Source: https://github.com/microsoft/call-center-ai/blob/main/_autodocs/02-types.md Defines the parameters required to initiate a phone call. It includes the target phone number and inherits other initiation details from WorkflowInitiateModel. ```python class CallInitiateModel(WorkflowInitiateModel): phone_number: PhoneNumber ``` -------------------------------- ### ReadinessModel Definition Source: https://github.com/microsoft/call-center-ai/blob/main/_autodocs/02-types.md Defines the overall readiness status of the application, including a list of individual check results. Use this model to represent the health status of the entire system. ```python class ReadinessModel(BaseModel): status: ReadinessEnum checks: list[ReadinessCheckModel] ``` -------------------------------- ### Create and Update Text Blocklist from CSV Source: https://github.com/microsoft/call-center-ai/blob/main/examples/blocklist.ipynb Reads words from a 'blocklist.csv' file and uses them to create or update a text blocklist. It first creates the blocklist if it doesn't exist, then adds the items. Assumes the CSV has 'word' and 'blocklist' columns. ```python name = "competitors" description = "Competitors blocklist." df = pd.read_csv("blocklist.csv") block_items = {} for index, row in df.iterrows(): text = TextBlocklistItem(text=row["word"]) if row["blocklist"] not in block_items: block_items[row["blocklist"]] = [] block_items[row["blocklist"]].append(text) for blocklist, words in block_items.items(): print(f"Creating blocklist {blocklist} with {len(words)} words") # noqa: T201 client.create_or_update_text_blocklist( blocklist_name=blocklist, options=TextBlocklist(blocklist_name=blocklist), ) client.add_or_update_blocklist_items( blocklist_name=blocklist, options=AddOrUpdateTextBlocklistItemsOptions(blocklist_items=words), ) ``` -------------------------------- ### Set Nested Environment Variables for Configuration Source: https://github.com/microsoft/call-center-ai/blob/main/_autodocs/03-configuration.md Configures nested settings using environment variables with a double underscore (`__`) delimiter. This allows for granular control over hierarchical configuration parameters. ```bash export LLM__FAST__ENDPOINT=https://xxx.openai.azure.com export LLM__SLOW__ENDPOINT=https://yyy.openai.azure.com ``` -------------------------------- ### Check Database Readiness Source: https://github.com/microsoft/call-center-ai/blob/main/_autodocs/04-persistence-api.md Validates database health by performing a CRUD test. Returns ReadinessEnum.OK or ReadinessEnum.FAIL. ```python status = await db.readiness() assert status == ReadinessEnum.OK ``` -------------------------------- ### Feature Flag Functions Source: https://github.com/microsoft/call-center-ai/blob/main/_autodocs/06-helpers-and-utilities.md Provides access to dynamic configuration settings from Azure App Configuration. These functions return integer, float, or boolean values and have a cache TTL of 60 seconds. ```APIDOC ## Feature Flag Functions Provides access to dynamic configuration settings from Azure App Configuration. ### Functions - `answer_hard_timeout_sec()` - `answer_soft_timeout_sec()` - `callback_timeout_hour()` - `phone_silence_timeout_sec()` - `recognition_retry_max()` - `recording_enabled()` - `slow_llm_for_chat()` ### Return Type All functions return `int`, `float`, or `bool` depending on the flag's configuration. ### Cache Features flags are cached with a Time-To-Live (TTL) of 60 seconds, refreshing every minute. ``` -------------------------------- ### IStore.call_create Source: https://github.com/microsoft/call-center-ai/blob/main/_autodocs/04-persistence-api.md Creates a new call record in the database. The returned CallStateModel may include server-assigned identifiers. ```APIDOC ## call_create(call: CallStateModel) ### Description Create a new call. ### Parameters #### Request Body - **call** (CallStateModel) - Required - New call data ### Returns Created `CallStateModel` (may include server-assigned IDs) ### Example ```python call = CallStateModel( initiate=CallInitiateModel( phone_number="+33612345678", bot_name="Amélie", bot_company="Contoso", agent_phone_number="+33698765432", ) ) created = await db.call_create(call) print(created.call_id) ``` ``` -------------------------------- ### Call Lifecycle Flowchart Source: https://github.com/microsoft/call-center-ai/blob/main/_autodocs/05-workflows-and-handlers.md Illustrates the sequence of events from an incoming call to post-call processing. ```text User dials → Incoming call event → Answer call → Media streaming starts ↓ Audio captured → Speech-to-text → LLM processing → Text-to-speech → Play audio ↓ [Loop until hangup] ↓ Call ends → Post-call processing (summary, reminders, next action) → Database update ``` -------------------------------- ### Define Language Model Source: https://github.com/microsoft/call-center-ai/blob/main/_autodocs/02-types.md Use this model to configure overall language settings, specifying the default language and a list of available languages. ```python class LanguageModel(BaseModel): default_short_code: str availables: list[LanguageEntryModel] ``` -------------------------------- ### Map Nested Environment Variables to YAML Structure Source: https://github.com/microsoft/call-center-ai/blob/main/_autodocs/03-configuration.md Illustrates how nested environment variables with `__` delimiters are mapped to a hierarchical YAML configuration structure. This demonstrates the interpretation of the environment variables set previously. ```yaml llm: fast: endpoint: https://xxx.openai.azure.com slow: endpoint: https://yyy.openai.azure.com ``` -------------------------------- ### Monitoring Configuration Settings Source: https://github.com/microsoft/call-center-ai/blob/main/_autodocs/03-configuration.md Configure Azure Monitor/Application Insights for telemetry. Includes enablement and sampling rate. Requires APPLICATIONINSIGHTS_CONNECTION_STRING environment variable. ```yaml monitoring: enabled: true sample_rate: 1.0 ``` -------------------------------- ### App Configuration Settings Source: https://github.com/microsoft/call-center-ai/blob/main/_autodocs/03-configuration.md Configure Azure App Configuration service for feature flags. Includes connection string and TTL for feature flag refresh. ```yaml app_configuration: connection_string: "Endpoint=https://xxx.azconfig.io;..." ttl_sec: 60 ``` -------------------------------- ### Processing Call Data from Training Queue Source: https://github.com/microsoft/call-center-ai/blob/main/_autodocs/07-advanced-topics.md Shows how to process call data from an Azure Queue Storage message for RAG training. It deserializes the JSON content and initiates the training process. ```python # training_event() processes it async def training_event(training: AzureQueueStorageMessage): call = CallStateModel.model_validate_json(training.content) await call.trainings(cache_only=False) # Pre-compute embeddings ``` -------------------------------- ### Configure SMS Provider (Twilio) Source: https://github.com/microsoft/call-center-ai/blob/main/_autodocs/03-configuration.md Set the SMS mode to 'twilio' and provide Twilio account credentials, including Account SID, Auth Token, and the phone number. ```yaml sms: mode: "twilio" twilio: account_sid: "ACxxx" auth_token: "xxx" phone_number: "+33612345678" ``` -------------------------------- ### Implement Call Transfer to Agent in Python Source: https://github.com/microsoft/call-center-ai/blob/main/_autodocs/07-advanced-topics.md Implement the 'call_transfer' function to handle playing a message and transferring the call to a specified phone number. Requires CallAutomationClient and CallStateModel. ```python async def call_transfer( message: str, call: CallStateModel, client: CallAutomationClient, ) -> bool: # Play message await handle_automation_tts(client, call.voice_id, message) # Transfer to agent transfer_result = await client.transfer_call_to_participant( target_participant=PhoneNumberIdentifier(call.initiate.agent_phone_number), ) return True ``` -------------------------------- ### Initiate Call to AI Agent Source: https://github.com/microsoft/call-center-ai/blob/main/README.md Use this cURL command to ask the AI bot to call a specific phone number. Ensure to replace 'xxx' with your actual API endpoint and provide all necessary data fields. ```bash data='{ "bot_company": "Contoso", "bot_name": "Amélie", "phone_number": "+11234567890", "task": "Help the customer with their digital workplace. Assistant is working for the IT support department. The objective is to help the customer with their issue and gather information in the claim.", "agent_phone_number": "+33612345678", "claim": [ { "name": "hardware_info", "type": "text" }, { "name": "first_seen", "type": "datetime" }, { "name": "building_location", "type": "text" } ] }' curl \ --header 'Content-Type: application/json' \ --request POST \ --url https://xxx/call \ --data $data ``` -------------------------------- ### MemoryCache Implementation Source: https://github.com/microsoft/call-center-ai/blob/main/_autodocs/04-persistence-api.md In-memory implementation of the ICache interface, suitable for local development. Not recommended for multi-process deployments. ```python class MemoryCache(ICache): ... ``` -------------------------------- ### Sending Call Data to Training Queue Source: https://github.com/microsoft/call-center-ai/blob/main/_autodocs/07-advanced-topics.md Demonstrates sending completed call data to an asynchronous training queue for RAG training. The data is serialized to JSON. ```python # on_end_call() sends to training queue await training_queue.send_message(call.model_dump_json()) ``` -------------------------------- ### AiSearchImpl Implementation Source: https://github.com/microsoft/call-center-ai/blob/main/_autodocs/04-persistence-api.md Implementation of the ISearch interface using Azure AI Search. It requires configuration for endpoint, API key, and index name. ```python class AiSearchImpl(ISearch): def __init__(self, cache: ICache, config: AiSearchModel): ... ```