Metrics-in-the-Loop: Complexity Feedback Reshapes Agent-Written Code

Nicolas Chapados, Jean-François Gagné (Nera Software) and Nouha Dziri (Cohere Labs, Mila) inject cheap code metrics into a coding agent's context after each edit and measure how this changes the code agents write over long runs.
Ask this paper
Metrics in the loop. After each code-changing turn, a short message names changed functions whose cyclomatic complexity exceeds a limit, or changed lines that tests skip. The agent can then refactor or add tests before continuing.
Setup. Four models (DeepSeek V4.1 Flash, GLM-5.3 Flash, Claude Haiku 5.5, GPT-6 Luna) on three long-horizon benchmarks (Commit0, SlopCodeBench, SWE-EVO), compared with a reminder-only control and a no-message baseline.
Complexity feedback works. Complexity plus coverage feedback lowers erosion for all four models on Commit0 and SlopCodeBench, with no detectable effect on held-out correctness. Agents re-edit 54 to 94% of flagged functions, against 1 to 18% under the reminder.
Coverage alone does not. Coverage feedback by itself does not lower erosion, and on SlopCodeBench it raises it for three of the four models.
Abstract
Coding agents now write whole codebases in long autonomous runs, guided mainly by whether their tests pass. Yet passing tests alone does not reveal accumulating complexity or gaps in test coverage, which then persist as agents extend their own code. We introduce metrics-in-the-loop, an inference-time intervention that gives agents in-flight feedback: cheap, automatically computed code metrics injected into the agent's context during the trajectory. After each code-changing agent turn, we insert short feedback messages naming changed functions whose cyclomatic complexity exceeds a limit (complexity feedback) or changed lines that are skipped by tests (coverage feedback), giving the agent the opportunity to refactor code or strengthen tests before continuing. We run extensive experiments and ablations comparing several interventions across three long-horizon coding benchmarks and four strong models. We find that complexity feedback significantly reduces erosion, a measure of complexity concentration of code, without affecting held-out correctness of the code. Broadly, our experiments investigate a practical form of agent "re-railing", where timely, actionable measurements redirect agents before weaknesses become the foundation they keep building on. As agents scale to codebases with millions of lines, such interventions become critical to sustaining effective development and long-term code maintainability.