fix(subagent): preserve reasoning_content in assistant messages

Subagent's _run_subagent() was dropping reasoning_content and
thinking_blocks when building assistant messages for the conversation
history. Providers like Deepseek Reasoner require reasoning_content on
every assistant message when thinking mode is active, causing a 400
BadRequestError on the second LLM round-trip.

Align with the main AgentLoop which already preserves these fields via
ContextBuilder.add_assistant_message().

Closes #1834
This commit is contained in:
lailoo
2026-03-11 00:47:09 +08:00
parent 947ed508ad
commit 2ffeb9295b

View File

@@ -145,11 +145,19 @@ class SubagentManager:
}
for tc in response.tool_calls
]
messages.append({
assistant_msg: dict[str, Any] = {
"role": "assistant",
"content": response.content or "",
"tool_calls": tool_call_dicts,
})
}
# Preserve reasoning_content for providers that require it
# (e.g. Deepseek Reasoner mandates this field on every
# assistant message when thinking mode is active).
if response.reasoning_content is not None:
assistant_msg["reasoning_content"] = response.reasoning_content
if response.thinking_blocks:
assistant_msg["thinking_blocks"] = response.thinking_blocks
messages.append(assistant_msg)
# Execute tools
for tool_call in response.tool_calls: