Abstract
LLM-powered coding agents are increasingly used for complex software engineering tasks, but their iterative nature leads to significant operational costs due to quadratic token growth in conversation histories. This paper investigates "turn-control" strategies—imposing strategic limits on the number of iterations an agent can perform. Our empirical evaluation using the SWE-bench Verified benchmark reveals that constraining agents can reduce costs by up to 68% while maintaining or even improving performance by mitigating model "hallucination loops."
Introduction
Modern coding agents operate in iterative loops, processing issue descriptions and codebases to generate patches. However, each subsequent "turn" adds to the conversation history, leading to $O(n^2)$ token growth. Without constraints, agents often engage in unproductive exploration or over-engineering, resulting in prohibitive costs. This study explores whether managing the total number of turns can optimize the efficiency of state-of-the-art models like Claude 4 Sonnet, Gemini 2.5 Pro, and GPT 4.1.
Methodology: Turn-Control Strategies
We evaluated three primary strategies for managing agent iterations using the open-source TRAE Agent:
- Unrestricted Baseline: The agent runs until it self-terminates.
- Fixed-Turn Limit: Agents are given a hard deadline based on the 25th, 50th, or 75th percentile of baseline turn distributions, accompanied by periodic "turns left" reminders.
- Dynamic-Turn Strategy: A multi-stage approach where agents start with a small budget and receive a one-time extension if a solution is not reached.
The dynamic strategy (Figure 2) aims to balance resource allocation by providing extra budget only to tasks that demonstrate a need for further iteration, thereby avoiding over-provisioning for simpler tasks.
Experimental Setup
The study utilized a curated subset of 100 tasks from the SWE-bench Verified benchmark. This subset was designed to reflect the original distribution of repositories (e.g., Django, Matplotlib, Sympy) and task types, ensuring that the findings are representative of real-world software engineering challenges. To ensure a fair comparison, prompt caching was disabled during the experiments.
Results and Discussion
Our results demonstrate a significant efficiency gain across all tested models. Notably, we observed a "More with Less" anomaly: Gemini 2.5 Pro's solve rate increased by approximately 3% when constrained to a 75th-percentile turn limit, even as its operational costs dropped by 68%.
As shown in Figure 5, the 75th percentile limit serves as a "sweet spot," providing substantial cost reductions (24% to 68%) with minimal impact on solve rates. Qualitative analysis suggests that turn limits foster "focused urgency," prompting agents to prioritize relevant file inspections over exhaustive, unfocused reconnaissance. Under pressure, agents adopt more decisive behaviors, making iterative, verifiable changes rather than getting lost in unproductive exploration.
Conclusion
Turn-control is a powerful lever for managing the cost and performance of coding agents. By moving away from unrestricted execution and adopting intelligent constraints—particularly dynamic allocation—developers can create agents that are not only more affordable but also more decisive and effective in solving real-world software issues. Future work may explore more sophisticated communication of budget constraints or confidence-based turn bidding.
Summary updated