TurnCost: Turns, Not Observations: Cache-Aware Loop Engineering for Coding Agents
Abstract
AI coding agents operate in iterative loops: they modify code, run tools, inspect the results, and decide what to do next. We call the design of this process loop engineering, which includes context management, model selection, compaction, and termination. Existing efficiency work mainly compresses tool observations or routes selected turns to cheaper models, but the practical opportunity for these optimizations remains unclear. We analyze 600 publicly released coding-agent trajectories spanning two agent scaffolds and two language models. Median observations contain only 118-286 tokens, while the large build logs commonly used to motivate compression occur near the ninety-ninth percentile. Moreover, 98.6% of input tokens are served from a prefix cache, so flat input pricing overestimates loop cost by roughly 7x on average under near-ideal caching. We derive and empirically validate a closed-form break-even condition for model delegation. Delegation increases cost in half of the evaluated settings, near the predicted boundary. More broadly, turn count explains 84% of the variance in log trajectory cost, compared with 4% for mean observation size; the most expensive trajectories have the most turns despite having the smallest observations. These associations suggest that observation-focused methods target a secondary cost factor, and identify unnecessary turns as the larger and largely unexamined opportunity, though we do not establish that turns can be removed while holding task success fixed. We release TurnCost, a tool for re-scoring trajectory corpora under alternative caching, pricing, compression, and routing policies.
Create a lesson
Metadata
- Categories
- cs.SE, cs.AI, cs.ET, cs.LG
Related papers
SpecEngineeringBench: Evaluating Coding Agents as Autonomous Specification Engineers
Shared title terminologycs.SEXingjian Wang, Shijian Wang, Minghao Liu et al.
Doc2Harness: Benchmarking LLMs on Long-Horizon Harness Engineering of Coding Agents
Shared title terminologycs.SEYuyao Ge, Shenghua Liu, Peizhong Gao et al.
Implementing the Spec Growth Engine: Preventing Spec-Code Divergence, and Growing the Spec with Agents
Shared title terminologycs.SEHartwig Grabowski
Why Software Engineering Is Indispensable in the Age of Coding Agents
Shared title terminologycs.SEAlfonso Fuggetta
Large-scale Repository Engineering via Agent-Native Reusable Code Primitives
Shared title terminologycs.SEHaibo Jin, Peng Kuang, Xucheng Yu et al.
Does Training-Free Delegation Improve Cost Efficiency in Multi-Agent Software Engineering Systems? An Empirical Study
Shared title terminologycs.SEMootez Saad, Mohammad Masudur Rahman, Tushar Sharma