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

智能体重构:AI 编码智能体的实证研究

Agentic Refactoring: An Empirical Study of AI Coding Agents

Nara Institute of Science and Technology(奈良先端科学技术大学院大学);Queen's University(女王大学)

Kosei Horikawa, Hao Li, Yutaro Kashiwa, Bram Adams, Hajimu Iida, Ahmed E. Hassan

AI总结:

本文基于 AIDev 数据集对真实 Java 项目中 AI 智能体生成的重构进行大规模实证研究,揭示了智能体重构以低层次一致性编辑为主、主要关注可维护性与可读性,并能带来小幅但显著的结构质量改进。

摘要:

智能体编码工具,如 OpenAI Codex、Claude Code 和 Cursor,正在改变软件工程的面貌。这些由 AI 驱动的系统能够作为自主队友,规划和执行复杂的开发任务。智能体已成为重构活动的积极参与者,而重构是可持续软件开发的基石,旨在不改变可观察行为的前提下改善内部代码质量。尽管其采用率日益提高,但关于智能体重构在实践中如何被使用、与人类驱动的重构相比如何、以及对代码质量有何影响,目前仍严重缺乏实证理解。为填补这一实证空白,我们对真实世界开源 Java 项目中由 AI 智能体生成的重构进行了大规模研究,分析了来自 AIDev 数据集的 12,256 个拉取请求和 14,988 次提交中的 15,451 个重构实例。我们的实证分析表明,在这种开发范式中,重构是一种常见且有意识的活动,智能体在 26.1% 的提交中明确以重构为目标。对重构类型的分析显示,智能体的工作以低层次、面向一致性的编辑为主,例如更改变量类型(11.8%)、重命名参数(10.4%)和重命名变量(8.5%),反映出其偏好局部改进,而非人类重构中常见的高层次设计变更。此外,智能体重构的动机绝大多数集中在内部质量问题,其中可维护性(52.5%)和可读性(28.1%)占据主导。进一步地,对代码质量指标的定量评估表明,智能体重构在结构指标上带来了虽小但具有统计学显著性的改进,尤其是在中等程度的变更中,降低了类的大小和复杂度(例如,类 LOC 中位数 $Δ$ = -15.25)。

英文摘要:

Agentic coding tools, such as OpenAI Codex, Claude Code, and Cursor, are changing how software is developed. These AI-powered systems function as autonomous teammates capable of planning and executing complex development tasks. Agents have become active participants in refactoring, a key practice for improving internal code quality without altering observable behavior. Despite their increasing adoption, there is little empirical understanding of how agentic refactoring is used in practice, how it compares to human-driven refactoring, and what impact it has on code quality. To address this gap, we present a large-scale study of AI agent-generated refactorings in real-world open-source Java projects, analyzing 51,412 refactoring instances across 12,256 pull requests and 14,998 commits based on the AIDev dataset. We find that refactoring is a common and intentional activity, with agents explicitly targeting refactoring in 26.1% of commits. The subsequent analyses of refactoring types, purposes, and code quality focus on the 3,907 commits (32,611 instances) with explicit refactoring intent. High-level refactorings form the largest category overall; however, agentic refactoring contains a slightly larger share of low-level, consistency-oriented edits than human refactoring (27.6% vs. 24.4%), and its two most frequent operations are Rename Variable (7.6%) and Change Variable Type (6.8%). Additionally, the stated motivations behind agentic refactoring focus overwhelmingly on internal quality concerns (52.5% maintainability and 28.1% readability), although the measured metric improvements from these frequent low-level refactorings remain limited. Finally, code quality metrics show that agentic refactoring yields small but statistically significant improvements in structural metrics, particularly for medium-level changes, reducing class size and complexity.

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

↑