th-562b6d: clamp max_tokens to model output ceiling (LlmClient)#69
Merged
Conversation
with_model_ceiling(Option<u32>) + effective_max_tokens() = min(config.max_tokens, ceiling). 4 request-build sites use it. None => passthrough (no behaviour change). Ceiling sourced from gateway /model/info by the consumer (engine stays git-dep-free + streaming-only reqwest). Test covers clamp/passthrough/zero/equal. EPIC th-1cc9fa. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
🦋 Changeset detectedLatest commit: 1cdc3db The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
AgentConfig.model_max_output + with_model_ceiling(); both LlmClient::new sites apply it. Lets a host set the per-turn model's output ceiling on the agent (the engine builds the client internally). None => unchanged. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
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.
Problem
A flat/high `max_tokens` can exceed a model's real output ceiling. Reasoning models then burn the budget on `reasoning_content` and return empty; some upstreams 400. Concretely: `groq-compound` caps output at 8192 while the daemon budget is 32768.
Change
`LlmClient` gains `with_model_ceiling(Option)` + `effective_max_tokens()`. All 4 request-build sites send `min(config.max_tokens, ceiling)`; `None` = graceful passthrough (zero behaviour change when unset). Ceiling is sourced from the gateway `/model/info` by the consumer, keeping this published crate free of a git-dep (smooai-fetch) and LiteLLM-specific HTTP.
Part of EPIC th-1cc9fa (gateway model_info ceilings + @smooai/config dynamic limits, clamped in engine). Paired gateway change: model_info `max_output_tokens` for ~35 custom models.
Test
`effective_max_tokens_clamps_to_model_ceiling` covers clamp-down / budget-governs / zero / none / equal.
Note
Triggers the polyglot release chain — not auto-merging; hold for review/release coordination.
🤖 Generated with Claude Code