Anti-Patterns

Tool Loadout Hot-Swap

Anti-pattern: add or remove tool definitions during a running task so the tool set the model sees changes from turn to turn.

Problem

Mutating tool definitions in the middle of a running task invalidates the prefix key-value cache for everything in the conversation that came after the change, because the model conditions on the original system message and tool list. The agent then becomes uncertain which tools it can still call: recent turns may reference tools that have just been removed, or tools the model has not yet been told about, leading to hallucinated calls and broken composition between steps. The cost of the cache invalidation also shows up as a latency spike on the very next turn. Hot-swapping the loadout mid-run trades a small inventory benefit for serious correctness and performance damage.

Solution

Don't mutate tool definitions mid-task. Define the tool palette once at the start of a run and keep it stable. To constrain what the model is allowed to call in a given state, mask the corresponding tool-name token logits during decoding (or use response prefill) instead of removing the tool. See tool-loadout (pick the subset at run start, not mid-run), tool-search-lazy-loading (discover tools without redefining the registry), prompt-caching (KV-cache reuse depends on stable prefixes).

When to use

  • Never. The combination of cache invalidation and contradicted conditioning is not worth the apparent flexibility.
  • Pick the tool loadout at run start (tool-loadout) and keep it stable across the run.
  • Constrain availability by masking logits during decoding, not by mutating the registry.

Open the full interactive page

Diagram, neighbourhood map, code examples, related patterns and full provenance.

Related