The 'Groundhog Day' Problem of AI Agents
In the movie <Groundhog Day>, Bill Murray repeats the same February 2nd for 34 years. Since the achievements of the previous day do not carry over, he must start anew every day. Currently, AI agents find themselves in a similar situation. Every time an agent progresses to the next step (tool call, reading results, making the next decision), the model must be resent the entire story up to that point. Tool definitions, guidelines, and all previous tool calls and results are input tokens for every request. Since the model cannot remember its internal state between requests, by the 20th turn, it has to read turns 1 through 19 again, and developers pay that token cost each time.
How Prompt Caching Works: Prefill and KV Cache
The first operation the model performs when reading a prompt is prefill. During the prefill stage, all input tokens are processed to generate key-value (KV) pairs, which become the model's working state. This process must be completed before the first output token is produced. The prompt caching service saves this KV state and, if subsequent requests start with the same input tokens, it loads the saved state to skip the prefill operation. It then processes only the newly added parts.
Combination Strategy of Explicit and Implicit Caching
Bedrock offers two caching modes that can be used simultaneously.
| Category | Explicit Caching (Explicit) | Implicit Caching (Implicit) |
|---|---|---|
| Cache Boundary Specification | Developer directly marks with `prompt_cache_breakpoint` | Bedrock automatically determines based on conversation growth |
| Main Use | Tools and guidelines shared between sessions and sub-agents | Increasing conversation history within the same session |
| Reuse Scope | Can be shared across multiple sessions with `prompt_cache_key` | Limited to the current conversation session |
Explicit caching is suitable for static content (tool lists, developer guidelines). A reusable prefix must be 1,024 tokens or more to be eligible for caching. Implicit caching automatically sets the cache boundary after the most recent eligible message as the conversation lengthens. By combining the two methods, a 'common starting point' can be fixed with explicit caching, while the 'growing history' is managed automatically by implicit caching.
Static Content Caching: Reusing Tools and Guidelines
The following code pattern is an example of fixing tools and guidelines with explicit caching.
```python
# Place variable elements (date, username, request ID) after the explicit cache boundary
messages = [
{