Mask, don't remove
unmaskedmaskedremoved
- A state machine restricts the action space per phase.
- Removing tool definitions invalidates the KV-cache.
- Logit masking keeps the prefix byte-identical.
- 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
- Context engineering: lessons from building ManusManus
- Prompt cachingAnthropic
- Prompt cachingOpenAI