A Good Agent Harness Starts With Cache Hits

    In real-world LLM applications, cost is often the most underestimated hidden variable. This is especially true for agentic applications, where a single task can generate millions of input tokens. Prompt caching makes "pay once for the same prefix" possible, and a well-designed harness can push cache hit rates high enough to cut bills by an order of magnitude. This article explains why prompt caching saves so much, why the hit rate depends on the harness rather than the model, and which engineering practices improve it. It also covers the latency benefits that come alongside the cost savings.

    In real-world LLM deployments, cost is often the most underestimated hidden variable. For agentic applications in particular, a single task can easily produce millions of input tokens. If all of those tokens were billed at full price, the bill would balloon to an uncomfortable level fast. Prompt caching changes that by making “the same prefix is only paid for once” possible.

    A recent community example is telling: a developer running a new-generation model inside their own agent execution framework reached a cumulative cache hit rate of 99.93%. That translated to roughly 947 million cache-hit input tokens costing about $2.65; the same tokens billed at the non-cached rate would have cost around $132.62 — a full 50x difference. Behind these numbers lies a deep coupling between framework engineering and the model’s billing mechanism.

    Why Prompt Caching Saves So Much

    Most major LLM providers use a prefix caching strategy: if the input prefix of the current request exactly matches a recent request, the server can reuse the already-computed KV Cache and skip the redundant forward computation. Since a large part of inference cost comes from attention computation over input tokens, the compute saved here is passed back to callers as a steep discount. A common pricing structure is: the cache-hit portion costs about one-tenth of the original price or even less, the cache-write portion is slightly higher than or on par with the original price, and the non-cached portion is billed at full price.

    This explains the 50x gap in the example: when nearly all input hits the cache, the effective price approaches “one-tenth of the original price multiplied by the hit rate,” so the bill is compressed by an order of magnitude.

    Why the Hit Rate Depends on the Harness, Not the Model

    Caching is a server-side capability, but whether a request hits depends on how the client organizes its requests. The agent framework (the harness) plays the decisive role, mainly in three ways:

    1. Prefix stability. Cache matching is strict prefix matching — a single differing byte invalidates everything from that position onward. This means the system prompt, tool definitions, and the serialization format of message history must be byte-for-byte stable. If the framework dynamically reorders the tool list on each turn, reformats timestamps, or injects a random ID into the system prompt, the cache will be repeatedly busted.

    2. Append-only conversation management. The ideal agent loop should use an “append-only, never modify” message history strategy: each turn appends the new tool-call result to the end of the history rather than compressing, summarizing, or rewriting it. Once the history is rewritten — even a small change in the middle — the cache for all subsequent tokens is invalidated.

    3. Request cadence and cache lifecycle. Caches typically have a time-to-live (TTL) and are evicted after too long without access. A framework that keeps a steady call cadence, or refreshes requests to keep the cache warm, will see a significantly higher hit rate. Parallel subtasks that interleave requests across different prefixes without careful design will also compete for cache space.

    An Engineering Checklist for Higher Hit Rates

    Drawing on common industry experience, you can start with the following:

    • Fix the prefix: put the system prompt, tool schema, and few-shot examples at the very front, and keep their content and order completely unchanged;
    • Isolate dynamic information: keep volatile content such as time, random numbers, and user IDs at the end or external to the request, so it does not pollute the prefix;
    • Set cache breakpoints: for very long contexts, draw a clear boundary between stable and dynamic segments so the stable portion stays as long as possible;
    • Monitor the hit rate: bring cache-hit, cache-miss, and cache-write token counts into your monitoring and alerting as first-class metrics — an abnormal drop in hit rate often means a framework change has broken prefix stability;
    • Ensure serialization determinism: serialize tool-call arguments and JSON structures deterministically to avoid field reordering caused by unstable map iteration order.

    A simple self-check: diff the full input text of two adjacent requests. The earlier the first difference appears, the worse the cache invalidation. A script of a few dozen lines can do this continuously:

    1. def first_divergence(prev, curr):
    2. for i, (a, b) in enumerate(zip(prev, curr)):
    3. if a != b:
    4. return i
    5. return min(len(prev), len(curr))

    The later the divergence point, the longer the reusable prefix.

    Beyond Cost: The Knock-On Benefits of Hit Rate

    Cache hits are about more than saving money. Reusing the KV Cache means the server does not recompute the prefix, so time to first token (TTFT) drops noticeably. For agent scenarios with many tool calls and high-frequency interaction, the improvement in experience is very tangible. In addition, a stable cache design often forces the framework toward a more disciplined message-management architecture, which is itself a mark of engineering quality.

    Conclusion

    The 99.93% hit rate in the example above was not the model’s doing alone; it was the product of a framework author’s deep understanding of the caching mechanism: a stable system prompt, append-only history, and restrained context management together produced a bill on which nearly all of the expensive input was discounted. For developers building agent applications, evaluating a harness should go beyond feature completeness — cache hit rate deserves to be one of the core metrics. Get prefix management, this “small” thing, right, and both cost and latency will reward you by an order of magnitude.