Tool schemas go at the top in the cached prefix because they are static and load-bearing; any per-user variation lives in a small separate per-call block to keep the cache hit rate high.
Think of a giant menu at a restaurant. The menu stays the same all day, so the restaurant prints it once and puts it on every table. They do not retype it for each customer. Now imagine one customer is allergic to peanuts. The restaurant does not reprint the whole menu without peanut dishes. They hand that one customer a small slip of paper that says, skip these two dishes. The menu is the tool schemas, printed once and reused for everyone. The slip is the per-user flag. If you put the slip into the big menu, you have to reprint the menu for every customer, which is slow and expensive. Keep the big static thing static, and put the small variable thing on its own slip.
Detailed answer & concept explanation~6 min readEverything you need to truly understand this topic: intuition, mechanics, step by step explanation, code, formulas, and worked example. Click to expand.
Everything you need to truly understand this topic: intuition, mechanics, step by step explanation, code, formulas, and worked example. Click to expand.
Everything you need to truly understand this topic: intuition, mechanics, step by step explanation, code, formulas, and worked example.
Everything important, quickly.
4 minutes: state the placement, name caching and anchoring as the two reasons, explain why per-user flags must live outside the cached block, and reference one 2026 provider's caching surface.
| Placement | Cache hit rate | Anchoring | When to use |
|---|---|---|---|
| System prompt top | High (90%+) | Strong (primacy) | Default for static schemas |
| Per-call user block | None | Weak | Only the per-user diff goes here |
| End of prompt | Low (varies per call) | Weak (recency stolen by question) | Never; antipattern |
| Mixed inline with task | None | Diluted | Never; antipattern |
Real products, models, and research that use this idea.
- Anthropic Claude Opus 4.7 prompt caching uses cache_control markers; production Claude Code agents place all tool definitions before the first cache boundary for ~10x cost reduction on the prefix.
- OpenAI GPT-5.5 automatic prefix caching kicks in on identical prompt prefixes over ~1024 tokens; agent stacks structure tool blocks at the top to hit the cache for free.
- Google Gemini 3.1 Pro context caching exposes explicit CachedContent objects; long-running agents cache the system block plus tool schemas once per session.
- Anthropic MCP (Model Context Protocol) servers expose tool schemas dynamically but Claude Code snapshots the schema set at session boundary to preserve caching across turns.
- Replit Agent and Cursor background agents in 2026 keep tool schemas in the system block and pass per-task arguments via the user turn, hitting cache rates above 90% in production.
What an interviewer would ask next. Try answering before peeking at the approach.
QHow do you handle a tool whose description must include per-user data, like the user's timezone or current account balance?
QWhy is the order of tools inside the schema block worth thinking about?
Don't say thisRed flags and common mistakes that signal junior thinking. Click to expand.
Red flags and common mistakes that signal junior thinking. Click to expand.
Dropping per-user feature flags into the middle of the tool definitions block. That one byte of variation invalidates the entire cached prefix and you pay full price every call.
The night-before-the-interview bullets. Scan these on the way to the call.
Primary sources. Skim if you want the original framing.
Same topic, related formats. Practice these next.