Repository navigation
feat: on-demand tool loading for large MCP tool sets - #103
Merged
Merged
Conversation
Above toolDeferralPercent (default 10, env TOOL_DEFERRAL_PERCENT) of the assistant model's context window, a turn's MCP tools are not sent as definitions: the system prompt lists them in a catalog (full names, one line each) and the model loads the ones it needs by exact name with load_tools. The SDK's per-step activeTools hides the others; toolOrder appends loaded tools so a load keeps the provider's cached prefix. The loaded set is read back from the history, so it holds across turns, revivals and approval runs. A call to a listed tool not yet loaded fails with a hint to load it. Validated on data-fair's autonomous-agent simulations (bridge, deferral forced vs off): 5/5 satisfied both ways, 31 -> 11-15 tools per step, assistant input tokens halved. See docs/architecture/tool-loading.md. 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.
When a turn's MCP tool definitions exceed
toolDeferralPercent(default 10, envTOOL_DEFERRAL_PERCENT; 100 disables) of the assistant model's context window, they are no longer sent: the system prompt lists them in a catalog (full names, one line each) and the model loads what it needs by exact name withload_tools.activeToolsholds back unloaded tools;toolOrderappends loaded ones so a load keeps the provider's cached prefix (measured on GreenPT: inserting a tool mid-list costs GLM its whole cache).code_modeoffers only loaded tools, andload_toolsis direct-only.toolSearch: the catalog already lists every name. Rationale, bench and measurements indocs/architecture/tool-loading.md(replacestool-exploration.md).Why: a full-scope autonomous agent is offered about a hundred MCP tools, far above what providers advise (fewer than 20–50), and production runs smaller open models whose tool selection degrades sooner.
Validation: data-fair's 5 autonomous-agent simulations on the Claude Code bridge, deferral forced against off on the same image: 5/5 satisfied both ways, 31 → 11–15 tools per step, assistant input tokens halved, no call to an unloaded tool. Not yet run on the GreenPT production models.
Heads-up: on by default. Full-scope agents in production will defer from the first deploy. Review the
prepareStep/repairToolCallchanges inmodel-loop.tsclosest.