fix(agent): don't clamp an unknown context window to the small-server budget (#6678) (#6706)

budget_context_for_model() returns 0 when the endpoint does not prove its
context window, and compute_input_token_budget() answers 0 with the
conservative default budget (6000). The agent loop's small-local-server
clamp (`candidate_context <= 8192`) also matched 0 and cut the request to
max(1200, 0) tokens, so on any endpoint with an unreported window an open
document or a few thousand tokens of earlier context were trimmed away
before the model saw them ("5519 tokens > 1200 budget (ctx=1800)").

Apply the clamp only to a known window.

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Grzegorz
2026-10-31 13:30:29 +00:00
committed by GitHub
co-authored by Claude Opus 5.5
parent 87193d23f5
commit a1a7f8fc9a
2 changed files with 75 additions and 1 deletions
+4 -1
View File
@@ -24193,11 +24193,14 @@ async def stream_agent_loop(
budget_is_explicit,
hard_max=hard_max,
)
if candidate_context <= 8192:
if 0 < candidate_context <= 8192:
# Small local servers often tokenize chat wrappers and tool
# results much more generously than our rough estimator. Keep
# substantial headroom for those wrappers and generation so a
# follow-up tool round cannot exceed the server's n_ctx.
# 0 means the window is unknown, which already gets the
# conservative default budget; clamping it as well cut every
# request to 1200 tokens and dropped open documents (#6678).
effective_budget = min(
effective_budget,
max(1200, int(candidate_context * 0.40)),