DEV Community

Cover image for Prompt Caches Turn Agent Reliability Into a Systems Design Problem
Jaromir Tesar
Jaromir Tesar

Posted on Originally published at spaisee.com Fully Autonomous

Prompt Caches Turn Agent Reliability Into a Systems Design Problem

The competitive advantage in AI agents will not come only from smarter models or cheaper inference. It will come from proving that a long-running agent can resume work with the right instructions, permissions, evidence and rationale intact. Prompt caching is moving into that reliability stack. What looks like a cost optimization can quietly become an undocumented dependency for an agent’s memory, latency profile and operational correctness.

The warning arrived in an unusually concrete form. Anthropic’s April 23 postmortem described a Claude Code bug in which a cache-maintenance change removed older reasoning from every later turn after a session had been idle for more than an hour. The intended behavior was a one-time cleanup of thinking history after a cache eviction. Instead, the system kept applying the cleanup, leaving the agent increasingly unable to remember why it had made earlier edits or tool calls. Anthropic said the result was forgetfulness, repetition, odd tool choices, cache misses and faster usage-limit depletion.

That incident changes the executive question. Prompt caching is usually discussed as a unit-economics lever: reuse a large prefix, pay less, respond faster. But a production agent can begin behaving as if the cached prompt is part of its durable state. If a changed prefix or overly aggressive compaction alters the assembled context, or if application logic wrongly changes context in response to cache expiry or a routing miss, the agent may make a different decision while its application still considers the session continuous.

For companies selling agents into coding, operations, finance or regulated workflows, that is not merely an infrastructure bug. It is a trust and retention risk. Customers forgive a slow task more readily than an agent that resumes a task with misplaced confidence and a missing rationale.

The cache is not the session

The foundational design rule is simple: a prompt cache is not a database, a memory system or an audit log. It is an opportunistic reuse mechanism for computational state associated with a prompt prefix.

Modern agent architecture makes that distinction more important. Anthropic’s managed-agent architecture separates an agent into a durable, append-only session log; a harness that selects context, calls the model and routes tools; and a sandbox that executes actions. The company’s central point is that the session is not the model’s context window. The session remains recoverable outside the window, while the harness decides what material to reconstruct for each inference.

Figure 1 - How a durable agent session is reconstructed into model context while prompt caching remains an optimization — see the chart in the original article.

This separation creates a more defensible operating model. The session log records what actually happened: user requests, tool calls, tool results, approvals, policy versions, files changed and checkpoints. The harness is a deterministic or at least inspectable reconstruction layer. The prompt cache accelerates the stable portion of the resulting request. It should not determine whether the agent can explain, reproduce or safely continue its work.

A naive transcript replay system reverses those priorities. It treats the entire past conversation as both history and context. That works for short chats. It degrades badly when agents run for hours, call tools repeatedly and accumulate huge outputs. The full transcript becomes too large, too noisy and too expensive. Engineers then trim it, summarize it or depend on a cached prefix to make replay tolerable. At that point, a transient optimization begins to carry application semantics.

The better architecture is durable event sourcing plus selective context assembly. Preserve the full record. Retrieve the relevant parts. Summarize explicitly and version the summary. Then construct a cache-friendly request from stable, validated components.

Why prefix matching changes agent behavior

Prompt caching works through prefix reuse, not a vague similarity judgment. OpenAI’s prompt-caching documentation says that the system seeks the longest available matching cached prefix, working backward through eligible cache breakpoints. For GPT-5.6 and later, the minimum cacheable prompt length is 1,024 tokens. The docs also distinguish writes from reads: a default 30-minute cache write costs 1.25 times ordinary uncached input, while a cache read generally costs 0.1 times the ordinary input rate, with some models priced at 0.05 times.

Figure 2 - how two requests reuse the longest matching cached prefix while their later blocks differ — see the chart in the original article.

The economic logic is powerful. A well-designed agent can put durable system instructions, static tool schemas, stable workspace configuration and other broadly shared material early in the request. It can append variable user requests, newly retrieved evidence and recent events later. The stable prefix gets reused, while only the changing suffix needs fresh processing.

The chart clarifies why product teams chase hit rates. With ten identical full-prefix requests, OpenAI’s example puts one default-lifetime write and nine reads at 2.15 times the ordinary input cost, compared with 10 times the cost without caching. That spread can improve gross margins and make an agent feel dramatically faster.

But prefix sensitivity means seemingly innocent changes can shatter reuse. Reordering tool definitions, inserting a timestamp into a developer message, changing a policy string, adding an experiment tag, rotating a workspace setting or moving instructions from one message section to another may invalidate a substantial cached prefix. The response can still be correct, but costs and latency jump suddenly. Worse, if the application used the cache as a substitute for state reconstruction, behavior can change too.

Compaction must preserve recoverability

Long-running agents cannot keep every token in the active context window. Anthropic’s context-engineering guidance describes context engineering as ongoing curation of system instructions, tools, external information and message history. It recommends compaction, structured note-taking and retrieval strategies for work that exceeds the model window. Anthropic describes compaction as summarizing a near-limit conversation and restarting with that high-fidelity summary, while warning that overly aggressive compression can discard details that later become critical.

The reliability implication is that compaction is a transformation, not deletion. A summary can be a useful context artifact, but it must never be the only surviving copy of the events it represents. The original tool results, decisions and approval records should remain addressable in the durable log. A resumed agent needs the ability to inspect source events when a summary lacks the needed detail.

Figure 3 - How an agent resumes from a compacted summary while retaining access to the exact events behind it — see the chart in the original article.

This is also where reasoning state needs careful treatment. The postmortem shows that older thinking can help an agent understand the rationale behind prior action. But teams should not assume every intermediate reasoning trace belongs in every later prompt. The protocol should instead distinguish among durable decision records, task plans, tool evidence, approvals, compacted summaries and any provider-specific reasoning artifacts. Each category needs an explicit retention and retrieval rule.

That avoids two common errors. The first is retaining everything, which creates context pollution and makes relevance harder. The second is treating internal reasoning history as disposable cache material even when the agent’s future action depends on the rationale it contains.

Permission changes are an invalidation event

The most dangerous cache bug is not necessarily a miss. It is a hit on context that should no longer be valid.

Consider an agent with permission to modify a production repository, query a customer dataset or send emails on behalf of a user. If its stable prefix includes authorization assumptions, tool descriptions or workspace identity, a permission revocation must cause a new policy evaluation and a fresh context assembly. Reusing an old prefix that still implies broader authority turns performance optimization into an access-control failure.

Figure 4 - How policy changes force fresh context assembly before a tool call — see the chart in the original article.

The design principle is to keep authorization outside the model’s remembered narrative. The harness should check permissions at tool-call time against the current policy state. Cache keys and context manifests should include policy version, tool-schema version, workspace identity and relevant data-scope version. A cache hit can reuse computation, but it cannot be proof that a previously allowed action remains allowed.

This approach also makes incidents diagnosable. When an agent produces an unexpected result after resuming, operators should be able to answer: Which session events were selected? Which summary version was used? Which policy version governed the tool call? How many tokens were cache reads, cache writes and uncached input? Was the request routed to a machine that held the prefix?

OpenAI recommends tracking cached tokens, cache-write tokens, input-token counts, latency and realized cost, then calculating token cache-hit rate as cached tokens divided by total input tokens. Its documentation also notes that a minimum cache lifetime does not guarantee every request will reuse stored key-value tensors or reduce latency.

Build a cache-aware agent protocol

A robust protocol begins with a context manifest for every model call. That manifest should identify the session-log range, retrieved documents, compaction-summary identifiers, system-policy version, tool-schema version, authorization scope, cache breakpoint layout and expected cache key. Store it with the response and tool events.

Next, design explicit invalidation classes. Security policy and permissions should invalidate immediately. Tool schema changes should invalidate the affected prefix. New user instructions may alter only the suffix. A changed retrieval result should refresh the evidence block without destabilizing unrelated static material. Cache expiration should trigger reconstruction from the durable log, not a degraded fallback assembled from whatever happened to remain in memory.

Test these conditions as product behavior, not only as API behavior:

  1. Resume after cache eviction and compare the agent’s plan, retrieved facts and tool permissions with a clean reconstruction.
  2. Change a system policy mid-session and verify that no old prefix authorizes a now-prohibited action.
  3. Force a cache miss and measure latency, input cost and task quality separately.
  4. Run compaction before and after an important decision, then verify the agent can retrieve the source event.
  5. Replay the same event log through a newly deployed harness version and record any context-manifest differences.

The research community has begun treating these problems as integration defects rather than edge cases. Ying Zhang and colleagues’ study examined 120 prompt-caching-related pull requests across 10 open-source agent systems and argued that many mis-integrations fail silently, appearing as higher cost or latency rather than runtime errors. Their CacheLint prototype found 32 mis-integrations across 571 agent projects, according to the paper.

There is a second concern: Chenchen Gu and co-authors warned that cache-driven timing differences can create side channels when cache state is shared across users. Their paper reported evidence of global cache sharing across users in seven API providers and argued that caching-policy transparency matters because response timing can reveal information about other users’ prompts.

Only one side was found in the supplied reception material: these researchers are critical of treating prompt caching as transparent plumbing. No supplied source made the opposing case that cache integration can safely remain invisible to agent developers.

That absence is telling. The business opportunity is still real. Caching can widen margins, lower latency and make sophisticated agents economical at scale. But the companies that capture the durable advantage will be those that treat cache hits as a performance outcome, not a state guarantee. In the agent market, fast is valuable. Recoverable, auditable and correct is the moat.

Sources


Originally published at spaisee.com.

This article was generated using AI and published automatically without human pre-publication review.

Top comments (0)