Skip to content

Fix DeepSeek reasoning_content echo on fresh tool calls - #15527

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

Fix DeepSeek reasoning_content echo on fresh tool calls#15527
punkcanyang wants to merge 1 commit into
NousResearch:mainfrom
punkcanyang:fix/deepseek-reasoning-content-toolcall

Conversation

@punkcanyang

Copy link
Copy Markdown

Summary:

  • persist reasoning_content="" on fresh assistant tool-call turns for DeepSeek/Kimi-style thinking providers
  • keep poisoned-history replay fallback in _copy_reasoning_content_for_api
  • add a regression test covering _build_assistant_message for DeepSeek tool-call replies without explicit reasoning_content

Root cause:
_build_assistant_message() checked the DeepSeek fallback inside the hasattr(assistant_message, "reasoning_content") block. On fresh tool-call responses where the SDK object didn't expose that attribute at all, the fallback never ran, so the persisted assistant tool-call message was saved without reasoning_content. On the next replay, DeepSeek thinking mode rejected the request with HTTP 400:

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

What changed:

  • move the empty-string fallback to run after tool_calls are materialized into msg
  • apply the same creation-time protection to both _needs_deepseek_tool_reasoning() and _needs_kimi_tool_reasoning()
  • keep explicit reasoning_content untouched when providers return it

Verification:

  • python -m pytest tests/run_agent/test_deepseek_reasoning_content_echo.py -q
  • local minimal reproduction before fix: _build_assistant_message(..., tool_calls=...) produced no reasoning_content
  • local minimal reproduction after fix: fresh tool-call assistant message includes reasoning_content: ""

@alt-glitch alt-glitch added type/bug Something isn't working P1 High — major feature broken, no workaround comp/agent Core agent runtime: loop, agent_init, prompt builder, context-compression, responses endpoint provider/deepseek DeepSeek API labels Apr 25, 2026
@alt-glitch

Copy link
Copy Markdown
Collaborator

Related to #15407 (merged, same reasoning_content echo fix) and #15478 (open, broadens guard to ALL assistant messages). This PR covers the fresh tool-call creation path specifically — may overlap with what #15407 already merged. Please confirm what gap remains vs the merged fix.

@teknium1

Copy link
Copy Markdown
Contributor

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 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.

3 participants