> This is a page from the ElevenLabs documentation. For a complete page index, fetch https://elevenlabs.io/docs/llms.txt. For the full documentation in a single file, fetch https://elevenlabs.io/docs/llms-full.txt.

# 实时监控

实时监控支持通过 WebSocket 实时查看智能体对话，以及远程控制进行中的通话。此功能可实时呈现对话事件，并允许通过控制命令进行干预。

> **Note**
>
> 此功能仅限企业版使用。

## 概述

监控会话会实时传输对话事件，包括转录文本、智能体回复和修正内容。你还可以发送控制命令来结束通话、转接到电话号码，或在进行中的聊天对话中启用人工接管。

## WebSocket 端点

使用监控端点连接到实时对话：

```
wss://api.elevenlabs.io/v1/convai/conversations/{conversation_id}/monitor
```

将 `{conversation_id}` 替换为要监控的对话 ID。

## 身份验证

身份验证要求：

* **API 密钥权限**：API 密钥必须具有 `ElevenLabs Agents Write` 范围
* **工作区访问权限**：必须拥有智能体工作区的 `EDITOR` 访问权限
* **标头格式**：通过 `xi-api-key` 标头包含 API 密钥

### 连接示例

```javascript
const ws = new WebSocket('wss://api.elevenlabs.io/v1/convai/conversations/conv_123/monitor', {
  headers: {
    'xi-api-key': 'your_api_key_here',
  },
});
```

```python
import websockets
import asyncio

async def monitor_conversation():
    uri = "wss://api.elevenlabs.io/v1/convai/conversations/conv_123/monitor"
    headers = {
        "xi-api-key": "your_api_key_here"
    }

    async with websockets.connect(uri, extra_headers=headers) as websocket:
        # Connection established
        pass
```

## 配置

监控对话前，请在智能体设置中启用该功能：

### 前往智能体设置

在控制台中打开智能体配置页面。

### 启用监控

在高级设置面板中，开启“监控”选项。

![智能体设置中的监控开关](/docs/_fern-img/1a4b5507a39ddf6a517772b8c01ede5f7d12429175fdf89e04c8ba910f646f8e.webp)

### 选择事件

选择要监控的事件。有关所有可用事件，请参阅[客户端事件](/docs/zh/eleven-agents/customization/events/client-events)。

> **Warning**
>
> 以下事件无法监控：VAD 分数、轮次概率指标和 ping。

> **Info**
>
> 必须先激活对话，才能连接进行监控。无法在对话开始前监控对话。

## 控制命令

通过 WebSocket 发送 JSON 命令以控制对话：

#### 结束通话

立即终止进行中的对话。

```javascript
// End the active conversation
ws.send(JSON.stringify({
  command_type: "end_call"
}));
```

```python
import json

# End the active conversation
await websocket.send(json.dumps({
    "command_type": "end_call"
}))
```

#### 转接到电话号码

将通话转接至指定电话号码。

```javascript
// Transfer to a phone number
ws.send(JSON.stringify({
  command_type: "transfer_to_number",
  parameters: {
    phone_number: "+1234567890"
  }
}));
```

```python
import json

# Transfer to a phone number
await websocket.send(json.dumps({
    "command_type": "transfer_to_number",
    "parameters": {
        "phone_number": "+1234567890"
    }
}))
```

> **Note**
>
> 必须已在智能体中配置 `transfer_to_number` 系统工具。

#### 实时上下文更新

将上下文或指令注入进行中的对话，以便智能体在回复中使用新信息。

```javascript
// Send a contextual update to the agent
ws.send(JSON.stringify({
  command_type: "contextual_update",
  parameters: {
    contextual_update: "<your update text>"
  }
}));
```

```python
import json

# Send a contextual update to the agent
await websocket.send(json.dumps({
    "command_type": "contextual_update",
    "parameters": {
        "contextual_update": "<your update text>"
    }
}))
```

#### 启用人工接管

在聊天对话中，从 AI 智能体切换至人工客服模式。

```javascript
// Enable human takeover
ws.send(JSON.stringify({
  command_type: "enable_human_takeover"
}));
```

```python
import json

# Enable human takeover
await websocket.send(json.dumps({
    "command_type": "enable_human_takeover"
}))
```

#### 以人工身份发送消息

在聊天对话中，以人工客服身份向用户发送消息。

```javascript
// Send a message as a human operator
ws.send(JSON.stringify({
  command_type: "send_human_message",
  parameters: {
    text: "How can I help you?"
  }
}));
```

```python
import json

# Send a message as a human operator
await websocket.send(json.dumps({
    "command_type": "send_human_message",
    "parameters": {
        "text": "How can I help you?"
    }
}))
```

#### 禁用人工接管

将控制权从人工客服交还给 AI 智能体。

```javascript
// Disable human takeover and return to AI
ws.send(JSON.stringify({
  command_type: "disable_human_takeover"
}));
```

```python
import json

# Disable human takeover and return to AI
await websocket.send(json.dumps({
    "command_type": "disable_human_takeover"
}))
```

## 使用场景

实时监控支持多种运营场景：

#### 质量保证

实时监控智能体对话，确保达到质量标准并发现培训机会。

#### 人工升级

识别需要人工干预的对话，并无缝接管 AI 智能体。

#### 分析仪表板

构建实时监控仪表板，汇总对话指标和性能指标。

#### 呼叫中心监管

同时监管多个智能体对话，并在必要时进行干预。

#### 自动干预

实现可分析对话内容并根据特定条件触发操作的自动化系统。

#### 培训与辅导

将实时对话用作培训材料，并提供实时反馈以提升智能体表现。

## 限制

#### 异步事件传送

监控事件会异步发送到对话中，可能不会按核心对话事件的相同顺序到达。处理事件时，请勿依赖事件顺序来重建准确的对话时间。

#### 音频数据不可用

监控端点仅传输文本事件和元数据。监控事件不包含原始音频数据。

#### 历史事件限制

连接到进行中的对话时，仅会缓存并提供最近约 100 个事件。无法检索更早的事件。

#### 事件筛选限制

启用自定义事件选择后，无法监控 VAD 分数、轮次概率指标和 ping 事件。

#### 连接时机

必须在对话开始后连接。无法在对话发起前使用监控端点。

#### 所需权限

API 密钥必须具有 `ElevenLabs Agents Write` 范围，并且必须拥有 `EDITOR` 工作区访问权限才能监控对话。

## 相关资源

#### [通话后 Webhook](/docs/zh/eleven-agents/workflows/post-call-webhooks)

在通话结束后接收对话数据和分析结果。

#### [智能体分析](/docs/zh/eleven-agents/customization/agent-analysis)

配置对话的成功评估和数据收集。

#### [客户端事件](/docs/zh/eleven-agents/customization/events/client-events)

了解对话式应用中接收的事件。

#### [WebSocket API](/docs/zh/eleven-agents/libraries/web-sockets)

了解用于实时对话的 WebSocket API。