mcpField
A
agents

agents

github.com/connoradsAgent 工作流1862 次安装今天更新
代码仓库

关于 agents

面向开发者的 ElevenLabs 语音 AI Agent 构建与管理工具,提供 CLI 和 SDK 工作流,并支持配置 LLM、工具、网页嵌入及电话呼叫。

主要功能

  1. 01通过 CLI 和 SDK 创建及管理 Agent
  2. 02配置多个 LLM 提供商
  3. 03添加 webhook、客户端和系统工具
  4. 04将 Agent 嵌入网站
  5. 05通过 Twilio 发起外呼

适用场景

  1. 01使用 CLI 模板创建语音 Agent
  2. 02让 Agent 连接自定义端点
  3. 03将语音 Agent 添加到网站
  4. 04使用 Agent 发起外呼

安装

复制下面的命令,在终端中运行。

$npx skills add https://github.com/connorads/dotfiles --skill agents

安装后在 Claude Code 中输入/agents确认已加载。

包含的文件

除 SKILL.md 外,安装时一起下载的参考资料和脚本。

references/
agent-configuration.md
client-tools.md
installation.md
outbound-calls.md
widget-embedding.md

详细介绍

ElevenLabs Agents Platform

构建具有自然对话能力、支持多种 LLM 提供商、可使用自定义工具并轻松嵌入网页的语音 AI Agent。

**设置:**有关 CLI 和 SDK 设置,请参阅安装指南。

使用 CLI 快速开始

ElevenLabs CLI 是创建和管理 Agent 的推荐方式:

# Install CLI and authenticate
npm install -g @elevenlabs/cli
elevenlabs auth login

# Initialize project and create an agent
elevenlabs agents init
elevenlabs agents add "My Assistant" --template complete

# Push to ElevenLabs platform
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"}}}'

开始对话

**服务端(Python):**获取用于客户端连接的签名 URL:

signed_url = client.conversational_ai.conversations.get_signed_url(
    agent_id="your-agent-id",
    environment="staging",
)

客户端(JavaScript):

import { Conversation } from "@elevenlabs/client";

const conversation = await Conversation.startSession({
  agentId: "your-agent-id",
  environment: "staging",
  onMessage: (msg) => console.log("Agent:", msg.message),
  onUserTranscript: (t) => console.log("User:", t.message),
  onError: (e) => console.error(e)
});

**React Hook:**将 Hook 使用方包装在 ConversationProvider 中。对于会话控制和 UI 状态,优先使用 useConversationControls 和 useConversationStatus 等粒度更细的 Hook;仍可使用 useConversation 这个便捷的一体化 Hook。如果希望由 React 在同一处处理对话错误,请传入 onError 等提供程序级回调。

import {
  ConversationProvider,
  useConversationControls,
  useConversationStatus,
} from "@elevenlabs/react";

function Agent({ signedUrl }: { signedUrl: string }) {
  const { startSession, endSession } = useConversationControls();
  const { status } = useConversationStatus();

  if (status === "connected") {
    return <button onClick={endSession}>End conversation</button>;
  }

  return (
    <button onClick={() => startSession({ signedUrl })}>
      Start conversation
    </button>
  );
}

function App({ signedUrl }: { signedUrl: string }) {
  return (
    <ConversationProvider
      onError={(error) => console.error("Conversation error:", error)}
    >
      <Agent signedUrl={signedUrl} />
    </ConversationProvider>
  );
}

配置

提供商模型
OpenAIgpt-5.4、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
Anthropicclaude-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
Googlegemini-3.1-flash-lite-preview、gemini-3.1-pro-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
ElevenLabsglm-45-air-fp8、qwen3-30b-a3b、qwen35-35b-a3b、qwen35-397b-a17b、gpt-oss-120b
自定义custom-llm(使用你自己的端点)

使用 GET /v1/convai/llm/list 查看当前模型目录,包括弃用状态、令牌/上下文限制、图像输入支持等能力标志,以及特定模型对推理力度的支持情况。

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

轮次响应积极程度: patient(等待用户更长时间以便其说完)、normal 或 eager(快速响应)

所有选项请参阅Agent 配置。

工具

使用 Webhook、客户端或内置系统工具扩展 Agent。工具定义在 conversation_config.agent.prompt 中:

工作区环境变量可按环境解析服务端工具 URL、标头和身份验证连接;运行时系统变量(如 {{system__conversation_history}})则可在需要时将完整对话上下文传入工具调用。

"prompt": {
    "prompt": "You are a helpful assistant that can check the weather.",
    "llm": "gemini-2.0-flash",
    "tools": [
        # Webhook: server-side API call
        {"type": "webhook", "name": "get_weather", "description": "Get weather",
         "api_schema": {"url": "https://api.example.com/weather", "method": "POST",
             "request_body_schema": {"type": "object", "properties": {"location": {"type": "string"}}, "required": ["location"]}}},
        # Client: runs in the browser
        {"type": "client", "name": "show_product", "description": "Display a product",
         "parameters": {"type": "object", "properties": {"productId": {"type": "string"}}, "required": ["productId"]}}
    ],
    "built_in_tools": {
        "end_call": {},
        "transfer_to_number": {"transfers": [{"transfer_destination": {"type": "phone", "phone_number": "+1234567890"}, "condition": "User asks for human support"}]}
    }
}

客户端工具在浏览器中运行:

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

完整文档请参阅客户端工具参考。

嵌入 Widget

<elevenlabs-convai agent-id="your-agent-id"></elevenlabs-convai>
<script src="https://unpkg.com/@elevenlabs/convai-widget-embed" async type="text/javascript"></script>

可使用以下属性进行自定义:avatar-image-url、action-text、start-call-text、end-call-text。

所有选项请参阅Widget 嵌入参考。

外呼

通过 Twilio 集成,使用你的 Agent 拨打外呼电话:

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
)
print(f"Call initiated: {response.conversation_id}")
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}'

有关配置覆盖项和动态变量,请参阅外呼参考。

管理 Agent

使用 CLI(推荐)
# List agents and check status
elevenlabs agents list
elevenlabs agents status

# Import agents from platform to local config
elevenlabs agents pull                      # Import all agents
elevenlabs agents pull --agent <agent-id>   # Import specific agent

# Push local changes to platform
elevenlabs agents push              # Upload configurations
elevenlabs agents push --dry-run    # Preview changes first

# Add tools
elevenlabs tools add-webhook "Weather API"
elevenlabs tools add-client "UI Tool"
项目结构

CLI 会创建用于管理 Agent 的项目结构:

your_project/
├── agents.json       # Agent definitions
├── tools.json        # Tool configurations
├── tests.json        # Test configurations
├── agent_configs/    # Individual agent configs
├── tool_configs/     # Individual tool configs
└── test_configs/     # Individual test configs
SDK 示例
# List
agents = client.conversational_ai.agents.list()

# Get
agent = client.conversational_ai.agents.get(agent_id="your-agent-id")

# Update (partial - only include fields to change)
client.conversational_ai.agents.update(agent_id="your-agent-id", name="New Name")
client.conversational_ai.agents.update(agent_id="your-agent-id",
    conversation_config={
        "agent": {"prompt": {"prompt": "New instructions", "llm": "claude-sonnet-4"}}
    })

# Delete
client.conversational_ai.agents.delete(agent_id="your-agent-id")

所有配置选项和 SDK 示例请参阅Agent 配置。

错误处理

try:
    agent = client.conversational_ai.agents.create(...)
except Exception as e:
    print(f"API error: {e}")

常见错误:401(密钥无效)、404(未找到)、422(配置无效)、429(请求频率超限)

参考资料

评论

支持 Markdown