# Agent 场景模型调用注意事项

> 全部文档的索引见 [llms.txt](https://ark.volcengine.com/llms.txt)；在任一文档页面地址后追加 `.md` 可获取该页的 Markdown 版本。

> **警告：重要注意事项**
>
> 在 Agent 场景下，如果出现模型效果不及预期、任务通过率下降、输出被截断或缓存命中率异常等情况，建议优先排查模型调用方式，[正确的使用方式](#recommended-practice) 如下：
> * **回传思维链**：按模型选择支持的回传方式。对需要回传思维链密文的模型，**必须原样回传思维链密文**。
> * **配置关键参数**：按推荐值配置输出长度参数、**thinking** 参数、**reasoning_effort** 参数、**temperature** 及 **top_p** 参数。
> * **遵循缓存命中原则**：在同一 Session 内保持采样参数、思考配置、工具定义与 **System Prompt** 的稳定，避免重置上下文缓存。

本文根据 Agent 场景下经常遇到的问题梳理可能原因，并给出推荐的使用方式，便于问题定位并修改。

> **说明**
>
> 本文聚焦"调用方式"层面的问题定位与参数配置。如需从零到一的完整接入流程（参数配置、Harness 接入、突发流量爬坡、生产上量监控），请参考 [模型接入指南（LLM） - 标准流程](/docs/go-live-access-sop)。

| 常见问题 | 可能的原因 | [推荐使用方式](#recommended-practice) |
| --- | --- | --- |
| 多轮工具调用效果随轮数增加而下降 | 思维链未回传，导致每一轮工具返回后丢失思维链 | 回传思维链 |
| 相同模型、相同 Prompt 在不同实现下任务通过率差异明显 | 参数配置未按推荐值；上下文回传不完整 | 配置关键参数 | \
| | | 回传思维链 |
| 回答被截断、工具参数 JSON 不完整、`finish_reason` / `stop_reason` 为 `length` | `max_tokens` 未显式传入或值过小 | 调整输出长度参数 |
| Prompt Cache 命中率异常偏低 | System Prompt 或工具定义在轮次间发生变化；Session 内改动参数 | 遵循缓存命中原则 |

<span id="recommended-practice"></span>
# 推荐使用方式

三种接口在字段名、层级与默认返回策略上存在差异。请先根据模型选择对应的回传方式，再按对应表格配置字段。

## 回传思维链原文

支持的模型：

* 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](/docs/chat-api) | [Responses API](/docs/create-model-responses-api) | [Messages API](/docs/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

> **警告：注意**
>
> * 使用支持的模型时，需要**回传思维链密文**，回传时的关键规则及使用示例参见 [关键规则](#key-rules)、[回传思维链密文使用示例](#encrypted-thinking-block-examples)。模型调用时返回的内容是思维链密文字段、摘要字段，不是思维链原文。模型真正用于推理的完整思维链存在于**密文字段**中。仅回传 `reasoning_content` 等摘要字段并不等同于回传了完整思维链，会直接导致模型推理效果下降。
> * 同一模型的不同版本可能属于不同类别：`doubao-seed-2.0-lite-260215` 回传思维链原文(明文)，`doubao-seed-2.0-lite-260428` 起改为回传思维链密文。升级模型版本时，请务必同步更新调用代码，否则模型质量显著下降，且不会触发 API 报错。

| 维度 | [Chat API](/docs/chat-api) | [Responses API](/docs/create-model-responses-api) | [Messages API](/docs/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](/docs/chat-api) | [Responses API](/docs/create-model-responses-api) | [Messages API](/docs/messages-api) |
| --- | --- | --- | --- |
| 配置输出长度参数 | `max_tokens` / `max_completion_tokens` | `max_output_tokens` | `max_tokens` | \
|  | 建议显式配置，不低于 `128000`。 | 建议显式配置，不低于 `128000`。 | 建议显式配置，不低于 `128000`。 |
| 配置 thinking 参数 | `{"type": "enabled"}` | `{"type": "enabled"}` | `{"type": "enabled"}` | \
|  | 建议显式开启。 | 建议显式开启。 | 建议显式开启。 |
| 配置 reasoning_effort 参数 | `"reasoning_effort": "high"` | `"reasoning": {"effort": "high"}` | `"output_config": {"effort": "high"}` | \
|  | 建议 `high` 或以上。 | 建议 `high` 或以上。 | 建议 `high` 或以上。 |
| 配置 temperature / top_p 参数| 建议 `temperature=1`、`top_p=0.95` | 建议 `temperature=1`、`top_p=0.95` | 建议 `temperature=1`、`top_p=0.95` |

> **注意**
>
> 请务必在同一 Session 内保持采样参数、思考配置、工具定义与 **System Prompt** 的稳定，任何中途修改都会重置上下文缓存。常见失效操作包括修改 **thinking** 配置、**reasoning_effort**、采样参数、**System Prompt** 或工具定义。可通过响应中的 Cache 命中 token 数观察命中情况。

<span id="thinking-replay-mechanism"></span>
# 核心机制：思维链回传

<span id="why-return-thinking"></span>
## 为什么需要回传思维链

在 Agent 场景中，一个任务通常会经历多轮“推理 -> 调用工具 -> 等待结果 -> 继续推理 -> 调用工具”，工具结果返回后，模型需要继续在该推理链路上把后续步骤做完。

如果不回传思维链，会有以下影响：

- **推理连续性会被打断**：工具结果返回后，模型只能根据可见对话文本重新构建上下文。对于复杂任务这些隐含的中间判断无法被完整还原，容易出现推理衔接不顺或逻辑断层的情况。
- **多步执行稳定性下降**：由于缺少中间推理状态，模型可能重复做已做过的推导，或者在下一步采用与前一步不一致的假设，导致任务执行跑偏、步骤不稳定，影响结果的一致性与可复现性。
- **整体成本上升**：回传的思维链会与 tool result 一起参与缓存，更容易命中 Prompt Cache。对包含多次工具调用的场景来说，缓存命中意味着减少重复 token 消耗，从而降低整体成本。

<span id="thinking-return-methods-and-models"></span>
## 回传方式与支持模型

方舟大模型的思维链回传方式分为两类：

- **回传思维链原文（明文）**：将响应中的思维链原文直接拼回下一轮请求。
- **回传思维链密文**：将响应中的密文原样拼回下一轮请求。

两类回传方式支持的模型不同，具体参见 [推荐使用方式](#recommended-practice)。

<span id="key-rules"></span>
## 关键规则

- 思维链密文字段**要求原样、完整回传**。任何篡改或截断都会返回 `Invalid signature` 错误。
- 不回传思维链密文**不会触发报错，但会影响推理效果**。
- 思维链密文字段**优先级高于思维链摘要**：同时传入时，摘要会被忽略。
- 输出思维链部分计费会按原始思维链 token 计算，如果不回传思维链密文，已付费的思维链不仅没有起到效果，还可能会导致推理效果下降。

---

<span id="encrypted-thinking-block-examples"></span>
# 回传思维链密文使用示例

**选项：Chat API（OpenAI 兼容）**

<span id="chat-api-non-streaming"></span>
### 非流式响应

对于非流式响应，密文位于 assistant 消息的**扁平字段** `encrypted_content`，与 `reasoning_content`、`tool_calls` 同级。`encrypted_content` 默认返回，无需额外声明。

**正确使用方式**：将响应中的 assistant message 对象整体加入到下一轮 `messages` 中，避免按字段挑选重建。

```Bash
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"]
          }
        }
      }
    ]
  }'
```

<span id="chat-api-streaming"></span>
### 流式响应

流式响应下，思维链密文由**独立的 chunk** 下发，时机是思维链输出完成之后、正式应答开始之前。该 chunk 的 `content` 与 `reasoning_content`**可能均为空**。

**正确使用方式**：请务必在流式合并逻辑中对 `encrypted_content` 字段做处理。仅处理 `delta.content` 或 `delta.reasoning_content`，会直接导致丢失思维链密文，从而影响推理效果。

```Bash
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。明天北京天气怎么样？"}
    ]
  }'
```

响应片段（示意）：

```text
data: {"choices":[{"delta":{"reasoning_content":"用户问明天"}}]}
data: {"choices":[{"delta":{"reasoning_content":"北京天气…"}}]}
data: {"choices":[{"delta":{"content":"","reasoning_content":"","encrypted_content":"<完整密文>"}}]}
data: {"choices":[{"delta":{"content":"明天北京"}}]}
data: [DONE]
```

**选项：Responses API**

<span id="responses-api-non-streaming"></span>
### 非流式响应

对于非流式响应，密文位于 `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`）必须按原顺序全部带回，不能只带最后一个。

手动回传思维链密文的示例如下：

```Bash
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
      }
    ]
  }'
```

<span id="responses-api-streaming"></span>
### 流式响应

对于流式响应，思维链密文通过 `response.output_item.added` / `response.output_item.done` / `response.completed` 等相关事件下发，需要按事件中 **encrypted_content** 字段非空过滤，并获取思维链密文。

获取到思维链密文后，回传方式参考上述示例。

**选项：Messages API**

密文位于 assistant content 数组中 `type == "thinking"` 的块的 **`signature`** 字段（Anthropic 协议原生命名）。

**正确使用方式**：

- thinking 块必须**整块回传**（`thinking` 文本 + `signature` 一起），并保持在 `tool_use` 块**之前**的原始顺序。
- **请勿按 `type == "thinking"` 做白名单过滤后重新构造 content 数组**。顺序或块被改动会导致校验失败。

```Bash
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"]
        }
      }
    ]
  }'
```
