Skip to content

fix: DeepSeek/Kimi thinking mode requires reasoning_content on ALL assistant messages#15478

Merged
OutThisLife merged 1 commit into
NousResearch:mainfrom
yes999zc:fix-deepseek-reasoning-all-assistant-messages
Apr 26, 2026
Merged

fix: DeepSeek/Kimi thinking mode requires reasoning_content on ALL assistant messages#15478
OutThisLife merged 1 commit into
NousResearch:mainfrom
yes999zc:fix-deepseek-reasoning-all-assistant-messages

Conversation

@yes999zc

Copy link
Copy Markdown
Contributor

Problem

DeepSeek V4 thinking mode requires reasoning_content on every assistant message, not just tool-call turns. The existing fix (#15250) only covered the tool-call path.

When an assistant message is a plain text reply (no tool_calls) and reasoning is empty, _copy_reasoning_content_for_api skips padding entirely, causing DeepSeek to reject the next request with:

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

Fix

Remove the source_msg.get("tool_calls") and guard in _copy_reasoning_content_for_api so all DeepSeek/Kimi assistant messages get reasoning_content="" when needed.

Changes

  • run_agent.py: broaden condition from tool_calls + provider to just provider
  • test_deepseek_reasoning_content_echo.py: update test to expect padding on plain assistant turns

Verification

pytest tests/run_agent/test_deepseek_reasoning_content_echo.py -v — 21/21 passed.

Fixes #15213

@alt-glitch alt-glitch added type/bug Something isn't working P1 High — major feature broken, no workaround comp/agent Core agent loop, run_agent.py, prompt builder provider/deepseek DeepSeek API labels Apr 25, 2026
@alt-glitch

Copy link
Copy Markdown
Collaborator

Related to #15476 — both fix DeepSeek V4 reasoning_content consistency but from different angles. #15478 broadens the per-message guard; #15476 adds history-level backfill. These likely conflict in run_agent.py and should be coordinated.

…sistant messages

Previously _copy_reasoning_content_for_api only padded reasoning_content
when the assistant message had tool_calls. DeepSeek V4 thinking mode
requires the field on every assistant turn, including plain text replies
without tool_calls.

- Remove the 'source_msg.get("tool_calls") and' guard
- Update test: plain assistant turns now get padded for DeepSeek/Kimi

Fixes #15213
@yes999zc yes999zc force-pushed the fix-deepseek-reasoning-all-assistant-messages branch from e48aab0 to ad0ac89 Compare April 25, 2026 23:54
@OutThisLife OutThisLife merged commit 489bed6 into NousResearch:main Apr 26, 2026
teknium1 pushed a commit that referenced this pull request Apr 26, 2026
… tool-call replay

PR #15478 fixed missing reasoning_content for DeepSeek API but introduced
a regression: tool-call messages with genuine 'reasoning' field were
overwritten by empty-string fallback before promotion.

Re-order _copy_reasoning_content_for_api steps:
  1. Preserve explicit reasoning_content
  2. Promote 'reasoning' field (MOVED UP)
  3. DeepSeek/Kimi tool-call empty-string fallback (MOVED DOWN)
  4. Non-thinking provider cleanup

Fixes #15812, relates #15749, #15478.
ulasbilgen pushed a commit to ulasbilgen/hermes-adhd-agent that referenced this pull request May 1, 2026
…oning-all-assistant-messages

fix: DeepSeek/Kimi thinking mode requires reasoning_content on ALL assistant messages
ulasbilgen pushed a commit to ulasbilgen/hermes-adhd-agent that referenced this pull request May 1, 2026
… tool-call replay

PR NousResearch#15478 fixed missing reasoning_content for DeepSeek API but introduced
a regression: tool-call messages with genuine 'reasoning' field were
overwritten by empty-string fallback before promotion.

Re-order _copy_reasoning_content_for_api steps:
  1. Preserve explicit reasoning_content
  2. Promote 'reasoning' field (MOVED UP)
  3. DeepSeek/Kimi tool-call empty-string fallback (MOVED DOWN)
  4. Non-thinking provider cleanup

Fixes NousResearch#15812, relates NousResearch#15749, NousResearch#15478.
donald131 pushed a commit to donald131/hermes-agent that referenced this pull request May 2, 2026
… tool-call replay

PR NousResearch#15478 fixed missing reasoning_content for DeepSeek API but introduced
a regression: tool-call messages with genuine 'reasoning' field were
overwritten by empty-string fallback before promotion.

Re-order _copy_reasoning_content_for_api steps:
  1. Preserve explicit reasoning_content
  2. Promote 'reasoning' field (MOVED UP)
  3. DeepSeek/Kimi tool-call empty-string fallback (MOVED DOWN)
  4. Non-thinking provider cleanup

Fixes NousResearch#15812, relates NousResearch#15749, NousResearch#15478.
@yes999zc yes999zc deleted the fix-deepseek-reasoning-all-assistant-messages branch May 3, 2026 18:49
02356abc pushed a commit to 02356abc/hermes-agent that referenced this pull request May 14, 2026
…oning-all-assistant-messages

fix: DeepSeek/Kimi thinking mode requires reasoning_content on ALL assistant messages
02356abc pushed a commit to 02356abc/hermes-agent that referenced this pull request May 14, 2026
… tool-call replay

PR NousResearch#15478 fixed missing reasoning_content for DeepSeek API but introduced
a regression: tool-call messages with genuine 'reasoning' field were
overwritten by empty-string fallback before promotion.

Re-order _copy_reasoning_content_for_api steps:
  1. Preserve explicit reasoning_content
  2. Promote 'reasoning' field (MOVED UP)
  3. DeepSeek/Kimi tool-call empty-string fallback (MOVED DOWN)
  4. Non-thinking provider cleanup

Fixes NousResearch#15812, relates NousResearch#15749, NousResearch#15478.
dannyJ848 pushed a commit to dannyJ848/hermes-agent that referenced this pull request May 17, 2026
…oning-all-assistant-messages

fix: DeepSeek/Kimi thinking mode requires reasoning_content on ALL assistant messages
dannyJ848 pushed a commit to dannyJ848/hermes-agent that referenced this pull request May 17, 2026
… tool-call replay

PR NousResearch#15478 fixed missing reasoning_content for DeepSeek API but introduced
a regression: tool-call messages with genuine 'reasoning' field were
overwritten by empty-string fallback before promotion.

Re-order _copy_reasoning_content_for_api steps:
  1. Preserve explicit reasoning_content
  2. Promote 'reasoning' field (MOVED UP)
  3. DeepSeek/Kimi tool-call empty-string fallback (MOVED DOWN)
  4. Non-thinking provider cleanup

Fixes NousResearch#15812, relates NousResearch#15749, NousResearch#15478.
gweeteve pushed a commit to gweeteve/hermes-agent that referenced this pull request Jun 2, 2026
…oning-all-assistant-messages

fix: DeepSeek/Kimi thinking mode requires reasoning_content on ALL assistant messages
gweeteve pushed a commit to gweeteve/hermes-agent that referenced this pull request Jun 2, 2026
… tool-call replay

PR NousResearch#15478 fixed missing reasoning_content for DeepSeek API but introduced
a regression: tool-call messages with genuine 'reasoning' field were
overwritten by empty-string fallback before promotion.

Re-order _copy_reasoning_content_for_api steps:
  1. Preserve explicit reasoning_content
  2. Promote 'reasoning' field (MOVED UP)
  3. DeepSeek/Kimi tool-call empty-string fallback (MOVED DOWN)
  4. Non-thinking provider cleanup

Fixes NousResearch#15812, relates NousResearch#15749, NousResearch#15478.
Egavasyug pushed a commit to Egavasyug/hermes-agent that referenced this pull request Jun 10, 2026
…oning-all-assistant-messages

fix: DeepSeek/Kimi thinking mode requires reasoning_content on ALL assistant messages
Egavasyug pushed a commit to Egavasyug/hermes-agent that referenced this pull request Jun 10, 2026
… tool-call replay

PR NousResearch#15478 fixed missing reasoning_content for DeepSeek API but introduced
a regression: tool-call messages with genuine 'reasoning' field were
overwritten by empty-string fallback before promotion.

Re-order _copy_reasoning_content_for_api steps:
  1. Preserve explicit reasoning_content
  2. Promote 'reasoning' field (MOVED UP)
  3. DeepSeek/Kimi tool-call empty-string fallback (MOVED DOWN)
  4. Non-thinking provider cleanup

Fixes NousResearch#15812, relates NousResearch#15749, NousResearch#15478.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp/agent Core agent loop, run_agent.py, prompt builder P1 High — major feature broken, no workaround provider/deepseek DeepSeek API type/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: HTTP 400 "reasoning_content must be passed back" with deepseek-v4-pro in cron/auxiliary path (thinking mode works in main loop, breaks elsewhere)

3 participants