Appearance
DeepSeek 思考模式让模型在输出答案前先生成一段内部推理链(reasoning_content),大幅提升复杂问题的准确性。本文介绍如何开启思考模式、控制推理力度,以及多轮对话和工具调用场景下正确处理 reasoning_content 的方法。
DeepSeek 思考模式
思考模式让模型在回答前先"想一想"——生成一段推理过程(reasoning_content),再基于推理给出最终答案(content)。
开启方式
typescript
const response = await client.chat.completions.create({
model: "deepseek-v4-pro",
messages: [{ role: "user", content: "证明 √2 是无理数" }],
extra_body: {
thinking: { type: "enabled" }, // 开启思考模式
reasoning_effort: "high", // 推理力度:high 或 max
},
});
console.log(response.choices[0].message.reasoning_content); // 推理过程
console.log(response.choices[0].message.content); // 最终答案Python 版本:
python
response = client.chat.completions.create(
model="deepseek-v4-pro",
messages=[{"role": "user", "content": "证明 √2 是无理数"}],
extra_body={
"thinking": {"type": "enabled"},
"reasoning_effort": "high",
},
)
print(response.choices[0].message.reasoning_content)
print(response.choices[0].message.content)参数说明
| 参数 | 值 | 说明 |
|---|---|---|
thinking.type | "enabled" / "disabled" | 开关思考模式,默认 enabled |
reasoning_effort | "high" / "max" | 推理力度,max 更彻底但更慢更贵 |
注意:
- 默认思考开关为
enabled,不传参数时自动开启temperature、top_p等参数在思考模式下无效(设置不报错,但不生效)- 普通请求默认
reasoning_effort: "high";Agent 场景建议用"max"
多轮对话处理
关键规则: 在没有工具调用的纯对话中,不需要把 reasoning_content 传回下一轮。
typescript
// 第一轮
const resp1 = await client.chat.completions.create({
model: "deepseek-v4-pro",
messages: [{ role: "user", content: "分析一下 React 和 Vue 的区别" }],
extra_body: { thinking: { type: "enabled" } },
});
const assistantMsg = resp1.choices[0].message;
// 第二轮:只传 content,不传 reasoning_content
const resp2 = await client.chat.completions.create({
model: "deepseek-v4-pro",
messages: [
{ role: "user", content: "分析一下 React 和 Vue 的区别" },
{
role: "assistant",
content: assistantMsg.content, // ✅ 只传 content
// reasoning_content 不传,会被自动忽略
},
{ role: "user", content: "哪个更适合企业级项目?" },
],
extra_body: { thinking: { type: "enabled" } },
});工具调用场景
当思考模式与 Tool Calls 混用时,reasoning_content 必须回传,否则返回 400 错误:
typescript
// 有工具调用时,assistant 消息必须包含 reasoning_content
messages: [
{ role: "user", content: "..." },
{
role: "assistant",
content: assistantMsg.content,
reasoning_content: assistantMsg.reasoning_content, // ✅ 必须传
tool_calls: assistantMsg.tool_calls,
},
{
role: "tool",
tool_call_id: toolCallId,
content: toolResult,
},
]思考模式 vs 无思考模式
| 无思考模式 | 思考模式(high) | 思考模式(max) | |
|---|---|---|---|
| 响应速度 | 快 | 中 | 慢 |
| 复杂推理准确性 | 一般 | 高 | 最高 |
| Token 消耗 | 低 | 中(reasoning_content 计费) | 高 |
| 适用场景 | 简单问答、格式化 | 代码、数学、分析 | 复杂 Agent、多步推理 |
与 Claude 扩展思考(Extended Thinking)对比:两者设计思路相同,都是在最终答案前生成推理链。DeepSeek 使用
reasoning_content字段,Claude 使用thinkingcontent block。
常见问题
Q: reasoning_content 会计入 token 费用吗?
A: 会,reasoning_content 的 token 数量计入输出 token 计费。如果不需要查看推理过程,可以设 thinking: {type: "disabled"} 节省成本。
Q: 什么场景必须开思考模式?
A: 数学证明、复杂代码调试、多步推理、需要"先分析再回答"的任务。简单 QA、翻译、格式转换等无需开启。
Q: 思考模式下 stream 流式输出怎么处理?
A: 流式输出时,reasoning_content 的 delta 在 choices[0].delta.reasoning_content 中,最终答案在 choices[0].delta.content 中。需要先等 reasoning_content 输出完毕,再开始显示 content。