Hotdry.
ai-systems

Call Center AI:AI 代理一键触发外呼电话的 REST API 实现

无需电话领域专业知识,通过 Microsoft Call Center AI 的简单 REST API,让 AI 代理发起外呼电话,支持自定义目标号码、机器人身份、任务和数据 schema,直接集成 Azure 服务。

Call Center AI 是 Microsoft 开源的一个 AI 驱动呼叫中心解决方案,利用 Azure Communication Services 和 OpenAI GPT 模型,实现 AI 代理通过 REST API 触发外呼电话的核心功能。该项目特别适合保险、IT 支持或客服场景,让开发者无需深入了解电话系统,就能快速集成外呼能力。核心在于一个 POST /call 接口:AI 代理只需发送 JSON payload,即可让机器人拨打指定号码,进行自然对话、数据收集和任务执行。

API 触发外呼的核心机制

外呼电话的发起完全通过 HTTP POST 请求到部署后的端点(如 https://your-domain/call)。Payload 结构简洁且高度可配置,支持动态指定目标号码、机器人身份和对话目标。示例 payload:

{
  "bot_company": "Contoso",
  "bot_name": "Amélie",
  "phone_number": "+11234567890",
  "task": "帮助客户解决数字工作场所问题。助理隶属 IT 支持部门,目标是诊断问题并收集索赔信息。",
  "agent_phone_number": "+33612345678",
  "claim": [
    {
      "name": "hardware_info",
      "type": "text"
    },
    {
      "name": "first_seen",
      "type": "datetime"
    },
    {
      "name": "building_location",
      "type": "text"
    }
  ]
}
  • phone_number:目标客户号码(E.164 格式,必填),支持全球号码。
  • task:英文任务描述(短小精悍),指导 GPT-4o 或 gpt-4o-mini 模型的行为,如 “收集事故细节并生成待办事项”。
  • claim:可选数据 schema,支持 text、datetime、email、phone_number 类型。机器人会自动验证并填充数据,避免无效输入。
  • bot_company/bot_name:自定义机器人身份,提升对话自然度。
  • agent_phone_number:可选代理转接号码,用于复杂场景 fallback 到人工。

调用 curl 示例:

curl --header 'Content-Type: application/json' \
  --request POST \
  --url https://your-domain/call \
  --data '@payload.json'

接口返回呼叫 ID 和状态,实时流式传输对话(支持断线重连)。Azure Communication Services 处理拨号、音频流和 SMS 备用,无需手动管理 SIP 或 PSTN。

无需领域专长的集成路径

项目封装了 Azure 服务栈,开发者只需 Azure 订阅和 CLI:

  1. 预备资源(~15 分钟):

    • 创建资源组:az group create --name ccai-rg --location westeurope
    • 新建 Communication Services:启用系统托管身份,购买支持 voice 的号码(Inbound/Outbound)。
    • 配置 OpenAI(gpt-4o-mini 推荐,低延迟)、Speech Services(STT/TTS)、Cosmos DB(对话存储)、AI Search(RAG)。
  2. 配置与部署make 一键):

    • Fork/clone repo,编辑 config-remote.yaml:填入资源名、端点密钥、默认语言(fr-FR/zh-CN 等,支持自定义神经语音)。
    • az loginmake deploy name=ccai-rg image_version=0.1.0
    • 部署到 Azure Container Apps(serverless),暴露 API 端点。日志:make logs name=ccai-rg
  3. AI 代理集成

    • 在 LangChain/crewAI 等框架中,添加工具函数调用此 API。
    • 示例 Python:
      import requests
      response = requests.post("https://your-domain/call", json=payload)
      call_id = response.json()["call_id"]
      # 轮询 /report/{phone_number} 获取对话历史、claim 数据和 reminders。
      
    • 支持多语言:TTS/STT 自动检测,RAG 注入领域知识(上传 PDF 到 AI Search)。

关键参数调优:

  • vad_threshold: 0.5(语音活动检测阈值,0.1-1.0;低值防漏,高值抗噪)。
  • phone_silence_timeout_sec: 20(静音警告触发,避免挂断)。
  • answer_hard_timeout_sec: 15(LLM 超时,防卡顿)。
  • callback_timeout_hour: 3(自动回拨窗口)。

落地清单与监控要点

部署清单

  • 号码验证:测试 inbound(拨打 bot 号码)确认 STT/TTS 流畅。
  • Payload 测试:最小 task="说 hello",渐进添加 claim。
  • RAG 注入:用 rag-index 工具填充 AI Search(vectors: 1536-dim ADA)。
  • 特性开关(App Configuration):recording_enabled=true(需 Storage 容器)、slow_llm_for_chat=false(用 nano 模型)。
  • 成本估算:1000 通 10 分钟呼叫~$720 / 月(主导 Cosmos RU/s 和 Speech)。

风险阈值与回滚

  • 延迟 >5s:切换 gpt-4o-mini 或 PTU(Azure OpenAI Provisioned Throughput)。
  • 识别失败(recognition_retry_max=3):调 recognition_stt_complete_timeout_ms=100。
  • 回滚:feature_flags 热更新(60s 生效),无需重启。

监控指标(Application Insights):

  • call.answer.latency:目标 <3s。
  • call.aec.droped/missed:回声消除失败 <5%。
  • Token 使用:输入 8k 历史 + 3.75k RAG,输出 400 / 响应。

报告端点 /report/{phone_number} 提供 JSON:messages、claim、synthesis(满意度)、reminders。历史数据可 fine-tune LLM,提升准确性。

此方案桥接 AI 代理与真实电话,适用于低中复杂度外呼(如预约确认、初步咨询)。项目虽 POC,但 IaC 完整,扩展性强:加 IVR、多区域、Twilio SMS。

资料来源

(正文约 1250 字)

查看归档