INQUIRING LINE

Why do agents that trim old chat or shorten tool results end up paying full price again on every AI call?

Why does context pruning and tool summarization break cached prompt representations?

This explores why agents that trim old context or condense tool outputs to save space can end up losing the savings from prompt caching, and what designs avoid that tradeoff.


This explores why tidying up an agent's context, by dropping old turns or swapping long tool outputs for summaries, can quietly undo prompt caching. The short version is that caches reuse only an exact, unchanged prefix. The corpus has no paper that tests pruning against caching directly. It does have enough pieces to explain the mechanism and to show how some systems get around it.

The key fact comes from work on tool discovery. A cache hit needs the start of the prompt to match exactly, token for token, what was cached before Does dynamic tool discovery break prompt caching benefits?. The model's internal state for each token depends on every token that came before it. So if you change something early in the prompt, every cached state after that point is stale. Pruning a middle turn or replacing a 5,000-token tool result with a three-line summary edits the prompt in exactly the place a cache can't tolerate. The cache stops at the first changed token, and the system has to recompute everything after it. The same paper's fix also applies here: keep a fixed, stable core at the front of the prompt and push variable material later, where changes cost less.

The stakes are large. Across OpenAI, Anthropic, and Google, caching cut agentic API costs by 41–80% and sped up the first token of each reply by 13–31% Does prompt caching actually reduce agentic LLM costs?. The same benchmark found that caching everything blindly can actually increase latency, because content that will never repeat still gets written to the cache. Taken together, the two papers show that pruning and caching are both bets about which parts of the context stay fixed. They conflict when you make different bets for each.

The more interesting part is how other designs handle this. Compression methods like LLMLingua rewrite the prompt itself. They can shrink it 20x with little accuracy loss Can prompts be compressed without losing model performance?, but a rewritten prompt is a new prefix, so you trade cache reuse for fewer tokens. ReWOO-style planning takes a different route: it plans the reasoning up front and keeps tool observations out of the main reasoning flow, so the prompt doesn't keep growing and changing with every tool call Can reasoning and tool execution be truly decoupled?. Recursive Language Models go further and never put the long prompt in context at all. They store it in a code environment and query it when needed Can models treat long prompts as external code environments?.

The surprise is that you can prune the cache itself instead of the text. The Thread Inference Model structures reasoning as a tree of subtasks and uses fixed rules to drop finished branches directly from the KV cache (the model's stored internal state for earlier tokens). It keeps reasoning accurately even after changing 90% of that cache Can recursive subtask trees overcome context window limits?. Related work argues that the real long-context bottleneck isn't memory but the compute needed to turn discarded context into lasting internal state Is long-context bottleneck really about memory or compute?. That points to a different framing: the problem isn't pruning as such. It's pruning at the text level, after the cache has already been built around the original text.


Sources 7 notes

Does dynamic tool discovery break prompt caching benefits?

MCP-style dynamic tool discovery breaks prompt caching because tool definitions in the prefix must match exactly for cache hits. Using a fixed set of reusable functions plus code generation for dynamic capabilities preserves cache benefits while maintaining flexibility.

Does prompt caching actually reduce agentic LLM costs?

A benchmark across OpenAI, Anthropic, and Google found caching reduces API costs 41–80% and improves time-to-first-token 13–31% in multi-turn agentic tasks. However, naive full-context caching can increase latency by caching dynamic content that will never be reused.

Can prompts be compressed without losing model performance?

LLMLingua achieves up to 20x prompt compression with only 1.5-point performance drops by allocating less compression to instructions and questions, more to demonstrations, then pruning tokens using a small model's perplexity scoring aligned to the target LLM.

Can reasoning and tool execution be truly decoupled?

ReWOO and Chain-of-Abstraction both decouple reasoning from tool responses through different mechanisms—planning-before-execution and abstract placeholders respectively—eliminating quadratic prompt growth and sequential latency while maintaining reasoning quality.

Can models treat long prompts as external code environments?

Recursive Language Models store long prompts in a Python REPL and query them via code execution, avoiding attention degradation. RLMs outperform base models even on shorter prompts while handling inputs two orders of magnitude beyond context windows.

Show all 7 sources
Can recursive subtask trees overcome context window limits?

The Thread Inference Model demonstrates that reasoning structured as recursive subtask trees with rule-based KV cache pruning sustains accurate reasoning beyond context limits, even when manipulating 90% of the cache. This enables single models to replace multi-agent systems by handling full recursive reasoning internally.

Is long-context bottleneck really about memory or compute?

Research shows the bottleneck is not memory capacity but the compute required to consolidate evicted context into fast weights during offline sleep phases. Performance improves with more consolidation passes, following a test-time scaling pattern on harder reasoning tasks.

Papers this line draws on 8

The research behind the notes this line reads — ranked by how closely each paper relates.