Skip to content

th-562b6d: clamp max_tokens to model output ceiling (LlmClient)#69

Merged
brentrager merged 3 commits into
mainfrom
th-562b6d-max-tokens-clamp
Jul 8, 2026
Merged

th-562b6d: clamp max_tokens to model output ceiling (LlmClient)#69
brentrager merged 3 commits into
mainfrom
th-562b6d-max-tokens-clamp

Conversation

@brentrager

Copy link
Copy Markdown
Contributor

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

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

changeset-bot Bot commented Jul 8, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 1cdc3db

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@smooai/smooth-operator-core Patch

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

brentrager and others added 2 commits July 8, 2026 10:54
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>
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.

1 participant