TRIM:通过Agent轨迹最小化减少AI生成的CodeSlop

TRIM: Reducing AI-Generated CodeSlop via Agent Trajectory Minimization

精选理由

这篇论文发现AI助手写代码越来越啰嗦,还给出了一个叫TRIM的清理方法,能减少17%到33%的冗余,实测效率高,推荐给写代码的朋友。

AI 摘要

论文定义了CodeSlop现象,即AI编码代理在搜索过程中残留的冗余编辑。提出TRIM算法,通过最小化代理轨迹来间接减少CodeSlop。实验在多种代理框架上测试,CodeSlop降低17.9%-32.9%,性能几乎无损失。验证成本仅为Delta Debugging算法的约一半。

原文 · arXiv cs.AI

TRIM: Reducing AI-Generated CodeSlop via Agent Trajectory Minimization

Coding agents are increasingly used to accelerate code generation in many downstream tasks, such as fixing bugs, building applications, and prototyping. However, despite their value as coding assistants, agent-generated code tends to be larger and more verbose than the corresponding human-written implementation. In this work, we show that the cause lies in the agent's own search process: while iterating toward a passing solution, an agent accumulates speculative edits, abandoned hypotheses, and temporary changes that persist into the final patch. This may seem harmless for a single patch, but the problem compounds as agents take responsibility for ever-larger portions of a codebase-a codebase that was once minimal and well-maintained slowly accumulates redundancy faster than it can be cleaned up, drifting to a state that is harder to maintain. Given the magnitude of this problem, we take a step towards alleviating this issue. First, we formally define this phenomenon as CodeSlop-the residual and functionally unnecessary edits commonly seen in AI-generated code. We then introduce our algorithm TRIM (Trajectory-guided Redundancy Identification and Minimization). Rather than minimizing CodeSlop directly, TRIM instead minimizes agent trajectories. As we show empirically, this indirect technique of minimizing CodeSlop is highly effective: TRIM cuts CodeSlop by 17.9%-32.9% across agentic scaffolds, with negligible performance regression. TRIM is also highly efficient, requiring roughly half the validation cost of algorithmic baselines such as Delta Debugging.