Cache Engineering for Agents
Tianyu Fu, Ruoxi Wang, Zihan Min, Zhongqi Ren, Zhihao Li, Tengxuan Liu, Shengxu Mu, Hanling Zhang and 1 others
Tsinghua University · The Chinese University of Hong Kong
Published October 20, 2026 · on the feed October 22, 2026 · ▲ 159 · arXiv 2610.28577
The abstract
Large Language Model (LLM) agents can handle increasingly complex tasks, navigating long trajectories of observations and actions. As these trajectories grow, key-value (KV) cache I/O and storage become the dominant cost. Trajectories can also exceed the LLM's maximum context length, requiring control over active cache growth. Prior work uses context engineering to reduce cache size by trimming or summarizing history. However, modifying the trajectory prefix invalidates subsequent cached states and triggers costly re-prefilling of retained context. Task accuracy can also suffer when too little context is retained to limit re-prefill costs. We propose cache engineering as a new scheme. It allows agents to directly control their active KV cache without modifying the trajectory or re-prefilling retained context. Specifically, agents can proactively use drop to exclude selected cache from future attention and repos to adjust retained keys' position encodings. We formalize these cache operations and identify history dependence as a serving challenge: identical token sequences can yield different cache states under different cache operation sequences, making prefix matching insufficient for correct cache reuse. Thus, we co-design the AKV serving engine. It provides a stateless interface compatible with existing serving APIs, while internally managing stateful cache reuse, eviction, and restoration. Experiments show that a tool-response rolling-drop cache policy improves average benchmark scores by 1.7 points and reduces average cost by 27.7%, compared with conventional threshold-triggered summarization. With AKV, it achieves up to 1.2x the output throughput and a 1.5x speedup in P95 request latency. Recursive self-improvement of cache policies further reduces cost by 7.1% over expert design. Our code is at https://github.com/thu-nics/AKV.
The Brief
3:19A short podcast summary of the paper. Written and voiced by AI.
Transcript
Cache Engineering for Agents. By Tianyu Fu and eight others, from Tsinghua University and the Chinese University of Hong Kong. Published on the twentieth of October. Its code repository is worked out: about fifty source files, with a readme and a licence.
Language-model agents now take on complex tasks that unfold over long trajectories of observations and actions. As a trajectory grows, the input and output traffic and the storage of the key-value cache become the dominant cost. A trajectory can also outrun the model's maximum context length, so the growth of the active cache has to be controlled somehow.
Prior work does this through context engineering, trimming or summarising the history to shrink the cache. The catch is that editing the start of a trajectory invalidates every cached state that came after it. The retained context then has to be prefilled again, which is costly. And if an agent keeps very little context to limit that re-prefill cost, task accuracy can suffer. Either way, something is paid.
Cache engineering, the scheme proposed here, lets an agent control its active key-value cache directly, without modifying the trajectory and without re-prefilling the context it keeps. Two operations make that possible. An agent can use drop to exclude selected cache from future attention, and repos to adjust the position encodings of the keys it retains. The agent applies them proactively, as part of how it works.
Formalising these operations exposes a serving problem the authors call history dependence. Identical token sequences can end up with different cache states, depending on which sequence of cache operations produced them. Prefix matching, which ordinarily decides when a cache can be reused, is no longer enough to guarantee the reuse is correct. Two requests may look the same token for token and still need different caches, because one agent dropped part of its history and the other did not, or one repositioned its keys and the other left them. The server can no longer tell from the text alone which cache state a request belongs to.
The answer is a co-designed serving engine called AKV. From the outside it presents a stateless interface compatible with existing serving APIs. On the inside it manages the stateful parts itself: cache reuse, eviction, and restoration. Clients keep calling it the way they already call a serving engine, and the bookkeeping that history dependence demands happens behind that interface.
The comparison is against conventional threshold-triggered summarization. A tool-response rolling-drop cache policy improves average benchmark scores by one point seven points while cutting average cost by twenty-seven point seven percent. Served through AKV, it reaches up to one point two times the output throughput and a one point five times speedup in P95 request latency. So the policy is cheaper and slightly more accurate than summarising, and the engine makes it faster to serve as well.
Cache policies can also improve themselves. Recursive self-improvement of the policies reduces cost by a further seven point one percent beyond an expert-designed policy.
The shift is in where the editing happens. Context engineering edits the text, and the cache has to be rebuilt to match. Cache engineering edits the cache, and the text is left alone. That move creates a new obligation for the server, tracking how each cache state came to be, and AKV is built to carry it while looking like an ordinary serving endpoint from outside.
Paper Quest · 7 chapters · about 41 min
Play this paper
Learn it by doing: make the calls the authors made, guess the result before you see it, and defend it in a viva graded on your own words. Chapter 1 is right here.
Chapter 1 🧩 · The problem
Long agent runs pile up memory. Every fix so far makes you pay twice.
You run a language-model agent that searches, calls tools and reasons over a very long trajectory. Its stored attention keys and values keep growing, and reading them back has become the main cost of every step.
The road ahead
- 1 · The problem ~7 min As an agent's history grows, its stored attention cache becomes the main cost, and the usual text-level trimming forces costly recomputation.
- 2 · What came before ~3 min
- 3 · The key idea ~9 min Cache engineering lets the agent edit its stored KV cache directly, leaving the text untouched, so the kept cache is reused without re-prefill.
- 4 · Choose your own research ~3 min
- 5 · Build the method ~8 min The agent drops and repositions cache entries, sends them with its messages through a stateless interface, and AKV handles reuse, eviction and restoration inside.
- 6 · The experiment ~6 min You’ll guess: Compared with conventional threshold-triggered summarization, how much did a tool-response rolling-drop cache policy cut average cost?
- 7 · The viva ~5 min Three questions from the examiners, answered in your own words. Win it for the paper’s trophy.
Free, with Google or an email address. Your stars and progress are kept.