Appearance
对话 WebSocket
ws://host/api/v1/conversations/{conversation_id}/ws?token=xxx客户端消息类型
1. append_message — 发送消息
追加一条用户消息或工具响应到对话。不会自动触发 AI 补全,需要额外发送 request_completion。
json
{
"type": "append_message",
"payload": {
"message": {
"role": "user",
"content": "你好,帮我分析一下这个项目"
}
},
"request_id": "req-001"
}消息内容格式
纯文本:
json
{
"role": "user",
"content": "你好"
}多模态(图片 + 文本):
json
{
"role": "user",
"content": [
{
"type": "text",
"text": "描述一下这张图片"
},
{
"type": "image_url",
"image_url": {
"url": "https://example.com/image.jpg",
"detail": "high"
}
}
]
}工具响应(用户对 awaiting_input 工具的回复):
json
{
"role": "tool",
"tool_call_id": "call_abc123",
"content": "用户的回答内容"
}支持的 content part 类型
| 类型 | 说明 |
|---|---|
text | 文本 |
image_url | 图片(URL 或 base64 data URI) |
input_audio | 音频(base64) |
file | 文件引用 |
服务端确认
json
{
"type": "message_appended",
"request_id": "req-001"
}2. request_completion — 请求 AI 回复
请求 AI 角色基于当前对话历史生成回复。
json
{
"type": "request_completion",
"payload": {},
"request_id": "req-002"
}可选参数
json
{
"type": "request_completion",
"payload": {
"disabled_tools": ["WebSearchFunction", "CodeInterpreterFunction"]
},
"request_id": "req-002"
}| 字段 | 类型 | 说明 |
|---|---|---|
disabled_tools | string[] | null | 本次补全禁用的工具列表 |
响应流
发送后,服务端会推送一系列流式消息,详见 消息类型速查。
3. stop_completion — 停止 AI 回复
立即中断正在进行的 AI 回复。
json
{
"type": "stop_completion",
"payload": {},
"request_id": "req-003"
}服务端响应
json
{
"type": "stop_completion",
"partial_text": "AI 已生成的部分文本...",
"request_id": "req-003"
}4. tool_confirmation_response — 工具确认
对需要确认的工具调用进行批准或拒绝。
json
{
"type": "tool_confirmation_response",
"payload": {
"tool_call_id": "call_xyz789",
"action": "accept"
},
"request_id": "req-004"
}| 字段 | 类型 | 必填 | 说明 |
|---|---|---|---|
tool_call_id | string | 是 | 工具调用 ID(1-65536 字符) |
action | string | 是 | accept 或 reject |
reject_reason | string | 否 | 拒绝原因(最大 500 字符) |
详见 工具确认流程。
典型对话流程
工具调用流程
错误处理
所有错误通过 error 类型消息推送:
json
{
"type": "error",
"message": "余额不足",
"code": "insufficient_balance",
"request_id": "req-002"
}详见 错误码与状态码。