fix(agent): scale tool-output budget to the model context window (#23767) - #50136
Merged
Conversation
) The tool-result persistence budget was a fixed 100K chars/result and 200K chars/turn regardless of the active model. On a small-context model (e.g. a 65K-token local model switched into mid-session) a single large tool result (reporter: a 279K-char search result) or a full 200K-char turn (~50K tokens) could by itself approach or exceed the window, forcing an oversized request that the provider rejects as "Prompt too long". - budget_config.budget_for_context_window() scales per-result/per-turn char caps to a fraction of the model window, clamped to the historical 100K/200K defaults (large models unchanged) and floored so small models stay usable. - resolve_threshold() now caps the per-tool registry value at default_result_size so tools that register a fixed 100K cap (web/terminal/x_search) don't re-inflate a scaled-down budget. No-op for the default budget (both 100K). - tool_executor wires the agent's live context_length (recomputed on model switch) into all four persist/turn-budget call sites. read_file stays inf-pinned (no persist loop). Verified E2E: a 279K-char result against a 65K model collapses to a ~1.6K preview; a 200K model is byte-identical to today.
Contributor
🔎 Lint report:
|
waefrebeorn
pushed a commit
to waefrebeorn/slermes
that referenced
this pull request
Jul 2, 2026
…ware-tool-budget fix(agent): scale tool-output budget to the model context window (NousResearch#23767)
habarmc1223-sudo
pushed a commit
to habarmc1223-sudo/hermes-agent-fluxmem
that referenced
this pull request
Jul 8, 2026
…ware-tool-budget fix(agent): scale tool-output budget to the model context window (NousResearch#23767)
santhreal
pushed a commit
to santhreal/hermes-agent
that referenced
this pull request
Jul 13, 2026
…ware-tool-budget fix(agent): scale tool-output budget to the model context window (NousResearch#23767)
Gravezzz
pushed a commit
to Gravezzz/hermes-agent
that referenced
this pull request
Jul 21, 2026
…ware-tool-budget fix(agent): scale tool-output budget to the model context window (NousResearch#23767)
leewenjie
pushed a commit
to leewenjie/hermes-agent
that referenced
this pull request
Aug 7, 2026
…ware-tool-budget fix(agent): scale tool-output budget to the model context window (NousResearch#23767)
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.
Summary
Tool-result size budgets now scale to the active model's context window. Previously they were fixed constants (100K chars per result, 200K per turn) regardless of the model — so on a small-context model a single large tool result, or one tool-heavy turn, could by itself approach or exceed the window and force a request the provider rejects as "Prompt too long" (part of #23767).
Root cause
tools/budget_config.pycapped tool output at fixed char counts blind to the model. The reporter switched a large session onto a 65,536-token local model; a 279,549-char search result (and the 200K-char per-turn budget ≈ 50K tokens — ~77% of that window) overflowed it.Changes
tools/budget_config.py: newbudget_for_context_window(context_length)scales per-result (15%) and per-turn (30%) char caps to the window, clamped to the historical 100K/200K defaults (large models unchanged) and floored (small models stay usable).resolve_threshold()now caps the per-tool registry value atdefault_result_sizeso tools registering a fixed 100K (web/terminal/x_search) don't re-inflate a scaled-down budget — a no-op for the default budget.agent/tool_executor.py:_budget_for_agent()wires the agent's livecontext_length(recomputed on model switch) into all four persist / turn-budget call sites.Validation
tests/tools/test_budget_config.py(+13 new)tests/tools/test_tool_result_storage.py+ budget (CI-parity runner)tests/run_agent/test_tool_executor_contextvar_propagation.pyread_filestays inf-pinned (no persist loop)Part of #23767 (does not close it on its own — sibling fixes tracked separately).
Infographic
Image generation is unavailable in this environment (FAL_KEY unset, no managed-provider credits), so the infographic could not be generated here. To be attached once image generation is available.