AI agents often face a recurring problem: every step must re-read their entire history. This leads to repeated input costs and high latency. A new pattern for OpenAI models on Amazon Bedrock solves this with prompt caching.
Groundhog Day for AI Agents
Every time an AI agent takes a step, it sends its full context to the model. This includes instructions, tools, and past interactions. The model has no internal memory. It must reprocess everything from scratch on each turn.
By turn 20, the model has re-read 19 previous turns. Each re-read counts as input tokens. These tokens cost money. Without caching, input costs grow with every step. This is not just a theoretical concern—it directly impacts operational budgets, especially in long-running workflows such as customer support, code generation, or data analysis.
The analogy of Bill Murray’s character in the movie Groundhog Day is apt. Every day, he wakes up in the same inn, hears the same radio song, and faces the same small-town scenario. He only progresses when he stops repeating mistakes and begins to build on what he learned from previous days. Similarly, AI agents must evolve from one step to the next. Without a mechanism to retain and reuse prior context, they are trapped in a loop of redundant processing—each turn re-reading the same history, leading to exponential input token usage and inflated costs.
For instance, in a typical coding agent workflow, the first turn might involve a simple task like identifying a bug in a codebase. The second turn might call a tool to retrieve logs, the third might analyze the logs, and so on. Without prompt caching, each of these turns must re-send the entire history of the session—instructions, tool definitions, and all prior outputs. This means that on the 20th turn, the model has effectively reprocessed 19 prior turns, each of which was processed as input tokens. The cumulative cost of this repetition can quickly become unsustainable, especially in production environments where thousands of agent interactions occur daily.
How Prompt Caching Works
When a large language model (LLM) receives a prompt, it performs a prefill operation. During this phase, the model processes every input token and builds a set of key-value vectors—also known as key-value (KV) vectors—that represent its internal working state. These vectors are critical for the model’s ability to generate a coherent and contextually relevant response.
These vectors are not stored in the model’s memory permanently. Instead, they are generated on the fly during the prefill phase and then used to generate the model’s output. Prompt caching introduces a mechanism to save these key-value vectors after the prefill phase. When a subsequent request includes the same or a similar input prompt, the system can retrieve the saved state instead of recomputing it from scratch.
As a result, the model only processes the new content in the request—such as a new user message or a tool result—while reusing the previously computed vectors for the shared context. This drastically reduces the number of input tokens that must be processed, leading to significant cost savings and improved response times.
Two Caching Modes
- Implicit caching: Amazon Bedrock automatically detects where to stop the cached prefix. It works best when the conversation grows naturally and the shared context remains stable over time. This mode is ideal for workflows where the agent’s initial instructions and tool definitions are consistent, and the conversation evolves organically.
- Explicit caching: Code explicitly marks a point in the prompt where content should be saved. This allows reuse across sessions or agent spawns. For example, a developer can define a specific section of the prompt—such as instructions and tool definitions—and instruct the system to save that section as a reusable prefix. This is particularly useful when multiple agents or sessions need to start from the same foundational context.
Both modes can be used in tandem. The service can manage the growing history of a conversation while preserving the stability of shared content. This hybrid approach provides the best of both worlds: automatic adaptation to evolving conversations and explicit control over what content is preserved for reuse.
Static Content Caching
Tools and instructions are typically stable over time. They do not change from one session to the next. For example, a support agent might have a fixed set of policies, response templates, and tool definitions that remain consistent across all interactions. These elements should be cached first to ensure that future requests do not have to reprocess them.
A reusable prefix must contain at least 1,024 tokens to qualify for caching. This threshold ensures that the content is sufficiently large and structured to allow meaningful reuse. If the prefix is too short, the system may not recognize it as a valid cacheable unit.
Use explicit mode to mark the end of the static content. For example, a developer prompt and tool list can be saved with a breakpoint. The following code demonstrates how to set up such a configuration:

KEY = "support-agent:v7:gpt-6-astra"
INSTRUCTIONS = "Your full support policies and examples..."
resp = client.responses.create(
model="us.openai.gpt-6-astra",
store=False,
include=["reasoning.encrypted_content"],
prompt_cache_key=KEY,
prompt_cache_options={"mode": "explicit", "ttl": "30m"},
tools=TOOLS,
input=[
{
"role": "developer",
"content": [
{
"type": "input_text",
"text": INSTRUCTIONS,
"prompt_cache_breakpoint": {"mode": "explicit"}
}
]
},
{
"role": "user",
"content": task
}
]
)
The tools and instructions are saved. The user message is not. This ensures that on future turns, the model only processes the new content, significantly reducing input token costs. The cached prefix remains valid as long as the content it includes does not change.
It is critical to ensure that the agent’s instructions and tool lists are serialized in the same way every time. Any variation—such as a timestamp, user name, or request ID—must be placed after the cached content. If such variations are included in the cached prefix, the system will fail to recognize the prompt as identical, and caching will not occur.
Conversations with Growing History
As a conversation progresses, new messages and tool results are added. Implicit caching allows the system to reuse the unchanged prefix. This is particularly effective in workflows where the agent’s initial setup remains consistent, and the conversation evolves over time.
For example, a session starts with instructions and a task. Each turn adds new content. The model only reprocesses what’s new. The cached prefix remains intact, and the model does not need to re-read the entire history.
Here is a function that uses implicit caching to manage a growing conversation:
def ask_with_implicit_cache(history):
return client.responses.create(
model="us.openai.gpt-6-astra",
store=False,
include=["reasoning.encrypted_content"],
prompt_cache_key=KEY,
prompt_cache_options={"mode": "implicit", "ttl": "30m"},
tools=TOOLS,
input=history
)
history = [
{"role": "developer", "content": INSTRUCTIONS},
{"role": "user", "content": task}
]
resp = ask_with_implicit_cache(history)
After each turn, the history grows. The model reads only what’s new. The cached prefix remains intact. This pattern is especially useful in long-running workflows, such as customer support tickets or multi-step debugging sessions, where the agent must maintain continuity across multiple interactions.
Combining Both Caching Modes
Some workflows require both stable content and growing history. For instance, a support agent might start with a fixed set of instructions and tools, but later need to adapt to new tasks or user requests. In such cases, it is beneficial to start with an explicit marker for tools and instructions, then allow the conversation to grow using implicit mode.
By doing so, the agent ensures that the foundational content—such as policies and tool definitions—is preserved and reusable, while the conversation itself evolves naturally. This combination provides a strong foundation for agent continuity without sacrificing flexibility.
history = [
{
"role": "developer",
"content": [
{
"type": "input_text",
"text": INSTRUCTIONS,
"prompt_cache_breakpoint": {"mode": "explicit"}
}
]
},
{"role": "user", "content": task}
]
resp = ask_with_implicit_cache(history)
This setup ensures shared content is saved early. The conversation grows without losing the base context. It is particularly effective when launching new agents or when a workflow involves multiple sub-tasks that build on a shared foundation.
Tool Changes and New Tools
Agents may add new tools during a session. The initial tool list must remain stable. Any change—such as adding, removing, or reordering tool definitions—invalidates the cached prefix. This is because the model’s understanding of the available tools is tied to the prompt structure, and any deviation breaks the consistency required for caching.
When a new tool is introduced, it must be added in a way that preserves the cached prefix. Amazon Bedrock supports this through the additional_tools input item type, which allows new tools to be appended to the session without disrupting the existing cache.

For example, a support agent might need to add a new tool to retrieve a case due date. The following code shows how to register and append this tool:
TOOL_HANDLERS["get_due_date"] = get_due_date
NEW_TOOL = {
"type": "function", "name": "get_due_date",
"description": "Return the due date for a support case.",
"strict": True,
"parameters": {
"type": "object",
"properties": {"case_id": {"type": "string"}},
"required": ["case_id"], "additionalProperties": False
}
}
history.append({
"type": "additional_tools", "role": "developer",
"tools": [NEW_TOOL]
})
history.append({
"role": "user", "content": "Find the due date for case C-123.",
})
resp = ask_with_implicit_cache(history)
Implicit caching now includes the new tool. The model can use it in future turns. The shared prefix remains valid. This approach allows agents to evolve over time without requiring a complete restart or re-caching of the entire session.
It is important to note that the additional_tools item itself cannot contain a prompt_cache_breakpoint. This is because the tool definition is not part of the user-facing content and does not need to be saved as a separate cache point. Instead, the tool is added to the history and the model processes it as part of the current session.
Subagents and Side Calls
When launching helper agents, they should not re-read the full history. A warm-up request should first establish the shared prefix. This ensures that all helper agents start from the same foundational context, avoiding redundant processing.
Mark the shared content explicitly in every request, even when using implicit mode. This includes both the initial instructions and the tool definitions. The following code demonstrates a warm-up request that establishes the shared prefix:
shared = {"role": "developer", "content": [
{
"type": "input_text", "text": INSTRUCTIONS,
"prompt_cache_breakpoint": {"mode": "explicit"}
}
]}
warm = client.responses.create(
model="us.openai.gpt-6-astra", store=False,
tools=TOOLS, prompt_cache_key=KEY,
prompt_cache_options={"mode": "implicit", "ttl": "30m"},
max_output_tokens=16,
input=[shared, {"role": "user", "content": "Reply READY."}]
)
if not (warm.usage.input_tokens_details.cache_write_tokens or warm.usage.input_tokens_details.cached_tokens):
raise RuntimeError("Shared prefix was not cached.")
After the warm-up request completes successfully, the system confirms that the shared prefix has been cached. Only then should helper agents be launched in parallel. This ensures that each helper agent starts with the same foundational context and avoids reprocessing the entire history.
Each helper agent adds its own task at the end of the prompt. For example, a summarizer agent might be tasked with condensing a long conversation into a single sentence. The helper uses the same tools, model, and cache key as the parent agent, ensuring consistency and continuity.
from copy import deepcopy
# history is the completed history built by the agent loop above.
# Copy it so the helper can add instructions without changing the parent.
helper_history = deepcopy(history)
helper_history.append({
"role": "developer",
"content": "Summarize this conversation in one sentence. Do not call tools.",
})
summary = ask_with_implicit_cache(helper_history)
d = summary.usage.input_tokens_details
print("history read", d.cached_tokens, "write", d.cache_write_tokens)
print(summary.output_text)
# Example output (assumed values and conversation):
# history read 4096 write 32
# Case C-123 is due on October 31, 2026.
The helper can reuse the cached portion of history, but the appended developer message does not automatically extend the cache to include the summary instruction. If later requests reuse the same history and instruction, the instruction must be placed in an input_text block with a prompt_cache_breakpoint. For a one-time summary, no additional marker is needed.
Cache Key and Session Management
Each cache entry is tied to a unique prompt_cache_key. This key must match across sessions to allow reuse. A session-specific key isolates content between users or sessions, while a shared key enables multiple sessions to reuse the same prefix.
Use a stable key based on app name, version, model, and instructions. For example, a support agent might use a key like support-agent:v7:gpt-6-astra:sha256-hash-of-instructions. This ensures that sessions with the same instructions and version can reuse the same cache, even if the tasks differ.
def cache_key(app, model, prompt_version, instructions):
digest = hashlib.sha256(instructions.encode()).hexdigest()[:12]
return f"{app}:{prompt_version}:{model}:{digest}"
KEY = cache_key("support-agent", "us.openai.gpt-6-astra", "v7", INSTRUCTIONS)
Two sessions with the same key can reuse the same prefix, even with different tasks. For example, one session might ask for a refund policy, and another might ask about escalation procedures. Both can draw from the same cached instructions and tools, significantly reducing input costs.
However, if a session uses a different key, it will not be able to reuse the cached content. This is critical for multi-user or multi-agent environments where isolation is required. Developers must carefully design their key generation logic to balance between reuse and isolation.

Cost and Performance Benefits
For a GPT-6 Astra agent with an 8,000-token startup prefix and six turns adding 2,000 tokens each:
- Static caching reduced input cost to $0.50 per session.
These savings come from reduced input token usage. The model only processes new content. In real-world scenarios, this can translate to significant cost reductions—especially in high-volume agent workflows where thousands of interactions occur daily.
These savings are not just theoretical—they are measurable and have been validated in actual deployments using Amazon Bedrock.
How to Verify Caching Is Working
Monitor response usage fields:
- cached_tokens: Input read from cache. This value shows how many tokens were retrieved from the saved state instead of being reprocessed.
- cache_write_tokens: Input written to cache. This value reflects the number of tokens stored during the initial prompt or a new tool addition.
Use Amazon CloudWatch to track these metrics. Enable model invocation logging when you need individual request records, then query them with Amazon CloudWatch Logs Insights. For the Amazon Bedrock Mantle endpoint, record the response usage fields in your application logs. Its Amazon CloudWatch namespace currently has no separate cache counters.
To check costs, filter AWS Cost Explorer to Amazon Bedrock and group by Usage type. Cache reads, cache writes, and uncached input appear as separate entries per model. Exclude output-token entries when calculating their shares of input cost.
Best Practices for Implementation
- Keep the shared prefix stable. Put shared tools and instructions first, then append conversation history and new turns. Changing a timestamp, message, or tool definition prevents reuse beyond that change. A shorter prefix can still be reused if it has its own saved endpoint.
- Choose boundaries around content you want to reuse. Use implicit caching for growing history, explicit markers for shared prefixes, or both. Explicit-only mode avoids writing disposable suffixes. When extending an explicit-only conversation, retain earlier markers so later requests can find the saved prefixes.
- Keep the initial tool catalog unchanged. Use allowed_tools to restrict which tools are callable. Append known definitions with additional_tools, or discover them through namespaced client-side tool_search. Choose a stable tool profile when different agent roles need different catalogs.
- Check prefix size and lifetime. A cacheable prefix must contain at least 1,024 tokens. Cached prefixes remain eligible for reuse for at least 30 minutes after their latest write or successful reuse.
- Warm shared content before launching helpers. Mark the shared prefix in both the warm-up and helper requests, including when using implicit mode. Finish the warm-up request before starting parallel calls.
- Keep cache keys stable within each sharing group. Requests intended to reuse a prefix must use the same key. Separate keys can keep cache accounting distinct between customers or users.
- Measure savings across the workflow. Cache writes cost 1.25 times the normal input rate. Read prices depend on the model. Track write costs alongside read savings, using response usage during development and monitoring and billing data in production.
Why This Matters
AI agents that re-read history every turn face high input costs and slow performance. This enables longer, more complex workflows without a spike in cost. It makes agent-based systems more scalable and practical for real-world use.
Without prompt caching, agents would be limited in their ability to perform complex, multi-step tasks due to the exponential growth of input costs. With prompt caching, agents can operate efficiently over extended periods, making them viable for real-world applications such as customer service, code generation, and data analysis.
Limitations and Open Questions
- Only static breakpoints work in explicit-only mode. Growing history is reprocessed each time.
- Changing tasks may break implicit reuse. Add explicit markers if different tasks need shared prefixes.
- Tool changes invalidate the cached prefix. The initial tool list must remain unchanged.
- Cache keys must match across sessions. A session-specific key isolates content.
- Cache write costs are 1.25 times the normal input rate. This must be factored into cost models.
- Amazon Bedrock Mantle lacks dedicated cache metrics in CloudWatch. Developers must track usage in logs.
What to Watch Next
As AI agents grow in complexity, prompt caching will become essential. Future versions may support:
- Dynamic prefix updates with minimal reprocessing.
- Longer cache lifetimes and automatic expiration policies.
- Integration with agent orchestration frameworks.
- Improved monitoring and cost visibility for developers.
For full details, see the original post on Amazon Bedrock: Groundhog Day for AI Agents.
Bill Murray’s character escapes Groundhog Day only when he stops repeating mistakes. AI agents achieve continuity by preserving their starting context and using prompt caching to avoid reprocessing history.
Sources & further reading
- Original source
- d2908q01vomqb2.cloudfront.net
- d2908q01vomqb2.cloudfront.net
- d2908q01vomqb2.cloudfront.net
Featured image: original publisher image. Via original publisher. Image source

