Appearance
DeepSeek thinking 模式多轮对话时 reasoning_content 必须回传
问题
使用 DeepSeek R1 的 thinking 模式(enable_thinking: true)进行多轮对话时,如果没有将上轮助手回复中的 reasoning_content 原样传回,后续轮次的推理链会断裂,出现:
- 推理质量明显下降
- 上下文不连贯,模型"忘记"前几轮的推理过程
- 部分框架集成时因缺少该字段而报错(如 opencode #24104)
解决方案
多轮对话时,必须把 assistant 消息的 reasoning_content 字段包含在历史消息里一并回传:
typescript
// 错误做法(丢弃 reasoning_content)
const history = [
{ role: "assistant", content: response.choices[0].message.content }
];
// 正确做法(保留 reasoning_content)
const assistantMsg = response.choices[0].message;
const history = [
{
role: "assistant",
content: assistantMsg.content,
reasoning_content: assistantMsg.reasoning_content // ← 必须保留
}
];使用 Python 的示例:
python
assistant_msg = response.choices[0].message
history.append({
"role": "assistant",
"content": assistant_msg.content,
"reasoning_content": assistant_msg.reasoning_content # 必须回传
})原因:DeepSeek R1 的 thinking 过程存储在 reasoning_content 里,这相当于模型的"工作记忆",多轮对话时需要连续传递才能保持推理连贯性。