Mask, don't remove

unmaskedmaskedremoved
RemovetoolssearchreadKV-cacheinvalidatedMaskphase: Researchtoolssearchreadedittestdeploy−∞−∞−∞KV-cachehit
  1. A state machine restricts the action space per phase.
  2. Removing tool definitions invalidates the KV-cache.
  3. Logit masking keeps the prefix byte-identical.
  4. Phase transition: new mask, same cached prefix.
Notes & references

Use when

Phase-gated agents with long cached prefixes.

Avoid

Masking as the only authorization boundary: enforce server-side.

ALL_TOOLS = [search, read, edit, test, deploy]   # never changes

ALLOWED = {
    "research": ["search", "read"],
    "build":    ["read", "edit", "test"],
    "ship":     ["test", "deploy"],
}

llm.create(messages, tools=ALL_TOOLS,
           allowed_tools=ALLOWED[phase])         # only this changes