arXivDaily arXiv每日学术速递 周一至周五更新
arXiv 2610.33343cs.SE
收藏

从表面到结构:关于指标引导的智能体重构的配对实验

From Cosmetic to Structural: A Paired Experiment on Metric-Guided Agentic Refactoring

Lund University(隆德大学);CodeScene

Nadim Hagatulah, Markus Borg, Emma Söderberg

AI总结:

本研究通过配对实验发现,指标引导可使智能体重构从表面编辑转向结构性操作,提升有效重构率21-26个百分点,但会增加token成本与交互轮次。

摘要:

编码智能体的作用正从编写新代码扩展为作为AI队友维护现有系统。然而近期研究显示,智能体重构更倾向于表面的、面向一致性的编辑,而非解决技术债务(TD)所需的结构性转换。我们研究明确的静态分析反馈是否能缩小这一差距。通过CodeScene MCP服务器,我们为开源智能体(gptme)提供代码异味报告和CodeHealth(CH)评分(1-10分,分值越高越好),并在一项配对实验中对比有引导与无引导的重构,该实验涵盖24620个C++、Java和Python的单文件竞赛编程解决方案。我们发现,引导使智能体从执行表面编辑转向结构性操作,将有效重构率提高了21至26个百分点。该收益取决于初始代码质量,存在语言相关的盈亏平衡点,对应CH值为4.9至7.1,低于此值时,引导推动的结构性转换日益增加回归风险,表明智能体在这些区域需要更多重构支持。有引导的运行还使失败类型转向逻辑测试失败,引入新的耦合异味,且消耗约3至5倍的token,交互轮次约为2倍。我们的结果表明,AI队友可从人类开发者已使用的类似静态分析反馈中受益,实现更有效TD修复所需的结构性转换,但代价是更高的token成本和更多交互轮次。

英文摘要:

The role of coding agents is expanding beyond writing new code toward maintaining existing systems as AI teammates. Yet recent studies show that agent refactorings favor superficial, consistency-oriented edits over structural transformations needed to resolve Technical Debt (TD). We investigate if explicit static-analysis feedback closes this gap. Through the CodeScene MCP server, we give an open-source agent (gptme) access to code smell reports and CodeHealth (CH) scores (1--10, higher is better), and compare guided against unguided refactorings in a paired experiment covering $24{,}620$ single-file competitive programming solutions in C++, Java, and Python. We find that guidance shifts the agent from performing cosmetic edits toward structural operations, raising the rate of effective refactorings by $21$--$26$ percentage points. The benefit depends on initial code quality, with language-dependent break-even points at CH $4.9$--$7.1$, below where the structural transformations pushed by guidance increasingly risk regression, indicating where the agent needs more support to refactor. Guided runs also shift the failure profile toward logical test failures, introduce new coupling smells, and consume $\sim$$3$--$5\times$ more tokens over $\sim$$2\times$ as many interaction turns. Our results indicate that AI teammates can benefit from similar static-analysis feedback that human developers already use, enabling structural transformations toward more effective TD remediation, at a higher token cost and more interaction turns.

机构、总结、中文摘要均由AI分析而来,可能存在错误,请以论文正文为准。

↑