Token Tadka · T2 Context & memory

Prefix caching

Last reviewed 3 Nov 2026by Pratima Chainani

Reusing the stored computation for the unchanged start of a prompt, so only the new part is processed. It pays off only while that start stays identical, which is why trimming an agent's history can cost more than it saves.

An agent sends the whole conversation back to the model on every turn: system prompt, tool definitions, every earlier tool result. With prefix caching on, the server keeps the computed state for the part of the prompt it has already seen, so only the new tail goes through prefill, the compute-heavy step that reads input before the first output token. A cache hit needs the start of the prompt to match exactly, token for token.

That makes history cheap in one way and expensive in another. A DEV post on 22 October 2026 put the expensive side well: “The same model can be 5x more expensive per input token depending on how much history you drag along.” Per token, that’s fair. The usual reaction is to trim the history.

A paper submitted on 26 October 2026 measured what trimming does when caching is on. It ran mini-SWE-agent on 100 SWE-bench Verified tasks with a policy that keeps only the last five observations. Prompt volume fell by 33.3%. But the policy threw away 135.9k reusable tokens per task, uncached prefill rose by 608.5% (about 7×), the GPU-energy proxy rose by 125.6%, and the run failed the paper’s five-point quality bar. In the authors’ words: “Deleting history can turn a token saving into extra work.”

The mechanism is the cache match. Delete one observation from the middle and every token after it moves, so the cache matches only up to the cut. Everything after the cut is prefilled again, and again on the next turn, because the window keeps sliding.

The same paper shows the other side: with caching on, keeping the full history left prompt volume roughly unchanged (+8.3%, with a confidence interval that spans zero) while uncached prefill fell by 67.7%.

The limits: one agent setup, 100 tasks, energy measured by a proxy, and a workshop paper. Providers bill cache hits differently, so what this does to your invoice depends on how yours prices cached input.

Common misread

Shorter prompts are cheaper prompts.

With caching on, the cost is uncached prefill. Cutting the middle of the history makes more of it.

For your code

Keep the start of the prompt stable: fixed system prompt and tool list first, history appended, never edited in place. Before you trim, log uncached prefill tokens per task and compare before and after.

For your roadmap

Ask your provider how cache hits are billed and how long a cached prefix lives, and track uncached prefill per task, not prompt length.

Sources

  1. Yu et al., The Physical Cost of Context: Quality-Constrained Resource Accounting for Coding Agents (arXiv 2610.34763), NeurIPS 2026 Workshop on Resource-Aware Agentic AI · 26 Oct 2026
  2. makayis, October’s model price cuts are real. Your long agent session will still find a way around them (DEV) · 22 Oct 2026

More on T2 Context & memory

Every term, by layer