fix: ensure reasoning_content consistency for DeepSeek-compatible APIs - #15982
Closed
highland0971 wants to merge 1 commit into
Closed
highland0971 wants to merge 1 commit into
highland0971 wants to merge 1 commit into
Conversation
DeepSeek V4 thinking mode (and compatible APIs like Ark Coding Plan) requires reasoning_content on EVERY assistant message in the conversation history. An inconsistent mix (some with, some without) triggers HTTP 400: 'The reasoning_content in the thinking mode must be passed back to the API.' Changes: - agent_loop.py: always set reasoning_content on assistant messages (use empty string when no reasoning was returned) — fixes the subagent/HermesAgentLoop creation path - run_agent.py (_build_assistant_message): extend defensive padding to cover ALL assistant messages for DeepSeek/Kimi, not just tool-call ones - run_agent.py (_copy_reasoning_content_for_api): same — pad all assistant messages during replay, not just tool-call ones - run_agent.py (_needs_deepseek_tool_reasoning): add detection for Ark Coding Plan endpoint (ark.cn-beijing.volces.com) which follows DeepSeek API conventions - test_deepseek_reasoning_content_echo.py: update test for new padding behavior, add Ark detection test Refs NousResearch#15250
Contributor
This was referenced Apr 26, 2026
Closed
Collaborator
|
Closing as redundant — the DeepSeek
21 regression tests in |
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
DeepSeek V4 thinking mode (and compatible APIs like Ark Coding Plan at
ark.cn-beijing.volces.com) requiresreasoning_contenton every assistant message in the conversation history. An inconsistent mix — some messages withreasoning_content, some without — triggers HTTP 400:This bug manifests on the Ark Coding Plan endpoint when models intermittently return
reasoning_content(e.g.,glm-5.1), producing 22 messages with it and 71 without in the same conversation.Changes
environments/agent_loop.py(subagent loop / HermesAgentLoop)reasoning_contenton assistant messages (use empty string when no reasoning was returned in that turn)reasoningwas non-None, creating inconsistent messagesrun_agent.py—_build_assistant_message()elif msg.get("tool_calls") and self._needs_deepseek_tool_reasoning()elif self._needs_deepseek_tool_reasoning() or self._needs_kimi_tool_reasoning()run_agent.py—_copy_reasoning_content_for_api()(replay path)run_agent.py—_needs_deepseek_tool_reasoning()(detection)ark.cn-beijing.volces.com) which follows DeepSeek API conventionsTests
test_deepseek_assistant_no_tool_call_now_paddedto expect padding on non-tool-call messagestest_ark_coding_plan_endpointfor Ark detectionTest Plan
All 22 tests in
test_deepseek_reasoning_content_echo.pypass. All 7 reasoning-related tests intest_hermes_state.pypass.Refs #15250