Repository navigation
fix(agent): give cloud models a 32K output-token cap - #4063
kovtcharov wants to merge 3 commits into
Conversation
Cloud reasoning models count their thinking against the agent's per-reply output cap, and the fixed 8,192-token cap (sized for a local 32K context) was cutting their replies off mid-thought. Lemonade cloud models now get 32,768; local models keep 8,192. - The cap is resolved per call from the current model, so a mid-session model switch takes effect. Cloud detection uses cloud_model_provider(), including Lemonade catalog metadata once discovered. - New optional max_output_tokens on Agent and ChatAgentConfig overrides the policy; an invalid value raises. Claude and OpenAI keep their 8,192 default and honor an explicit value.
Approve with suggestionsCloud reasoning models were being cut off mid-reply because the agent capped every response at 8,192 output tokens — a number sized for a local 32K context. This PR raises that to 32,768 for Lemonade cloud models, keeps 8,192 everywhere else, and adds a caller-settable override. The core change is correct and the tests read the real request body rather than trusting a mock, which is exactly the right bar. Two things worth tightening before merge, neither a regression from
Real-world evidenceN/A — no evidence bundle was produced for this run, and no pytest environment is available here, so this verdict rests on static review plus the unit tests as written. The PR description documents the before state well (three failed TheRock runs ending at exactly 8,192 tokens) but shows no after run against a real cloud model, and the author's own test-plan item — 🔍 Technical detailsIssues🟡 Two sources of truth for the cap, and they disagree (
🟡 Streaming call sites are untested (
Nits🟢 🟢 The new param is silently clamped on Claude ( 🟢 Strengths
|
|
Refreshed this branch against current The update was a clean merge: nothing was resolved by hand, and no commit on this branch was rewritten. CI now runs against an up-to-date base. |
…eads The truncated-tool-call error message now names the live output-token budget, so the code path reads self.max_output_tokens. The bare-agent stub in this file is built with __new__ on purpose and never ran __init__, so that attribute was missing and formatting the message raised AttributeError instead of the ValueError the test asserts. Set it on the stub like the other attributes it already primes.
Replicates amd#4063 (kovtcharov/gaia fork, push access blocked) onto a branch this session can push to. Cloud reasoning models such as `fireworks.deepseek-v4p1-flash` count their thinking against the agent's per-reply output cap. That cap was fixed at 8,192 tokens, which was sized for a local 32K context. On TheRock coding tasks, all three failed runs ended with a reply at exactly 8,192 tokens. Lemonade cloud models now get 32,768 output tokens, the same default Claude Code uses. Local models keep 8,192. Callers can set their own cap with a new optional `max_output_tokens` on the agent. - Replies that got cut off already continue since amd#4054, but each cut-off costs an extra round trip and drops thinking. This cuts off far fewer replies. - Claude keeps its current default. An explicit cap now reaches it, with one exception: Claude's existing 8,192 minimum still raises any smaller explicit value. One change beyond the original: `main` removed the openai/litellm providers (amd#3899), so `use_chatgpt` now raises a migration error at construction. The original PR's OpenAI request-cap test exercised that removed provider and has been dropped, along with a `use_chatgpt` term in the cap expression that can never be True. No other content changes beyond conflict resolution against current main. ## Test plan - [x] `pytest tests/unit/test_agent_max_output_tokens.py tests/unit/test_tool_call_priority.py` — 43 passed. These check the JSON body sent to Lemonade and expect `max_completion_tokens` 32768 for a cloud model and 8192 for a local model, plus an explicit override, a model switch mid-session, a custom provider flagged by catalog metadata, and the Claude request kwargs. - [x] `pytest tests/unit/agents` — 1422 passed, 50 skipped; identical on unmodified `main`. - [x] `python util/lint.py --black --isort` clean. - [ ] `gaia eval agent --category tool_selection` Carried over from the review on amd#4063, not addressed here: the cap is computed twice (once into `AgentConfig.max_tokens` at init, once per call in `_max_output_tokens()`), so memory-distillation and builder paths can disagree with the main loop for a catalog-flagged custom provider; and the streaming call sites have no test. --------- Co-authored-by: Kalin Ovtcharov <[email protected]> Co-authored-by: Ovtcharov <[email protected]> Co-authored-by: Kalin Ovtcharov <[email protected]>
|
Replicated as #4368 — fork push access (kovtcharov/gaia) was revoked mid-review, so this PR could no longer be refreshed against main. One change during the rebase: |
Cloud reasoning models such as
fireworks.deepseek-v4p1-flashcount their thinking against the agent's per-reply output cap. That cap was fixed at 8,192 tokens, which was sized for a local 32K context. On TheRock coding tasks, all three failed runs ended with a reply at exactly 8,192 tokens. Lemonade cloud models now get 32,768 output tokens, the same default Claude Code uses. Local models keep 8,192. Callers can set their own cap with a new optionalmax_output_tokenson the agent.Test plan
pytest tests/unit/test_agent_max_output_tokens.py: these tests check the JSON body sent to Lemonade and expectmax_completion_tokens32768 for a cloud model and 8192 for a local model. They also check an explicit override, a model switch mid-session, a custom provider flagged by catalog metadata, and the Claude and OpenAI request kwargs. 13 of the 14 fail on main.tests/test_lemonade_client.pyand the flagship tool-count tests also fail on unmodified main.gaia eval agent --category tool_selectioncompared against the committed baseline