Context
A single ranking at task start can miss tools the conversation drifts toward in the first few turns. The rolling window re-runs ranking for the first N turns (default 7) and unions the result into attachedMcpToolNames — so tools are only ever appended, never removed. After turn N, the set is frozen and only mcp_load can grow it.
The union-only rule preserves prompt caching: the API tools array prefix stays stable, so the cached prefix grows but never breaks.
Developer Notes
- Setting:
mcp.dynamicLoad.searchTurns (default 7). 0 disables dynamic loading entirely; 1 is sticky-from-start (no rolling).
- Hardcoded constant
MAX_ATTACHED_DURING_ROLLING = 60 (export from packages/types/src/mcp.ts). If |attachedMcpToolNames| ≥ this after a proposed append, stop appending in that turn and log a warning.
- In
build-tools.ts, before each API call within the first N turns:
- Compute
taskText = last user message (or last 2 messages, whichever is shorter).
- Call
ToolRouter.search(taskText, scopedTools, initialK).
attachedMcpToolNames ← attachedMcpToolNames ∪ result.
- Tool array is built deterministically (sorted by attach order, then by tool name) so cached prefix is stable.
- Files:
src/core/task/build-tools.ts, packages/types/src/mcp.ts (constants + setting).
- Validation: unit test simulates 10 turns with diverging topics —
attachedMcpToolNames grows during turns 1-7, stays constant during turns 8-10. Cache stability test asserts the API tools array order across turns.
Context
A single ranking at task start can miss tools the conversation drifts toward in the first few turns. The rolling window re-runs ranking for the first N turns (default 7) and unions the result into
attachedMcpToolNames— so tools are only ever appended, never removed. After turn N, the set is frozen and onlymcp_loadcan grow it.The union-only rule preserves prompt caching: the API
toolsarray prefix stays stable, so the cached prefix grows but never breaks.Developer Notes
mcp.dynamicLoad.searchTurns(default 7).0disables dynamic loading entirely;1is sticky-from-start (no rolling).MAX_ATTACHED_DURING_ROLLING = 60(export frompackages/types/src/mcp.ts). If|attachedMcpToolNames| ≥ thisafter a proposed append, stop appending in that turn and log a warning.build-tools.ts, before each API call within the first N turns:taskText= last user message (or last 2 messages, whichever is shorter).ToolRouter.search(taskText, scopedTools, initialK).attachedMcpToolNames ← attachedMcpToolNames ∪ result.src/core/task/build-tools.ts,packages/types/src/mcp.ts(constants + setting).attachedMcpToolNamesgrows during turns 1-7, stays constant during turns 8-10. Cache stability test asserts the APItoolsarray order across turns.