th-1cc9fa: model-output ceiling clamp + raise starvation defaults (TypeScript parity)#71
Merged
Merged
Conversation
Mirror the Rust engine's model-output ceiling clamp in the TypeScript core. AgentOptions gains `modelMaxOutput?: number`; a new exported `effectiveMaxTokens(configured, ceiling?)` computes min(maxTokens, ceiling) (floored at 1; undefined/0 => passthrough). Both the non-streaming `run` and streaming `runStream` request builds now send the clamped value, so a budget/policy max_tokens can never exceed what the model can physically emit (reasoning models otherwise burn the budget on reasoning_content and return empty; groq-compound 400s at an 8192 output cap). No behaviour change when modelMaxOutput is unset. EPIC th-1cc9fa. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
🦋 Changeset detectedLatest commit: e7ddcb2 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 |
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.
Why
A budget/policy
max_tokenscan exceed what a model can physically emit. When it does, reasoning models burn the whole budget onreasoning_contentand return emptycontent, or the upstream 400s (e.g.groq-compoundcaps output at 8192). The fix clamps every request'smax_tokenstomin(configured, model.max_output_tokens), where the per-model ceiling comes from the LiteLLM gateway's/model/infoendpoint (model_info.max_output_tokens).What (TypeScript core)
Mirrors the already-merged Rust reference (
rust/smooth-operator-core/src/llm.rsLlmClient::with_model_ceiling/effective_max_tokens;src/agent.rsAgentConfig.model_max_output, PR #69) in TS idioms:AgentOptionsgainsmodelMaxOutput?: number— the active model's hard output ceiling (agent-config threading, the TS analog ofAgentConfig.model_max_output).effectiveMaxTokens(configured, ceiling?)=min(configured, ceiling), floored at 1;undefined/0/non-positive ⇒ graceful passthrough (zero behaviour change). This is the TS analog ofLlmClient::effective_max_tokens.runloop and the streamingrunStreamloop — now sendeffectiveMaxTokens(...)formax_tokens.The ceiling itself is sourced by the consumer (the server) from
/model/infoand passed in viamodelMaxOutput, kept out of the published engine so it takes no LiteLLM-specific HTTP — same split as Rust.Mirroring Rust
None/unset ⇒ no clamp (passthrough), identical to the Rust reference. The clamp lives at the request build (the TS engine builds the OpenAI request directly rather than through a separateLlmClientwrapper class, so the natural home for the clamp is the agent's request build +AgentOptions, rather than awithModelCeilingbuilder on a client object).Tests
effectiveMaxTokens: clamp-down (ceiling < budget), passthrough (ceiling ≥ budget, undefined, 0, negative), never returns 0.SmoothAgent: asserts the recorded request body'smax_tokensis clamped on both the non-streaming and streaming paths, and unclamped when no ceiling is set.pnpm typecheck,pnpm build,pnpm testall green (141 tests).🤖 Generated with Claude Code