跪拜 Guibai
← All articles
Agent · Artificial Intelligence

A 94.5% Cache Hit Rate Cut This Coding Agent's Costs by 85%

By 樊小肆 ·
Read original on juejin.cn ↗ Google Translate ↗ Alt translation

Coding agents are input-heavy by design, and a high cache hit rate is the single biggest lever for controlling cost. This breakdown shows that a 94.5% hit rate—achieved through deliberate, cache-aware engineering rather than luck—can reduce input costs to one-seventh of the uncached baseline, turning what would be a prohibitive bill into pocket change.

Summary

A one-hour stress test of the open-source coding agent DeepSeeker-Code on the deepseek-v4-flash model consumed 25.68 million tokens at a total cost of ¥2.26. The output was a negligible 195,000 tokens; the agent's cost structure is dominated by repeatedly re-sending the full context—system prompts, tool definitions, and conversation history—which made input 130× larger than output. A 94.5% cache hit rate on those input tokens slashed the input bill by roughly 85%, because DeepSeek's context caching charges about one-tenth the standard price for repeated prefixes. That hit rate is not accidental. It is preserved through strict engineering constraints: the system prompt is immutable and always occupies the first message position, compression is deferred when the cache is healthy and triggered early when it is already broken, and the message structure keeps fixed slots for summaries and tool definitions. These choices trade away flexibility and lock the agent into DeepSeek's specific caching behavior, but for a high-frequency local agent the cost savings make the coupling worthwhile.

Takeaways
25.68 million tokens processed in one hour cost ¥2.26, with a 94.5% cache hit rate on input tokens.
Output accounted for only 0.76% of total tokens; the agent re-sent the full context repeatedly, making input 130× larger than output.
Cache-hit tokens are billed at roughly one-tenth the price of uncached tokens, cutting the input cost by nearly 85%.
An absolutely stable system prompt—always first in the message list, never reordered or prepended—is the foundation for a high hit rate.
Compression timing is tied to cache health: it is delayed when hit rates are high and triggered early when the cache is already broken.
Fixed positions for the summary slot and tool definitions prevent structural changes from breaking the prefix.
The approach is tightly coupled to DeepSeek's caching behavior and sacrifices prompt-engineering flexibility for cost control.
Conclusions

Agent economics invert the usual LLM cost intuition: output is cheap and negligible, while the repeated re-transmission of a growing context dominates the bill.

Cache hit rate is not a passive property of the model provider; it is an engineering outcome that must be actively preserved through strict constraints on prompt structure and compression timing.

The trade-off between flexibility and cost is stark—every structural change to the system prompt risks shattering the cache and multiplying the bill, so stability becomes a hard requirement rather than a nice-to-have.

Tying compression logic to cache health is a pragmatic heuristic that turns a destructive operation into a cost-aware decision, but it also deepens the agent's coupling to a specific model's caching implementation.

Concepts & terms
Context Caching
A mechanism where an LLM provider stores the prefix of a prompt for a limited time. If a subsequent request shares the same prefix, those tokens are served from cache at a significantly reduced price—roughly one-tenth the standard input rate on DeepSeek.
Cache Hit Rate
The percentage of input tokens in a request that match a previously cached prefix. A high hit rate is the primary lever for reducing the cost of agent workloads, which re-send large, repetitive contexts with every reasoning step.
Prefix Stability
The engineering practice of keeping the beginning of every LLM request identical across calls—fixed system prompts, fixed message ordering, and no prepended content—so that context caching can apply to the maximum number of tokens.
Source: juejin.cn ↗ Google Translate ↗ Backup ↗