Skip to content

fix(deepseek): forward graded reasoning_effort instead of discarding it - #40717

Closed
NasonZ wants to merge 1 commit into
BerriAI:mainfrom
NasonZ:fix-deepseek-reasoning-effort-passthrough
Closed

NasonZ wants to merge 1 commit into
BerriAI:mainfrom
NasonZ:fix-deepseek-reasoning-effort-passthrough

Conversation

@NasonZ

@NasonZ NasonZ commented Sep 11, 2026 •

Copy link
Copy Markdown

TLDR

Problem this solves:

  • reasoning_effort is dropped for DeepSeek, so low behaves like high
  • callers cannot ask a DeepSeek model to think less, at all

How it solves it:

  • forward the effort value instead of collapsing it to thinking: enabled
  • let DeepSeek grade it server-side rather than remapping in the client

User Flow

Before: a developer running an agent loop on deepseek-flash tries to stop the model over-thinking, and nothing they set makes any difference

  1. Their agent hits a task with an ambiguous next step, and the model deliberates until it exhausts max_tokens
  2. The turn comes back with finish_reason: "length", empty content and no tool_calls, so the loop has nothing to act on
  3. They set reasoning_effort="low" and send the same request
  4. The request body on the wire still says only "thinking": {"type": "enabled"}, with no effort, so the model reasons exactly as much as before
  5. They raise max_tokens instead, and the model simply deliberates further into the larger budget

After: the same developer sets reasoning_effort="low" and the model reasons roughly half as much and reaches an answer

  1. Their agent hits the same ambiguous task
  2. They set reasoning_effort="low" and send the request
  3. The request body on the wire now carries "reasoning_effort": "low" alongside "thinking": {"type": "enabled"}
  4. The response comes back with finish_reason: "stop" and a usable tool call, having used about half the reasoning tokens

Evidence

Measured against deepseek-flash, four samples per setting on a bounded reasoning task:

reasoning_effort reasoning tokens median
low 2828, 1315, 2603, 2972 2,716
high 4926, 11938, 3652, 3893 4,410

On an unbounded task with a 45,000 token budget, low finished at 19,554 reasoning tokens while high ran into the cap without finishing

Caveats

  • an explicit thinking toggle is still honoured exactly as given, and no effort is merged into it. I could not establish whether DeepSeek applies an effort alongside an explicit toggle: four samples per condition put the combined case between low and high, overlapping both, so the patch does not guess
  • the mapping is deliberately not reimplemented here. DeepSeek publishes its own table (minimal/low → low, medium/high/xhigh → high, max/ultra → max) and applies it server-side, so duplicating it in the client would diverge whenever they change it. (deepseek family) Fix reasoning_effort parameter mapping: correctly disable thinking for "none", and map deepseek's high/max reasoning_effort #27829 took the client-side approach and collapsed low into high, which loses the only level that shortens reasoning

Testing

Extends tests/test_litellm/llms/deepseek/chat/test_deepseek_chat_transformation.py:

  • every documented effort value, plus default, reaches the request body
  • an explicit thinking toggle carries no effort
  • disabled thinking carries no effort
  • the three existing effort tests now assert the forwarded value, not just the toggle

16 thinking and effort tests pass. Two vision tests in the same file fail identically before and after this change

@CLAassistant

CLAassistant commented Sep 11, 2026 •

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@codspeed

codspeed Bot commented Sep 11, 2026 •

Copy link
Copy Markdown
Contributor

Merging this PR will not alter performance

✅ 31 untouched benchmarks


Comparing NasonZ:fix-deepseek-reasoning-effort-passthrough (6cd2585) with main (bd23e6f)1

Open in CodSpeed

Footnotes

  1. No successful run was found on main (878ba39) during the generation of this report, so bd23e6f was used instead as the comparison base. There might be some changes unrelated to this pull request in this report. ↩

@greptile-apps

greptile-apps Bot commented Sep 11, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR forwards graded DeepSeek reasoning effort values and includes several additional resilience, MCP health, cache, spend-counter, and generated-schema updates

  • Preserves graded DeepSeek reasoning effort on provider requests
  • Adds bounded OpenAPI specification fetching and cached MCP health probes
  • Hardens Redis circuit-breaker behavior and open-breaker fallbacks
  • Expands MCP dynamic registration to four redirect URIs
  • Updates focused regression tests for the changed paths

Confidence Score: 4/5

The behavior appears safe, but the explicit repository type and source-comment requirements must be satisfied before merging

No blocking runtime failure was established; the remaining findings concern two confirmed repository-rule violations and missing coverage for a public effort value

Files Needing Attention: litellm/llms/deepseek/chat/transformation.py, tests/test_litellm/llms/deepseek/chat/test_deepseek_chat_transformation.py

Important Files Changed

Filename Overview
litellm/llms/deepseek/chat/transformation.py Forwards graded reasoning effort, but violates optional-type and source-comment rules and lacks coverage for the public default value
tests/test_litellm/llms/deepseek/chat/test_deepseek_chat_transformation.py Covers documented graded levels and explicit thinking precedence, while omitting the public default effort
litellm/llms/custom_httpx/http_handler.py Adds bounded streaming GET support with redirect, compression, size, and cleanup handling
litellm/proxy/_experimental/mcp_server/mcp_server_manager.py Adds bounded, coalesced OpenAPI specification health checks without forwarding server credentials
litellm/caching/redis_cache.py Prevents stale successes from closing a newer breaker generation and guards synchronous reads
litellm/caching/dual_cache.py Preserves in-memory batch results when Redis rejects reads through an open circuit breaker
litellm/proxy/proxy_server.py Invalidates local spend counters and quietly handles known open-breaker increment failures
litellm/proxy/_experimental/mcp_server/gateway_dcr_flow.py Allows four validated redirect URIs while preserving encoded client-size checks

Reviews (1): Last reviewed commit: "fix(deepseek): forward graded reasoning_..." | Re-trigger Greptile

Comment on lines +75 to +76
optional_params: dict, reasoning_effort: Optional[str]
) -> None:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Use PEP 604 syntax

This parameter uses Optional[str], but repository guidance requires str | None. This requirement must be satisfied before merging

Rule Used: In this repo, prefer str | None (PEP 604 union syntax) over Optional\[str\] for optional parameters. Do not flag str | None as a style inconsistency. (source)

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

Comment on lines +77 to +91
"""Pass a graded effort through to DeepSeek instead of discarding it.

DeepSeek's thinking mode accepts `reasoning_effort` directly and applies
its own documented mapping server-side (minimal/low -> low,
medium/high/xhigh -> high, max/ultra -> max). Collapsing the value to a
bare `thinking: {"type": "enabled"}` here made every graded level
identical to the default, so callers could not request `low` at all --
the one level that shortens deliberation.

The mapping is deliberately not reimplemented here: it is DeepSeek's
table, published in their docs, and duplicating it means this client
silently diverges whenever they change or extend it.

Reference: https://api-docs.deepseek.com/guides/thinking_mode
"""

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Unnecessary comments added

The new comment and docstring restate straightforward control flow, violating the repository rule against unnecessary source comments. Please resolve before merging

Context Used: CLAUDE.md (source)

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!


Reference: https://api-docs.deepseek.com/guides/thinking_mode
"""
if reasoning_effort not in (None, "none"):

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Default effort lacks coverage

The public API accepts reasoning_effort="default", but forwarding tests omit it, leaving its DeepSeek request behavior unverified

Knowledge Base Used: Provider adapters and capabilities

@NasonZ
NasonZ force-pushed the fix-deepseek-reasoning-effort-passthrough branch from 6f7a407 to 5687e9d Compare September 11, 2026 11:57
@NasonZ
NasonZ changed the base branch from main to litellm_internal_staging September 11, 2026 11:57
@NasonZ
NasonZ requested a review from a team September 11, 2026 11:57
@codecov

codecov Bot commented Sep 11, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@NasonZ
NasonZ force-pushed the fix-deepseek-reasoning-effort-passthrough branch 2 times, most recently from fa9900d to ee779d4 Compare September 11, 2026 23:03
amartinr added a commit to amartinr/litellm-extensions that referenced this pull request Sep 12, 2026
Move the client-side activation notes out of DESIGN §9 into
reasoning_route_adapter/DEPLOYMENT.md (pi models.json compat delta +
amartinr/pi-deepseek-reasoning-chain-fix), linked from the READMEs.

Record the measured finding that the reasoning-effort *level* is
ineffective through this gateway (LiteLLM v1.99.0): inert on native
(DeepSeekChatConfig discards the value, BerriAI/litellm#27439) and erratic
on OR (provider-side; object-vs-root isolation test). Only the ON/OFF kill
switch is reliable. Track upstream fix PR BerriAI/litellm#40717 (open) and
the recorded adapter activation path (drop the redundant thinking toggle on
native-ON). See DESIGN §1.4 and PLAN.md.

Co-Authored-By: Pi <noreply@pi.dev>
@yuneng-berri
yuneng-berri deleted the branch BerriAI:main September 13, 2026 04:52
@yuneng-berri yuneng-berri reopened this Sep 13, 2026
@devin-ai-integration
devin-ai-integration Bot changed the base branch from litellm_internal_staging to main September 23, 2026 14:36
map_openai_params collapsed every non-"none" reasoning_effort into a bare
thinking: {"type": "enabled"} and dropped the level, so low, high and max
were all indistinguishable from the default and callers could not ask for
reduced reasoning at all

DeepSeek accepts reasoning_effort directly in thinking mode and grades it
server-side, so the value is forwarded rather than remapped here

Fixes #27439
@NasonZ
NasonZ force-pushed the fix-deepseek-reasoning-effort-passthrough branch from ee779d4 to 6cd2585 Compare October 6, 2026 16:41
@NasonZ

NasonZ commented Oct 6, 2026

Copy link
Copy Markdown
Author

Rebased on current main; the merge conflict is resolved. The fix is unchanged: graded reasoning_effort values (low/medium/high/max) are now forwarded to DeepSeek instead of being collapsed to thinking: enabled. Still needed on current main. Ref #27439. Happy to adjust if you'd prefer a different approach.

@mateo-berri

Copy link
Copy Markdown
Contributor

Closing this since #38736 already fixes the same problem on main. Thanks for contributing, and please reopen if anything is missing

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants