Skip to content

th-1cc9fa: model-output ceiling clamp (Python core parity)#73

Merged
brentrager merged 1 commit into
mainfrom
th-1cc9fa-py-ceiling
Jul 8, 2026
Merged

th-1cc9fa: model-output ceiling clamp (Python core parity)#73
brentrager merged 1 commit into
mainfrom
th-1cc9fa-py-ceiling

Conversation

@brentrager

Copy link
Copy Markdown
Contributor

Problem

A budget/policy max_tokens can 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-compound caps output at 8192). The Rust engine already clamps max_tokens to 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)

  • AgentOptions gains model_max_output: int | None (the Python analog of AgentConfig.model_max_output / with_model_ceiling). None / non-positive ⇒ unknown ⇒ no clamp (graceful passthrough).
  • New exported effective_max_tokens(max_tokens, ceiling) = min(max_tokens, ceiling), floored at 1, passthrough on None/<=0 — the Python LlmClient::effective_max_tokens.
  • Both chat request sites (_call_model, _call_model_stream) now send the clamped value.
  • 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).

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 clamped max_tokens. Full suite: 155 passed, 1 skipped; ruff clean.

EPIC th-1cc9fa.

🤖 Generated with Claude Code

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

changeset-bot Bot commented Jul 8, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 80d7d9d

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
brentrager merged commit ab24904 into main Jul 8, 2026
4 checks passed
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