Repository navigation
Load MCP tools on demand; cap derived summary trigger at 100k - #304
Merged
Merged
Conversation
Every model call re-sent every bound tool definition. All four bots carry Linear's 76 MCP tools (~30k tokens) plus Serena and filesystem (~11k more), on every call, while Linear was called 19 times in ~3,200 tool calls over a week. - MCP tools stay bound but are left out of model requests until the bot loads them with the new load_tools tool (exact names or keyword query, max 15 per call); the system prompt lists them by name. The loaded set lives in agent state for the rest of the run; loaded tools go last in the tool list so a load keeps the cached prefix. Calling an unloaded tool is refused but loads it. - defer_mcp_tools setting (default on) turns it off. - MAX_DERIVED_SUMMARY_TRIGGER 200k -> 100k: on glm-5.3-flash's 1M window nothing was cleared until ~133k of messages and calls passed 170k tokens. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.
Why
A week of runs measured: each engineer call sent ~67k prompt tokens on average, starting at ~52k before any work. About 45k of that is tool definitions, and Linear's 76 MCP tools alone are ~30k. Every bot carries them on every call, yet Linear was called 19 times out of ~3,200 tool calls. The filesystem MCP tools were never called.
Separately, since #299 the derived thresholds for
glm-5.3-flash(1.05M window) are summary 200k / clear ~133k, so calls passed 170k tokens before anything was trimmed.What
runtime/tool_loading.py)mcp:*) stay bound to the agent, butDeferredToolsMiddlewareleaves them out of each model request until the bot loads them.load_toolstool: exactnames(the server prefix can be dropped when unique) or a keywordquery; at most 15 per call.defer_mcp_tools(default true) turns it off; it's in Settings → Context and the README.MAX_DERIVED_SUMMARY_TRIGGER200k → 100k: 1M-window models now summarize at 100k and clear at ~67k, still above the ~47k that caused re-reading before Cap the output reserve and derived summary trigger in context thresholds #299.Expected effect: per-call tool definitions go from ~45k tokens to ~4k plus a ~1k name list, until a run loads something.
Tests
tests/test_tool_loading.py: search and name resolution, the prompt section, tools hidden until loaded and kept after, load by query, refuse-and-load, unknown names, the off switch.Not yet run against a real model; worth watching the first run that touches Linear.
🤖 Generated with Claude Code