Repository navigation
fix(ai): fit thinking budgets to the output limit - #51157
Merged
Merged
Conversation
4 of 6 tasks
rekram1-node
force-pushed
the
fit-thinking-budgets
branch
from
September 24, 2026 17:41
d82c8c3 to
c568e92
Compare
This was referenced Sep 24, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Issue for this PR
N/A. Found while testing default output limits for #51021.
Type of change
What does this PR do?
Protocols that send an explicit thinking budget now cap it at half the output limit. Thinking counts against the output limit, so a budget near or above it leaves the answer, a tool call or a summary with no room.
ProviderShared.fitThinkingBudgetis the single rule:-1(dynamic) and0(off) pass through;It applies in the four protocols that read a typed budget:
thinking.budget_tokensmax_tokens. Keeps Anthropic's 1,024 minimum.thinking_budgetmax_completion_tokens; the answer gets what remains.thinking.budget_tokensthinking, so it never went through the Anthropic path.thinkingConfig.thinkingBudgetMAX_TOKENS). Uses a 512 minimum, because Gemini 2.5 rejects budgets under a per-model minimum (512 on Flash-Lite, 128 on Pro).Main steps are mostly unaffected, because variant budgets are usually at most half the model's output limit. The cap applies to compaction summaries (32k), near-full contexts, and budgets derived from the whole output limit.
Not covered:
reasoningthrough untyped.How did you verify your code works?
Unit tests: fit tests for Anthropic (including the minimum), Alibaba Chat and Messages, and Gemini (including
-1and the 512 minimum). The fullpackages/aisuite passes.Gemini minimums, live on AI Studio:
All three accept 512 under a 1,000 limit, which is what the fit now sends there.
Live with the default output limits from feat(core): fit output limits to the context window #51021 applied: a title, tool-using steps and a manual compaction.
qwen3.7-plusmaxgemini-2.5-promaxclaude-haiku-4-5maxAll requests returned 200, and every compaction completed.
Screenshots / recordings
N/A
Checklist