Managing Caching in Agents
Prompt caching is one of the biggest levers on the cost and latency of an agent, because an agent resends a growing prefix (system prompt, tool definitions, history) on every turn. Anything that changes an earlier part of that prefix invalidates the cache for everything after it.
What invalidates the cache
- Editing the system prompt (it sits at the top, so everything after it is invalidated)
- Adding, removing or reordering tools, for example when skills load or unload tools dynamically
- Editing or removing earlier messages in the history, such as compaction or trimming
In our agent, skills and tools changing mid-run is one of the biggest sources of cache misses.
Mid-conversation system messages
Newer Claude models allowlet you append a system{"role": "system", ...} message to bethe appendedmessages mid-conversationarray ratherpartway thanthrough a conversation. This adds or updates instructions without rewriting the top-level system prompt.prompt, Theso earlierthe cached prefix stays byte-identical, so it stays cached and only the new tail is processed.not Thisinvalidated. It is promising for cost reduction in agents that change instructions or tools during a run.
How
it works on Amazon Bedrockrole (must be system), content (string or content blocks), optional cache_control
Put cache_control on the last block that stays unchanged, then append the system message after that breakpoint. The new message can itself be cached on later turns.
Placement: not the first message, and it must follow a user message (or an assistant message ending in a server tool result). tool_addition / tool_removal blocks (adding and removing tools Pydantic AI supports the same idea in its message history: a system prompt part in the first request is the standing system prompt, while one in a later request is a mid-conversation instruction that keeps its position. See Pydantic AI: message history.
Caveats:
- Position alone does not enable caching. You still need the provider's prompt-caching settings (or an explicit cache point).
- Never build a mid-conversation system message from untrusted content such as tool output or fetched pages. Only inject instructions you wrote yourself.
- Frontends that don't send mid-conversation system prompts back can change the prefix every turn and defeat the cache.
To do
Related Content
- Claude 5.5 Series