通过最小化智能体轨迹减少生成代码冗余,提升代码简洁性。
TRIM: Reducing AI-Generated CodeSlop via Agent Trajectory Minimization

- 基于智能体搜索路径建模,间接消除冗余代码
- 在多种场景下减少17.9%-32.9%的冗余代码
- 效率高,验证成本仅为基线算法一半
编码智能体在修复漏洞、构建应用和原型开发等任务中日益普及。然而,其生成的代码往往比人类编写的更长且冗余。我们发现,问题根源在于智能体的搜索过程:在迭代逼近正确解时,会积累临时修改、被放弃的假设并保留在最终补丁中。虽然单个补丁影响有限,但当智能体负责更大代码库时,冗余持续累积,导致维护困难。为此,我们首次提出「CodeSlop」概念,指代生成代码中残留的、功能无关的修改。提出算法TRIM(Trajectory-guided Redundancy Identification and Minimization),通过最小化智能体轨迹而非直接清除冗余,实现高效净化。实验表明,TRIM在多个智能体框架下减少17.9%-32.9%的CodeSlop,性能几乎无损失,且验证成本仅为基线方法(如Delta Debugging)的一半。
原文摘要 · Abstract (English)
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.
Thank you to arXiv for use of its open access interoperability. PaperDance 不是 arXiv 官方产品;中文卡片由大模型生成,请以原文为准。