Skip to content

W1.5 — Rolling-search window across first N turns (union-only growth) #22

Description

@edelauna

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions