Skip to content

fix: ensure reasoning_content consistency for DeepSeek-compatible APIs - #15982

Closed
highland0971 wants to merge 1 commit into
NousResearch:mainfrom
highland0971:fix/deepseek-reasoning-content-consistency
Closed

highland0971 wants to merge 1 commit into
NousResearch:mainfrom
highland0971:fix/deepseek-reasoning-content-consistency

Conversation

@highland0971

Copy link
Copy Markdown

Summary

DeepSeek V4 thinking mode (and compatible APIs like Ark Coding Plan at ark.cn-beijing.volces.com) requires reasoning_content on every assistant message in the conversation history. An inconsistent mix — some messages with reasoning_content, some without — triggers HTTP 400:

The reasoning_content in the thinking mode must be passed back to the API.

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)

  • Always set reasoning_content on assistant messages (use empty string when no reasoning was returned in that turn)
  • Previously only set it when reasoning was non-None, creating inconsistent messages

run_agent.py_build_assistant_message()

  • Extend defensive padding to cover all assistant messages for DeepSeek/Kimi, not just tool-call ones
  • Previously: elif msg.get("tool_calls") and self._needs_deepseek_tool_reasoning()
  • Now: elif self._needs_deepseek_tool_reasoning() or self._needs_kimi_tool_reasoning()

run_agent.py_copy_reasoning_content_for_api() (replay path)

  • Same change: pad all assistant messages during replay, not just tool-call ones

run_agent.py_needs_deepseek_tool_reasoning() (detection)

  • Add detection for Ark Coding Plan endpoint (ark.cn-beijing.volces.com) which follows DeepSeek API conventions

Tests

  • Update test_deepseek_assistant_no_tool_call_now_padded to expect padding on non-tool-call messages
  • Add test_ark_coding_plan_endpoint for Ark detection

Test Plan

All 22 tests in test_deepseek_reasoning_content_echo.py pass. All 7 reasoning-related tests in test_hermes_state.py pass.

Refs #15250

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
@alt-glitch alt-glitch added type/bug Something isn't working P2 Medium — degraded but workaround exists comp/agent Core agent runtime: loop, agent_init, prompt builder, context-compression, responses endpoint provider/deepseek DeepSeek API labels Apr 26, 2026
@alt-glitch

Copy link
Copy Markdown
Contributor

Related to #15446 (comprehensive DeepSeek V4 support) and refs #15250. This PR extends reasoning_content padding to non-tool-call assistant messages and adds Ark Coding Plan endpoint detection.

@teknium1

Copy link
Copy Markdown
Collaborator

Closing as redundant — the DeepSeek reasoning_content thinking-mode 400 and cross-provider leak chain of issues is now fully covered on main:

21 regression tests in tests/run_agent/test_deepseek_reasoning_content_echo.py + 2 new tests for the cross-provider scenario exercise every known path. Thanks for the submission — appreciate the digging on this area.

@teknium1 teknium1 closed this Apr 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp/agent Core agent runtime: loop, agent_init, prompt builder, context-compression, responses endpoint P2 Medium — degraded but workaround exists provider/deepseek DeepSeek API type/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants