fix(subagent): preserve reasoning_content in assistant messages#1848
Merged
Re-bin merged 1 commit intoHKUDS:mainfrom Mar 11, 2026
Merged
fix(subagent): preserve reasoning_content in assistant messages#1848Re-bin merged 1 commit intoHKUDS:mainfrom
Re-bin merged 1 commit intoHKUDS:mainfrom
Conversation
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 HKUDS#1834
This was referenced Mar 11, 2026
Re-bin
added a commit
that referenced
this pull request
Mar 11, 2026
sorker
pushed a commit
to sorker/nanobot
that referenced
this pull request
Mar 24, 2026
Wattysaid
pushed a commit
to kieran-assistant/nanobot
that referenced
this pull request
Apr 3, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
_run_subagent()was silently droppingreasoning_contentandthinking_blockswhen building assistant messages for the conversation historyreasoning_contenton every assistant message when thinking mode is active, causing a400 BadRequestErroron the second LLM round-tripAgentLoopalready preserves these fields correctly viaContextBuilder.add_assistant_message()— this fix aligns the subagent loop with that behaviorRoot Cause
In
subagent.py, the assistant message was built as a plain dict withoutreasoning_content:Deepseek's API returns
400with:Fix
Conditionally include
reasoning_contentandthinking_blockswhen the provider returns them, matching howContextBuilder.add_assistant_message()handles this in the main agent loop:Verification
Bug reproduced and fix verified by calling Deepseek Reasoner API (
deepseek-reasoner) directly:Full test output:
Test plan
reasoning_content→ 400 error)reasoning_content→ success)Closes #1834
🤖 Generated with Claude Code