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.
An Empirical Study on the Potential of LLMs in Automated Software Refactoring
Beijing Institute of Technology(北京理工大学);Peking University(北京大学);University of Cincinnati(辛辛那提大学);National Innovation Institute of Defense Technology(国防科技大学创新研究院)
Humanizing Automatically Generated Unit Test Suites with LLM-Based Refactoring
University of Luxembourg(卢森堡大学);Nanjing University of Science and Technology(南京理工大学);Zhejiang University(浙江大学);Bilkent University(比尔肯特大学);Singapore Management University(新加坡管理大学)
Leveraging LLMs, IDEs, and Semantic Embeddings for Automated Move Method Refactoring
University of Colorado(科罗拉多大学);Tulane University(路易斯安那州立大学);Amazon Web Services(亚马逊网络服务);JetBrains Research(JetBrains研究);NEC Corporation(日本电报电话公司);NEC Laboratories America(日本电报电话美洲实验室);University of Texas at Dallas(德克萨斯大学达拉斯分校);Concordia University(康科迪亚大学);University of Colorado, JetBrains Research(科罗拉多大学,JetBrains研究)
Laboratorio de Investigación y Formación en Informática Avanzada (LIFIA)(先进信息与计算研究培训中心);Facultad de Informática - Universidad Nacional de La Plata(拉普拉塔国立大学信息学院);Comisión de Investiación Científica - CIC Bs.As.(布宜诺斯艾利斯省科学研究委员会)