Research Published here Reported by arXiv on

Trimming your agent's context saves 19–36% — until you price the cache, and then it costs up to 116% more

Zerui Yang, Miaomiao Dong, Quan Xue, Chaorui Zhang, Xuanyu Zheng, Xiyuan Wang, Haolin Ruan, Xueyan Niu, Guangcheng Song, Weixi Zhang, Wei Han, and Bo Bai treat context management as a measurement problem and run more than 20,000 agent executions with open models on SWE-bench Verified, SWE-bench, and Loc-Bench, accounting separately for uncached input, cached input, and output tokens. Three findings come out. First, injecting retrieved code into the agent's context reduced read and search commands by 18–34% but increased total cost by 33–42% when cached input is priced at one tenth of uncached input, with no measurable improvement in task resolution. Second, removing old tool observations cuts both ways: the same technique saves 19–36% with no cache discount but increases cost by 38–116% once a tenth-price cache is in play, because editing the history invalidates the prefix everything after it was reusing. Third, shorter prompts do not guarantee cheaper runs, since agents respond to a thinner context by taking more steps. The authors add a methodological warning that lands squarely on anyone benchmarking this themselves: concurrent experiments can share cached prefixes, which distorts cost comparisons between conditions.

Why it matters

Nearly every context-management technique in circulation — summarize the history, drop old tool outputs, prune the transcript — was designed against a mental model where tokens cost one price. With prefix caching at a tenth of the rate, the economics invert, because every edit to the middle of a conversation throws away the cached prefix for everything downstream. The sign of the effect flips, not just the magnitude, and a 38–116% increase is not a rounding error on a technique teams adopt specifically to save money. The retrieval finding is the one that should sting: injecting the right code genuinely reduced the agent's searching by up to a third and still cost more without resolving more tasks, which means "the agent did less work" and "the run was cheaper" have come apart. And the shared-prefix warning explains a class of confusing benchmark results people have been quietly attributing to noise.

What to do

Re-measure every context-trimming technique you run against your provider's actual cached and uncached rates, because if you validated it before prefix caching was priced in, you validated it under economics that no longer hold. Prefer append-only context management — add at the end, avoid rewriting history — since anything that mutates the middle of the transcript invalidates the cache for everything after it. Stop treating prompt length as a cost proxy and measure dollars per resolved task, given that shorter prompts here routinely produced more steps. And when you run comparisons, isolate conditions in time or in separate accounts so concurrent runs cannot share a cached prefix and make one arm look cheaper than it is.

Tags: Agents Cost Optimization Evaluation Research

More from November 21, 2026

All AI news