本文根据 Agent 场景下经常遇到的问题梳理可能原因,并给出推荐的使用方式,便于问题定位并修改。
| 常见问题 | 可能的原因 | 推荐使用方式 |
|---|---|---|
| 多轮工具调用效果随轮数增加而下降 | 思维链未回传,导致每一轮工具返回后丢失思维链 | 回传思维链 |
| 相同模型、相同 Prompt 在不同实现下任务通过率差异明显 | 参数配置未按推荐值;上下文回传不完整 | 配置关键参数 回传思维链 |
回答被截断、工具参数 JSON 不完整、finish_reason / stop_reason 为 length |
max_tokens 未显式传入或值过小 |
调整输出长度参数 |
| Prompt Cache 命中率异常偏低 | System Prompt 或工具定义在轮次间发生变化;Session 内改动参数 | 遵循缓存命中原则 |
推荐使用方式#
三种接口在字段名、层级与默认返回策略上存在差异。请先根据模型选择对应的回传方式,再按对应表格配置字段。
回传思维链原文#
支持的模型:
- Doubao 模型:doubao-seed-2-0-pro-260215
- 开源模型:deepseek-v4-flash-ga-260731、deepseek-v4-1-flash-261017、deepseek-v4-1-flash-260910、glm-5-2-260617
| 维度 | Chat API | Responses API | Messages API |
|---|---|---|---|
| 思维链原文字段 使用说明:需要将思维链原文拼回下一轮请求 |
choices[].message.reasoning_content |
output[reasoning].summary[].text,也可配置 store: true 后使用 previous_response_id |
content[thinking].thinking |
回传思维链密文#
支持的模型:
- Doubao 模型:doubao-seed-evolving、doubao-seed-2-1-pro-260915、doubao-seed-2-1-lite-260915、doubao-seed-2-1-pro-260628、doubao-seed-2-1-turbo-260628、doubao-seed-2-0-lite-260428
| 维度 | Chat API | Responses API | Messages API |
|---|---|---|---|
| 思维链密文字段 使用说明:需要将思维链密文拼回下一轮请求 |
choices[].message.encrypted_content |
output[reasoning].encrypted_content,也可配置 store: true 后使用 previous_response_id |
content[thinking].signature |
| 是否默认返回思维链密文字段 | 是 | 是 | 是 |
| 思维链摘要字段 使用说明:请勿只回传思维链摘要,会导致模型效果下降。 |
choices[].message.reasoning_content |
output[reasoning].summary[].text |
content[thinking].thinking |
通用参数配置#
两类模型的通用参数配置一致,按下表配置即可。
| 维度 | Chat API | Responses API | Messages API |
|---|---|---|---|
| 配置输出长度参数 | max_tokens / max_completion_tokens建议显式配置,不低于 128000。 |
max_output_tokens建议显式配置,不低于 128000。 |
max_tokens建议显式配置,不低于 128000。 |
| 配置 thinking 参数 | {"type": "enabled"}建议显式开启。 |
{"type": "enabled"}建议显式开启。 |
{"type": "enabled"}建议显式开启。 |
| 配置 reasoning_effort 参数 | "reasoning_effort": "high"建议 high 或以上。 |
"reasoning": {"effort": "high"}建议 high 或以上。 |
"output_config": {"effort": "high"}建议 high 或以上。 |
| 配置 temperature / top_p 参数 | 建议 temperature=1、top_p=0.95 |
建议 temperature=1、top_p=0.95 |
建议 temperature=1、top_p=0.95 |
核心机制:思维链回传#
为什么需要回传思维链#
在 Agent 场景中,一个任务通常会经历多轮“推理 -> 调用工具 -> 等待结果 -> 继续推理 -> 调用工具”,工具结果返回后,模型需要继续在该推理链路上把后续步骤做完。
如果不回传思维链,会有以下影响:
- 推理连续性会被打断:工具结果返回后,模型只能根据可见对话文本重新构建上下文。对于复杂任务这些隐含的中间判断无法被完整还原,容易出现推理衔接不顺或逻辑断层的情况。
- 多步执行稳定性下降:由于缺少中间推理状态,模型可能重复做已做过的推导,或者在下一步采用与前一步不一致的假设,导致任务执行跑偏、步骤不稳定,影响结果的一致性与可复现性。
- 整体成本上升:回传的思维链会与 tool result 一起参与缓存,更容易命中 Prompt Cache。对包含多次工具调用的场景来说,缓存命中意味着减少重复 token 消耗,从而降低整体成本。
回传方式与支持模型#
方舟大模型的思维链回传方式分为两类:
- 回传思维链原文(明文):将响应中的思维链原文直接拼回下一轮请求。
- 回传思维链密文:将响应中的密文原样拼回下一轮请求。
两类回传方式支持的模型不同,具体参见 推荐使用方式。
关键规则#
- 思维链密文字段要求原样、完整回传。任何篡改或截断都会返回
Invalid signature错误。 - 不回传思维链密文不会触发报错,但会影响推理效果。
- 思维链密文字段优先级高于思维链摘要:同时传入时,摘要会被忽略。
- 输出思维链部分计费会按原始思维链 token 计算,如果不回传思维链密文,已付费的思维链不仅没有起到效果,还可能会导致推理效果下降。
回传思维链密文使用示例#
非流式响应#
对于非流式响应,密文位于 assistant 消息的扁平字段 encrypted_content,与 reasoning_content、tool_calls 同级。encrypted_content 默认返回,无需额外声明。
正确使用方式:将响应中的 assistant message 对象整体加入到下一轮 messages 中,避免按字段挑选重建。
curl https://ark.cn-beijing.volces.com/api/v3/chat/completions \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $ARK_API_KEY" \
-d '{
"model": "doubao-seed-evolving",
"thinking": {"type": "enabled"},
"temperature": 1,
"top_p": 0.95,
"max_tokens": 128000,
"messages": [
{"role": "system", "content": "你是人工智能助手。"},
{"role": "user", "content": "今天是 2026-08-10(星期一)。明天北京天气怎么样?"},
{
"role": "assistant",
"reasoning_content": "用户问明天北京天气,明天是 2026-08-11,调用天气工具。",
"encrypted_content": "<完整密文,原样回传>",
"tool_calls": [
{
"id": "call_wiezxeyae8jzxl3jx8nhfgb5",
"type": "function",
"function": {"name": "get_weather", "arguments": "{\"location\":\"北京\",\"date\":\"2026-08-11\"}"}
}
]
},
{
"role": "tool",
"tool_call_id": "call_wiezxeyae8jzxl3jx8nhfgb5",
"content": "2026-08-11 北京:阴,11~16°C,北风4级。"
}
],
"tools": [
{
"type": "function",
"function": {
"name": "get_weather",
"description": "查询指定城市指定日期的天气",
"parameters": {
"type": "object",
"properties": {
"location": {"type": "string", "description": "城市名,如北京、上海"},
"date": {"type": "string", "description": "日期,格式 YYYY-MM-DD"}
},
"required": ["location", "date"]
}
}
}
]
}'
流式响应#
流式响应下,思维链密文由独立的 chunk 下发,时机是思维链输出完成之后、正式应答开始之前。该 chunk 的 content 与 reasoning_content可能均为空。
正确使用方式:请务必在流式合并逻辑中对 encrypted_content 字段做处理。仅处理 delta.content 或 delta.reasoning_content,会直接导致丢失思维链密文,从而影响推理效果。
curl https://ark.cn-beijing.volces.com/api/v3/chat/completions \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $ARK_API_KEY" \
-d '{
"model": "doubao-seed-evolving",
"stream": true,
"thinking": {"type": "enabled"},
"max_tokens": 128000,
"messages": [
{"role": "user", "content": "今天是 2026-08-10。明天北京天气怎么样?"}
]
}'
响应片段(示意):
data: {"choices":[{"delta":{"reasoning_content":"用户问明天"}}]}
data: {"choices":[{"delta":{"reasoning_content":"北京天气…"}}]}
data: {"choices":[{"delta":{"content":"","reasoning_content":"","encrypted_content":"<完整密文>"}}]}
data: {"choices":[{"delta":{"content":"明天北京"}}]}
data: [DONE]
非流式响应#
对于非流式响应,密文位于 output 数组内 type == "reasoning" 的 item。
回传思维链密文的方式如下:
- previous_response_id:注意需显式配置
store: true。由服务端托管 session 状态,客户端无需自行搬运历史 item,自动获取思维链密文并回传给模型参与推理。 - 手动回传思维链密文:从响应中获取 Reasoning item,并在后续请求中原样回传
encrypted_content。
手动回传思维链密文注意事项:
- Reasoning item 的
id必须原样带回,不能自行生成。 - 回放时
content可以是空数组[],但encrypted_content不能为空。 - 连续多次工具调用时,从最后一条 user message 之后的所有 item(
reasoning/function_call/function_call_output)必须按原顺序全部带回,不能只带最后一个。
手动回传思维链密文的示例如下:
curl https://ark.cn-beijing.volces.com/api/v3/responses \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $ARK_API_KEY" \
-d '{
"model": "doubao-seed-evolving",
"store": false,
"reasoning": {"effort": "high", "summary": "detailed"},
"max_output_tokens": 128000,
"input": [
{"type": "message", "role": "user", "content": "今天是 2026-08-10(星期一)。明天天气怎么样?"},
{
"id": "rs_0c2e0389c1bdc80f016a79c44c1fd08198bbdcb852ca75789b",
"type": "reasoning",
"content": [],
"encrypted_content": "<完整密文,原样回传>",
"summary": [
{"type": "summary_text", "text": "先取用户所在城市,再查 2026-08-11 的天气。"}
]
},
{
"id": "fc_0c2e0389c1bdc80f016a79c44d9fac81988abe3597d1fbba88",
"type": "function_call",
"status": "completed",
"call_id": "call_tjOpXT7tq4KbtdnpQYdBNTXz",
"name": "get_location",
"arguments": "{\"location_level\":\"city\"}"
},
{
"type": "function_call_output",
"call_id": "call_tjOpXT7tq4KbtdnpQYdBNTXz",
"output": "北京"
},
{
"id": "fc_0c2e0389c1bdc80f016a79c451d4348198a1c4eb858f8a858b",
"type": "function_call",
"status": "completed",
"call_id": "call_cf3Sz3cE2fZkZBPdez5P9Ecb",
"name": "get_weather",
"arguments": "{\"location\":\"北京\",\"date\":\"2026-08-11\"}"
},
{
"type": "function_call_output",
"call_id": "call_cf3Sz3cE2fZkZBPdez5P9Ecb",
"output": "2026-08-11 北京:阴,11~16°C,北风4级。"
}
],
"tools": [
{
"type": "function",
"name": "get_location",
"description": "获取用户当前位置",
"parameters": {
"type": "object",
"properties": {
"location_level": {"type": "string", "description": "所需粒度:country / province / city / street"}
},
"required": ["location_level"],
"additionalProperties": false
},
"strict": true
},
{
"type": "function",
"name": "get_weather",
"description": "查询指定城市指定日期的天气",
"parameters": {
"type": "object",
"properties": {
"location": {"type": "string", "description": "城市名"},
"date": {"type": "string", "description": "日期,格式 YYYY-MM-DD"}
},
"required": ["location", "date"],
"additionalProperties": false
},
"strict": true
}
]
}'
流式响应#
对于流式响应,思维链密文通过 response.output_item.added / response.output_item.done / response.completed 等相关事件下发,需要按事件中 encrypted_content 字段非空过滤,并获取思维链密文。
获取到思维链密文后,回传方式参考上述示例。
密文位于 assistant content 数组中 type == "thinking" 的块的 signature 字段(Anthropic 协议原生命名)。
正确使用方式:
- thinking 块必须整块回传(
thinking文本 +signature一起),并保持在tool_use块之前的原始顺序。 - 请勿按
type == "thinking"做白名单过滤后重新构造 content 数组。顺序或块被改动会导致校验失败。
curl https://ark.cn-beijing.volces.com/api/v3/compatible/v1/messages \
-H "Content-Type: application/json" \
-H "x-api-key: $ARK_API_KEY" \
-H "anthropic-version: 2023-06-01" \
-d '{
"model": "doubao-seed-evolving",
"max_tokens": 128000,
"thinking": {"type": "enabled"},
"messages": [
{"role": "user", "content": "今天是 2026-08-10(星期一)。明天天气怎么样?"},
{
"role": "assistant",
"content": [
{
"type": "thinking",
"thinking": "用户问明天天气,明天是 2026-08-11。需要先获取城市,再查天气。",
"signature": "<完整密文,原样回传>"
},
{
"type": "tool_use",
"id": "tool_4U01J2huMeLhTlTKyrU5rhI5",
"name": "get_location",
"input": {"location_level": "city"}
}
]
},
{
"role": "user",
"content": [
{
"type": "tool_result",
"tool_use_id": "tool_4U01J2huMeLhTlTKyrU5rhI5",
"content": "北京"
}
]
}
],
"tools": [
{
"name": "get_location",
"description": "获取用户当前位置",
"input_schema": {
"type": "object",
"properties": {
"location_level": {"type": "string", "description": "所需粒度:country / province / city / street"}
},
"required": ["location_level"]
}
},
{
"name": "get_weather",
"description": "查询指定城市指定日期的天气",
"input_schema": {
"type": "object",
"properties": {
"location": {"type": "string", "description": "城市名"},
"date": {"type": "string", "description": "日期,格式 YYYY-MM-DD"}
},
"required": ["location", "date"]
}
}
]
}'