Context Has a Price: Adding and Removing Context for LLM Coding Agents under Prefix Caching
Zerui Yang, Miaomiao Dong, Quan Xue, Chaorui Zhang, Xuanyu Zheng, Xiyuan Wang, Haolin Ruan, Xueyan Niu, Guangcheng Song, Weixi Zhang, Wei Han, Bo Bai
Abstract
Coding agents repeatedly send their conversation history to a language model. Adding useful code may reduce search, while removing old tool outputs may shorten later prompts. But do these changes reduce the cost of solving a task? We study this as a measurement problem in more than 20,000 runs of open models on SWE-bench Verified, SWE-bench and Loc-Bench. We account separately for uncached input, cached input and output tokens. Three findings emerge. First, in our main evidence-package experiments, retrieved code reduces read and search commands by 18--34%, but increases cost by 33--42% when cached input costs one tenth of uncached input, without a measurable improvement in resolution. Second, removing old observations can either save money or increase cost: the same approach saves 19--36% without a cache discount but increases cost by 38--116% with a tenth-price cache. Third, shorter prompts do not guarantee cheaper runs because agents may respond by taking more steps. We also find that concurrent experiments can share cached prefixes and distort cost comparisons. These results show why context-management methods should be evaluated using both token prices and the agent's subsequent behavior.
Create a lesson
Related papers
CompAct-Bench: A Benchmark for Working-Context Compaction in Long-Horizon Agent Tasks
Shared title terminology · Jiayi Chen, Lizhe Chen, Yujia Chen et al.
Think Offline, Act in Real Time: Self-Improving Visual Game Agents through Code
Shared title terminology · Zipeng Qiu, Shusheng Xu, Jiale Li et al.
Semantic Context Handoff with On-Demand Evidence for Long-Horizon Agents
Shared title terminology · Guolong Zheng, Chen Hou, Xu Yang et al.
Reducing Inference Cost of Coding Agents with Timeout Cascades
Shared title terminology · Boxi Zhou, German Sviridov, Dmitrii Ustiugov et al.
3D GameDev Arena: Benchmarking Coding Agents That Plan, Build, and Playtest extreme Long-Horizon Browser Games
Shared title terminology · Bizhe Bai, Jiliang Jian, Yuqing Yan et al.
Metrics-in-the-Loop: Complexity Feedback Reshapes Agent-Written Code
Shared title terminology · Nicolas Chapados, Jean-François Gagné, Nouha Dziri