Skip to content

fix(agent): comprehensive DeepSeek V4 support — context windows, thinking mode, reasoning replay#15446

Closed
Tranquil-Flow wants to merge 2 commits into
NousResearch:mainfrom
Tranquil-Flow:fix/deepseek-v4-comprehensive-support
Closed

fix(agent): comprehensive DeepSeek V4 support — context windows, thinking mode, reasoning replay#15446
Tranquil-Flow wants to merge 2 commits into
NousResearch:mainfrom
Tranquil-Flow:fix/deepseek-v4-comprehensive-support

Conversation

@Tranquil-Flow

Copy link
Copy Markdown
Contributor

Summary

Unifies 5 fragmented DeepSeek V4 PRs into a single cohesive implementation:

  • Context windows: Add 1M entries for deepseek-v4-pro, deepseek-v4-flash, deepseek-chat, deepseek-reasoner (128K fallback preserved for older models)
  • Thinking mode toggle: Plumb thinking.type and reasoning_effort for native DeepSeek API — maps effort values to DeepSeek's supported "high"/"max" pair, strips incompatible sampling params (temperature, top_p, etc.) when thinking is enabled
  • reasoning_content replay: Inject reasoning_content="" on all assistant messages for DeepSeek replay, scoped to api.deepseek.com and OpenRouter deepseek/ prefix. Respects enabled: false to skip injection
  • _extract_reasoning guards: Use isinstance(str) checks instead of truthy checks, preventing crashes on non-string reasoning values
  • reasoning_content normalization: Preserve empty string "" in normalize_response (semantically valid for DeepSeek, was being dropped by truthy check)
  • _handle_max_iterations: Add missing _copy_reasoning_content_for_api call so the max-iterations summary path doesn't produce 400s
  • deepseek-chat preserved: deepseek-chat (the non-thinking alias) is NOT forced into thinking mode by default — only deepseek-v4-* and deepseek-reasoner models, or when the user explicitly opts in via reasoning_config

Test plan

  • 34 tests across 5 test classes (context windows, thinking mode, replay, isinstance guards, normalization)
  • Verified deepseek-chat does NOT force thinking mode by default
  • Verified deepseek-chat CAN opt-in to thinking with explicit config
  • Verified temperature stripping only happens when thinking is enabled
  • Verified non-DeepSeek models are not affected by any of these changes
  • Verified explicit reasoning_content is preserved (not overwritten with "")

Fixes #15353. Supersedes #14952, #14958, #15325, #15228, #15354.

…king mode, reasoning replay

Unifies approaches from PRs NousResearch#14952, NousResearch#14958, NousResearch#15325, NousResearch#15228, NousResearch#15354
into a single cohesive implementation:

- Add 1M context window entries for V4 models (deepseek-v4-pro,
  deepseek-v4-flash, deepseek-chat, deepseek-reasoner)
- Plumb thinking.type toggle and reasoning_effort mapping for
  native DeepSeek API (only "high" and "max" are valid)
- Strip incompatible sampling params when thinking is enabled
- Inject reasoning_content="" on all assistant messages for
  DeepSeek replay (scoped to api.deepseek.com and OpenRouter)
- Fix _extract_reasoning isinstance checks for empty strings
- Preserve empty-string reasoning_content in normalize_response
- Add _copy_reasoning_content_for_api call in _handle_max_iterations

Fixes NousResearch#15353. Supersedes NousResearch#14952, NousResearch#14958, NousResearch#15325, NousResearch#15228, NousResearch#15354.
@ukint-vs

Copy link
Copy Markdown

Superseded by #15478 (merged 2026-04-26) which landed a more comprehensive fix covering both DeepSeek and Kimi, with the regression follow-up in #16097. Closing — upstream main now has the 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.

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.

DeepSeek V4 thinking mode: missing reasoning_content on tool-call messages causes 400

4 participants