Skip to content

feat: on-demand tool loading for large MCP tool sets - #103

Merged
albanm merged 1 commit into
mainfrom
feat-tool-selection
Nov 18, 2026
Merged

albanm merged 1 commit into
mainfrom
feat-tool-selection

Conversation

@albanm

@albanm albanm commented Nov 18, 2026

Copy link
Copy Markdown
Member

When a turn's MCP tool definitions exceed toolDeferralPercent (default 10, env TOOL_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 with load_tools.

  • Per step, the AI SDK's activeTools holds back unloaded tools; toolOrder appends loaded ones so a load keeps the provider's cached prefix (measured on GreenPT: inserting a tool mid-list costs GLM its whole cache).
  • The loaded set is read from the history: it holds across turns, revived conversations and approval runs.
  • A call to a listed but unloaded tool fails without running, with a hint to load it; code_mode offers only loaded tools, and load_tools is direct-only.
  • No keyword search and no SDK toolSearch: the catalog already lists every name. Rationale, bench and measurements in docs/architecture/tool-loading.md (replaces tool-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 / repairToolCall changes in model-loop.ts closest.

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>
@albanm
albanm merged commit 5aa548a into main Nov 18, 2026
4 checks passed
@albanm
albanm deleted the feat-tool-selection branch November 18, 2026 19:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant