th-1cc9fa: model-output ceiling clamp (Python core parity)#73
Merged
Conversation
Python parity for the Rust LlmClient output-ceiling clamp (th-562b6d/th-1cc9fa). - AgentOptions gains `model_max_output: int | None` (None = unknown = no clamp). - New `effective_max_tokens(max_tokens, ceiling)` helper: min(max_tokens, ceiling), passthrough on None/<=0, never returns 0. Exported from the package. - Both chat paths (`_call_model`, `_call_model_stream`) now send the clamped value. Stops a budget/policy max_tokens from exceeding what a model can physically emit (reasoning models otherwise burn the budget and return empty, or 400 upstream). The per-model ceiling is sourced from the gateway's /model/info by the consumer. Bumps python core 1.3.1 -> 1.3.2 so the clamp is releasable and the server can pin it (release-ordering: core publishes first, then the server bumps its pin). Tests: exhaustive clamp table (clamp-down / passthrough / equal / zero-ceiling / never-zero) + both agent request paths send the clamped value. 155 passed. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
🦋 Changeset detectedLatest commit: 80d7d9d 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.
Problem
A budget/policy
max_tokenscan exceed what a model can physically emit — a reasoning model then burns the whole budget on reasoning and returns EMPTY, or the upstream 400s (e.g.groq-compoundcaps output at 8192). The Rust engine already clampsmax_tokensto the model's output ceiling (th-562b6d, #69); this brings the Python core to parity.Change (mirrors
rust/smooth-operator-core/src/llm.rs+agent.rs)AgentOptionsgainsmodel_max_output: int | None(the Python analog ofAgentConfig.model_max_output/with_model_ceiling).None/ non-positive ⇒ unknown ⇒ no clamp (graceful passthrough).effective_max_tokens(max_tokens, ceiling)=min(max_tokens, ceiling), floored at 1, passthrough onNone/<=0— the PythonLlmClient::effective_max_tokens._call_model,_call_model_stream) now send the clamped value.Tests
tests/test_max_tokens_ceiling.py— the same clamp table the Rust reference asserts (clamp-down / passthrough / equal / zero-ceiling→unknown / never-returns-0) plus both agent paths actually sending the clampedmax_tokens. Full suite: 155 passed, 1 skipped; ruff clean.EPIC th-1cc9fa.
🤖 Generated with Claude Code