fix: preserve empty reasoning_content in thinking mode history

This commit is contained in:
JOJO 2026-04-25 16:35:02 +08:00
parent d541d9bd30
commit d076e334d9
2 changed files with 9 additions and 7 deletions

View File

@ -289,9 +289,11 @@ class MainTerminalContextMixin:
"role": conv["role"],
"content": conv["content"]
}
reasoning = conv.get("reasoning_content")
if reasoning:
message["reasoning_content"] = reasoning
# 对于思考模式(如 DeepSeek thinkingassistant 历史消息中的
# reasoning_content 即使为空字符串也需要原样回传,否则下一轮可能被
# API 判定为“未回传 reasoning_content”并返回 400。
if "reasoning_content" in conv:
message["reasoning_content"] = conv.get("reasoning_content", "")
# 如果有工具调用信息,添加到消息中
tool_calls = conv.get("tool_calls") or []
if tool_calls and self._tool_calls_followed_by_tools(conversation, idx, tool_calls):

View File

@ -1200,10 +1200,10 @@ async def handle_task_with_sender(
assistant_message = {
"role": "assistant",
"content": assistant_content,
"tool_calls": tool_calls
"tool_calls": tool_calls,
# thinking 模式下reasoning_content 需要原样回传;即使该轮为空字符串也保留字段
"reasoning_content": current_thinking or "",
}
if current_thinking:
assistant_message["reasoning_content"] = current_thinking
messages.append(assistant_message)
if assistant_content or current_thinking or tool_calls:
@ -1211,7 +1211,7 @@ async def handle_task_with_sender(
"assistant",
assistant_content,
tool_calls=tool_calls if tool_calls else None,
reasoning_content=current_thinking or None
reasoning_content=current_thinking or ""
)
# 为下一轮迭代重置流状态标志,但保留 full_response 供上面保存使用