用多个AI代理自动重构代码,提升质量和成功率。
RefAgent: A Multi-agent LLM-based Framework for Automatic Software Refactoring
- 设计多代理系统,分工规划、执行、测试与自我优化。
- 重构后测试通过率中位数达90%,代码异味减少52.5%。
- 适合需要自动化代码优化的开发团队和持续集成场景。
大型语言模型(LLMs)已显著影响软件工程任务。在代码重构方面,传统LLMs虽能缩短开发时间并提升代码质量,但依赖静态指令。相比之下,基于LLM的代理可动态适应上下文,自主决策并调用工具执行流程。本文提出RefAgent,一种端到端的多代理重构框架,包含负责规划、执行、测试与迭代优化的专用代理,具备自省与工具调用能力。我们在8个开源Java项目上评估其表现,对比单代理方法、搜索型重构工具及历史开发者重构。评估指标包括:重构对软件质量的影响、识别重构机会的能力,以及各代理贡献的消融研究。结果表明,RefAgent实现中位数90%的单元测试通过率,代码异味减少52.5%,关键质量属性(如可重用性)提升8.6%。其重构机会识别的中位F1分数达79.15%(接近开发者),优于单代理方案,测试通过率提升64.7%,编译成功率提升40.1%。这些成果凸显多代理架构在自动化重构中的潜力。
原文摘要 · Abstract (English)
Large Language Models (LLMs) have substantially influenced various software engineering tasks. Indeed, in the case of software refactoring, traditional LLMs have shown the ability to reduce development time and enhance code quality. However, these LLMs often rely on static, detailed instructions for specific tasks. In contrast, LLM-based agents can dynamically adapt to evolving contexts and autonomously make decisions by interacting with software tools and executing workflows. In this paper, we explore the potential of LLM-based agents in supporting refactoring activities. Specifically, we introduce RefAgent, a multi-agent LLM-based framework for end-to-end software refactoring. RefAgent consists of specialized agents responsible for planning, executing, testing, and iteratively refining refactorings using self-reflection and tool-calling capabilities. We evaluate RefAgent on eight open-source Java projects, comparing its effectiveness against a single-agent approach, a search-based refactoring tool, and historical developer refactorings. Our assessment focuses on: (1) the impact of generated refactorings on software quality, (2) the ability to identify refactoring opportunities, and (3) the contribution of each LLM agent through an ablation study. Our results show that RefAgent achieves a median unit test pass rate of 90%, reduces code smells by a median of 52.5%, and improves key quality attributes (e.g., reusability) by a median of 8.6%. Additionally, it closely aligns with developer refactorings and the search-based tool in identifying refactoring opportunities, attaining a median F1-score of 79.15% and 72.7%, respectively. Compared to single-agent approaches, RefAgent improves the median unit test pass rate by 64.7% and the median compilation success rate by 40.1%. These findings highlight the promise of multi-agent architectures in advancing automated software refactoring.
Thank you to arXiv for use of its open access interoperability. PaperDance 不是 arXiv 官方产品;中文卡片由大模型生成,请以原文为准。