Chad Research · Paper 02

The KV cache is the wrong memory.

Today's agents keep their memory in an enormous key-value cache in GPU RAM: gigabytes per agent, caching tokens rather than meaning. We replaced it with tools that rebuild exactly the context a step needs, in milliseconds.

10 min read16 references

Abstract

The KV cache stores the attention keys and values of every token a model has seen, so it doesn’t recompute them. It grows linearly with context, it lives in the scarcest memory in the data center, and most of what it holds is barely attended to again.

For agents that run for hours, the KV cache has quietly become their memory. We argue that is a category error. Memory should be durable, structured and queryable, a log of intents, changes and validated actions. The context should be rebuilt from it by tools for each small loop. The KV cache then goes back to what it is good at: a short-lived cache for a short context.

The arithmetic

For a transformer, the KV cache size is simple to compute:

KV bytes = 2 (K and V) × layers × kv_heads × head_dim × bytes_per_value × tokens

Grouped-query attention [3] and multi-query attention [2] shrink the kv_heads term, but the cache still grows linearly with every token appended. Try it:

…per token
…per agent
…for the fleet
…each square = one 80 GB GPU holding only KV

Exact formula. Excludes model weights, activations and allocator overhead.

KV cache per agent as context grows

Llama-3.1-70B architecture, BF16. Computed with the formula above.

Where the memory goes

Size is only half the problem. The other half is how little of that memory does useful work.

  • Fragmentation and over-reservation. The vLLM authors measured that serving systems before PagedAttention wasted 60–80% of KV cache memory [4]. Paging fixed the allocator, not the fact that the cache keeps growing.
  • Attention is sparse. A small set of “heavy-hitter” tokens receives most of the attention mass; H2O keeps model quality while evicting most of the cache [5]. StreamingLLM shows a handful of “attention sink” tokens plus a recent window suffices for stable generation [6], and SnapKV compresses the prompt cache by selecting what each head actually attends to [7].
  • Prefix fragility. Prefix caching only reuses an exact prefix. Change anything early (a system prompt, a summary, a reordered file) and everything after it must be recomputed.
  • Tokens, not meaning. The cache faithfully stores every dead end, wrong hypothesis and verbose log line. It has no notion of what was validated, what the intent was, or what is related to what.

Most of the cache is barely attended to

Schematic attention map (rows: generated tokens, columns: cached tokens). Bright = high attention weight. Patterns after H2O and StreamingLLM; not real model data.

attention sinksheavy hittersrecent windowrarely used

Share of cached tokens doing most of the work in this schematic: …

If most of the cache can be evicted without hurting quality, most of it was never memory. It was ballast.

Context is RAM, and RAM is volatile

There is a simpler way to see the problem. An LLM’s context window is working memory: fast, small, and private to one running process. MemGPT makes the analogy explicit and manages the context window like main memory in an operating system’s memory hierarchy [15]. The KV cache is its physical counterpart, sitting in GPU memory.

RAM is volatile, and so is context. It is lost in three ordinary ways:

  • The session ends. A restart, a crash, a timeout or simply the end of a task, and everything the agent held in context is gone unless something wrote it down.
  • The window fills. Long-running agents must truncate or compact their transcript. Anthropic’s context-engineering guidance describes compaction as summarizing the conversation near the limit and continuing from that summary [16]. By construction, whatever the summary leaves out is gone.
  • Agents do not share it. Each agent’s context is private. A second agent, or the same agent tomorrow, starts from zero.

Context is RAM. Memory has to live on disk.

Left: an agent's context window fills, gets compacted, then the session ends and it is wiped. Right: the same events written to a durable log. Illustrative.

context window · RAMfilling
held in context0
lost so far0
clickhouse · diskdurable
rows stored0
lost so far0

For one developer in one chat, that is an inconvenience. For an organization it is not acceptable. The reason a line of code exists, the decision taken in last week’s meeting, the constraint a customer insisted on: none of it can live only in a buffer that is overwritten when a window fills or a process stops.

Nothing important should exist only in context. Chad treats the context window as a cache loaded from disk: ClickHouse holds the durable memory, and each loop loads a small, compiled slice of it. Losing a context costs nothing, because nothing lived only there.

The agent era makes it worse

2026 research converges on the same diagnosis: for agents, the bottleneck is the KV cache, not compute.

Reported savings from cutting agent KV caches

Each paper's own reported reduction. Different models and setups, so read them as direction, not comparison. Hover for details.

  • IntentKV tracks intent across turns to decide which history tokens to keep, and cuts worst-case raw KV reads by 92.6% on Qwen2.5-14B with almost no accuracy loss [8]. The signal that matters is the intent, which is exactly what Chad stores explicitly.
  • DualPath finds that in agentic inference, KV-cache loading bandwidth, not computation, is the bottleneck [9].
  • TripleKV reports that under high agent concurrency the combined KV working set reaches hundreds of GiB, and that retrieval delays stall agents [10].
  • CoMixKV reduces peak KV memory by 32% for multi-agent systems by mixing precisions across co-resident caches [11]; AgentKV, ActKV and online compaction studies propose phase-aware, action-guided and incremental eviction [12][13][14].

Every one of these papers works hard to decide, after the fact, which cached tokens still matter. We think the better move is to never cache what doesn’t matter in the first place.

Tools instead of RAM

In Chad, what used to be a giant KV cache in RAM is replaced by tools that build the data a step needs, on demand:

  • ClickHouse as the memory expert. We have contributed to ClickHouse for years and use it to log everything: every GitHub event, every human input, every signal from Sentry or Prometheus.
  • Git history as ground truth. Every change is decomposed into ClickHouse rows of additions and deletions, each linked to the intent behind it. Finding the tasks and diffs related to a new problem is a columnar query that returns in milliseconds. No LLM has to grind through history for nothing.
  • Validated actions. Each action is stored as an input → output pair once it has been executed and validated, either by a human or by an AI verifier. Context is rebuilt from what is true, not from what was said.
  • Many small loops. Chad spawns far more LLM loops than a monolithic agent, each with a small compiled context and one atomic task. Each loop’s KV cache is small, short-lived and thrown away.

Context rebuilt by tools, every loop

What replaces the giant KV cache. Query timings shown are example values.

?Step needs contextctx.related(intent)
▦ClickHousegit_changes · intents · actions
≡Compile~6k tokens
✦Small LLM loopone atomic task
✓Validate & write backhuman or AI check
compiled context…

KV cache as memory

  • Grows linearly with every turn
  • Lives in scarce GPU RAM
  • Stores tokens, including dead ends
  • Invalidated by any early change
  • Lost when the session ends

Chad: tools + ClickHouse

  • Context compiled per step, ~6k tokens
  • Lives in cheap, durable columnar storage
  • Stores intents, diffs and I/O validated by humans or AI
  • Queried by intent in milliseconds
  • Shared across every agent and project

Fleet-level impact

Same model, same number of agents, different memory strategy. Below, 50 concurrent agents on the Llama-3.1-70B architecture in BF16. All values are computed from the formula.

One 80 GB GPU, two memory strategies

KV size per agent = 320 KiB × tokens (Llama-3.1-70B, BF16). Animation speed is illustrative.

Accumulating agents4 agents, context grows every turn
OUT OF MEMORY · evict / restart
0 GB
Chad loopssmall compiled contexts, freed when done
0 GB
Chad loops completed0
Live Chad loops0
KV per Chad loop≈1.9 GB

KV memory for 50 concurrent agents

Accumulated context per agent vs. a ~6k-token compiled context. GiB.

Computed: 320 KiB/token × context × 50 agents. KV footprint only.

Trade-offs

Rebuilding context means re-running prefill for every loop. With ~6k-token contexts, prefill is cheap, highly parallel and cacheable for the stable part of the prompt (best practices, intent). The ClickHouse queries that assemble the rest add milliseconds. In exchange, memory becomes durable, auditable and shared across agents, and the model never has to find the intent in a haystack (see Paper 01).

We are publishing our own measurements of end-to-end cost and latency on real repositories here as they land.

References

  1. Vaswani, A. et al. Attention Is All You Need. NeurIPS, 2017.
  2. Shazeer, N. Fast Transformer Decoding: One Write-Head is All You Need. arXiv, 2019.
  3. Ainslie, J. et al. GQA: Training Generalized Multi-Query Transformer Models from Multi-Head Checkpoints. EMNLP, 2023.
  4. Kwon, W. et al. Efficient Memory Management for Large Language Model Serving with PagedAttention. SOSP, 2023.
  5. Zhang, Z. et al. H2O: Heavy-Hitter Oracle for Efficient Generative Inference of Large Language Models. NeurIPS, 2023.
  6. Xiao, G. et al. Efficient Streaming Language Models with Attention Sinks. ICLR, 2024.
  7. Li, Y. et al. SnapKV: LLM Knows What You are Looking for Before Generation. NeurIPS, 2024.
  8. Li, J., Lou, J., Li, J. IntentKV: Cross-Turn Intent-Aware KV Cache Pruning for Agent Inference. arXiv:2606.09916, 2026.
  9. DualPath: Breaking the Storage Bandwidth Bottleneck in Agentic LLM Inference. arXiv:2602.21548, 2026.
  10. TripleKV: Predict, Prefetch, Protect - KV Cache Management for AI Agents. arXiv:2611.25112, 2026.
  11. Coordinated Mixed-Precision KV Cache Quantization for Efficient LLM-based Multi-agent Systems. arXiv:2611.10096, 2026.
  12. AgentKV: Phase-Aware KV Eviction for Agentic LLMs. arXiv:2609.14872, 2026.
  13. ActKV: Efficient LLM Agents through Action-Guided KV Cache Management. arXiv:2609.31395, 2026.
  14. Practical Online KV Cache Compaction for LLM Agents: An Empirical Study. arXiv:2608.00902, 2026.
  15. Packer, C. et al. MemGPT: Towards LLMs as Operating Systems. arXiv, 2023.
  16. Anthropic. Effective context engineering for AI agents. 2025.