MikhbarMIKHBAR
Artificial Intelligence

Amazon Bedrock Prompt Caching for OpenAI Models

AI agents repeatedly re-read their entire context with every turn, but prompt caching patterns on Amazon Bedrock offer a way to maintain continuity without re-sending the same instructions, tools, and history.

Amazon Bedrock Prompt Caching for OpenAI Models

The Groundhog Day Dilemma for AI Agents

Every time an autonomous AI agent takes a step—whether it calls a tool, reads a result, or decides on its next action—it must send the large language model its entire story so far. Because models lack internal memory between requests, they must re-read tool definitions, developer instructions, and previous tool results on every single turn. By turn 20 of a coding session, the model re-reads turns one through nineteen, leaving developers to pay for those tokens repeatedly. Further details are available from AWS Machine Learning Blog in the original source material.

Prompt caching breaks this repetitive cycle by storing the input prompt and reusing it on subsequent requests at a fraction of the standard input price. As detailed in the official guidance, understanding model behavior helps optimize these interactions. Further details are available from Artificial Intelligence in the original source material.

Five growing agent requests, with tools, instructions, and earlier history marked in red and each new turn in yellow.
Image related to the report from AWS Machine Learning Blog · Source: AWS Machine Learning Blog

Understanding Implicit and Explicit Caching Modes

When a model reads a prompt, it performs a prefill process where it builds its key-value vectors to form the working state before generating tokens. Prompt caching preserves this state. With implicit caching, the service automatically selects where the reusable prefix ends based on conversation growth. Conversely, explicit caching allows code to mark specific endpoints using designated parameters to share content across sessions.

Developers can combine both methods to establish a reusable starting point while allowing the platform to automatically manage the growing conversation history. To ensure successful caching, the reusable prefix must reach a minimum threshold of 1,024 tokens.

Turn 1 writes the tools and instructions through a breakpoint. Turn 2 reads that same prefix from cache and processes its new question.
Image related to the report from AWS Machine Learning Blog · Source: AWS Machine Learning Blog

Implementing Static and Dynamic Prompt Caching

Caching static content like tool lists and system instructions requires explicit mode to designate where the saved prefix terminates. By assigning a cache key, applications indicate which requests share a cache pool. For example, a tools-and-instructions prefix of roughly 4,000 tokens can write once and subsequently read those same tokens on later requests without triggering an additional write.

To maintain cache hits, developers must ensure that instructions and tool lists serialize identically across requests. Dynamic variables such as timestamps, user names, or request identifiers should always be placed after the cached instructions to prevent cache misses.

Rolling breakpoints, where each turn reads all earlier turns and writes only its own tool result.
Image related to the report from AWS Machine Learning Blog · Source: AWS Machine Learning Blog

Managing Conversation History and Tool Loops

As agents execute tasks, applications route requested tool arguments to matching functions and collect their outputs. Appending the model output and tool results to a history list allows the system to send cumulative turns back to the model until a final answer is reached. In implicit mode, Amazon Bedrock leverages the unchanged prefix to lower latency and maintain high operational efficiency throughout complex multi-turn workflows.

Bar chart comparing the input cost of each caching setup on GPT-6 Astra, relative to no caching.
Image related to the report from AWS Machine Learning Blog · Source: AWS Machine Learning Blog

Sources

Continue chronologically

Related entity coverage