SuperAPI AI 工具集

agents

智能体与模型

查看项目

更新于 10-14 21:59

技能介绍

用途

ElevenLabs Agents Platform 用于构建具有自然对话能力的语音 AI 智能体。该技能适用于创建语音助手、客服机器人、交互式语音角色或任何实时语音对话场景。

主要能力

智能体创建

支持通过 CLI、Python SDK、JavaScript SDK 和 cURL 创建智能体。创建时可配置首条消息、语言、提示词、LLM 模型、温度、TTS 语音 ID 等参数,并支持版本管理(enable_versioning)。

多 LLM 提供商支持

平台支持以下 LLM 提供商与模型:

  • OpenAI:gpt-5、gpt-5-mini、gpt-5-nano、gpt-4.1、gpt-4.1-mini、gpt-4.1-nano、gpt-4o、gpt-4o-mini、gpt-4-turbo
  • Anthropic:claude-sonnet-4-6、claude-sonnet-4-5、claude-sonnet-4、claude-haiku-4-5、claude-3-7-sonnet、claude-3-5-sonnet、claude-3-haiku
  • Google:gemini-3.1-flash-lite-preview、gemini-3-pro-preview、gemini-3-flash-preview、gemini-2.5-flash、gemini-2.5-flash-lite、gemini-2.0-flash、gemini-2.0-flash-lite
  • ElevenLabs:glm-45-air-fp8、qwen3-30b-a3b、gpt-oss-120b
  • Custom:custom-llm(自带端点)

可通过 GET /v1/convai/llm/list 查看当前模型目录,包括弃用状态、token/上下文限制以及图像输入支持等能力标志。

语音配置

常用语音包括:JBFqnCBsd6RMkjVDRZzb(George)、EXAVITQu4vr4xnSDxMaL(Sarah)、onwK4e9ZLuTAKqWW03F9(Daniel)、XB0fDUnXU5powFXDhCwa(Charlotte)。

可设置对话响应积极性(turn eagerness):patient(等待用户说完)、normal、eager(快速响应)。

工具集成

智能体可通过 webhook、client 或内置系统工具进行扩展。工具在 conversation_config.agent.prompt 中定义。工作区环境变量可解析各环境的服务器工具 URL、请求头和鉴权连接;运行时系统变量(如 {{system__conversation_history}})可在需要时将完整对话上下文传入工具调用。

  • Webhook 工具:服务器端 API 调用,需定义 api_schema(url、method、request_body_schema)。
  • Client 工具:在浏览器中运行,需定义 parameters。
  • 内置工具:包括 end_call(结束通话)和 transfer_to_number(转接号码)等。

对话启动

  • 服务端(Python):获取签名 URL 供客户端连接,支持指定 environment(如 staging)。
  • 客户端(JavaScript):使用 @elevenlabs/client 的 Conversation.startSession 启动会话,支持 onMessage、onUserTranscript、onError 回调。
  • React Hook:使用 @elevenlabs/react 的 useConversation,从后端获取签名 URL 后通过 startSession 启动。

网页嵌入

通过 <elevenlabs-convai> 自定义元素和 @elevenlabs/convai-widget-embed 脚本嵌入网站。支持属性定制:avatar-image-url、action-text、start-call-text、end-call-text。

拨出电话

通过 Twilio 集成实现拨出电话,支持 Python、JavaScript 和 cURL 调用。可配置 agent_id、agent_phone_number_id、to_number、call_recording_enabled 等参数。

智能体管理

推荐使用 CLI 管理:

  • elevenlabs agents list — 列出智能体并检查状态
  • elevenlabs agents status — 查看状态
  • elevenlabs agents pull — 从平台导入智能体到本地配置(支持 --agent <agent-id> 指定单个)
  • elevenlabs agents push — 推送本地更改到平台(支持 --dry-run 预览)
  • elevenlabs tools add-webhook "Weather API" — 添加 webhook 工具
  • elevenlabs tools add-client "UI Tool" — 添加 client 工具

CLI 项目结构包含:agents.json(智能体定义)、tools.json(工具配置)、tests.json(测试配置)、agent_configs/、tool_configs/、test_configs/ 目录。

SDK 也支持 list、get、update(部分更新)、delete 等操作。

使用方式

安装与认证

npm install -g @elevenlabs/cli
elevenlabs auth login

CLI 快速开始

elevenlabs agents init
elevenlabs agents add "My Assistant" --template complete
elevenlabs agents push

可用模板:complete、minimal、voice-only、text-only、customer-service、assistant。

Python 创建示例

from elevenlabs import ElevenLabs

client = ElevenLabs()

agent = client.conversational_ai.agents.create(
    name="My Assistant",
    enable_versioning=True,
    conversation_config={
        "agent": {
            "first_message": "Hello! How can I help?",
            "language": "en",
            "prompt": {
                "prompt": "You are a helpful assistant. Be concise and friendly.",
                "llm": "gemini-2.0-flash",
                "temperature": 0.7
            }
        },
        "tts": {"voice_id": "JBFqnCBsd6RMkjVDRZzb"}
    }
)

JavaScript 创建示例

import { ElevenLabsClient } from "@elevenlabs/elevenlabs-js";
const client = new ElevenLabsClient();

const agent = await client.conversationalAi.agents.create({
  name: "My Assistant",
  enableVersioning: true,
  conversationConfig: {
    agent: {
      firstMessage: "Hello! How can I help?",
      language: "en",
      prompt: {
        prompt: "You are a helpful assistant.",
        llm: "gemini-2.0-flash",
        temperature: 0.7
      }
    },
    tts: { voiceId: "JBFqnCBsd6RMkjVDRZzb" }
  }
});

cURL 创建示例

curl -X POST "https://api.elevenlabs.io/v1/convai/agents/create?enable_versioning=true" \
  -H "xi-api-key: $ELEVENLABS_API_KEY" -H "Content-Type: application/json" \
  -d '{"name": "My Assistant", "conversation_config": {"agent": {"first_message": "Hello!", "language": "en", "prompt": {"prompt": "You are helpful.", "llm": "gemini-2.0-flash"}}, "tts": {"voice_id": "JBFqnCBsd6RMkjVDRZzb"}}}'

客户端工具示例

clientTools: {
  show_product: async ({ productId }) => {
    document.getElementById("product").src = `/products/${productId}`;
    return { success: true };
  }
}

拨出电话示例

Python:

response = client.conversational_ai.twilio.outbound_call(
    agent_id="your-agent-id",
    agent_phone_number_id="your-phone-number-id",
    to_number="+1234567890",
    call_recording_enabled=True
)

JavaScript:

const response = await client.conversationalAi.twilio.outboundCall({
  agentId: "your-agent-id",
  agentPhoneNumberId: "your-phone-number-id",
  toNumber: "+1234567890",
  callRecordingEnabled: true,
});

cURL:

curl -X POST "https://api.elevenlabs.io/v1/convai/twilio/outbound-call" \
  -H "xi-api-key: $ELEVENLABS_API_KEY" -H "Content-Type: application/json" \
  -d '{"agent_id": "your-agent-id", "agent_phone_number_id": "your-phone-number-id", "to_number": "+1234567890", "call_recording_enabled": true}'

错误处理

常见错误码:401(无效密钥)、404(未找到)、422(无效配置)、429(速率限制)。

适用场景

  • 语音助手
  • 客服机器人
  • 交互式语音角色
  • 需要实时语音对话的 Web 应用
  • 通过 Twilio 进行电话外呼的场景

限制

  • 具体定价与收费信息暂未提供。
  • 可用模型目录可通过 API 查询,具体可用性视账户与环境而定。