mlsanityData to 14 Oct 2026

MANTRA: Enhancing Automated Method-Level Refactoring with Contextual RAG and Multi-Agent LLM Collaboration

arXiv 2503.14340 ↗First posted 18 Mar 2025cs.SEcited by 10

On the map: LLM agents and tool use → Software engineering coding agents

Abstract (arXiv)

Maintaining and scaling software systems relies heavily on effective code refactoring, yet this process remains labor-intensive, requiring developers to carefully analyze existing codebases and prevent the introduction of new defects. Although recent advancements have leveraged Large Language Models (LLMs) to automate refactoring tasks, current solutions are constrained in scope and lack mechanisms to guarantee code compilability and successful test execution. In this work, we introduce MANTRA, a comprehensive LLM agent-based framework that automates method-level refactoring. MANTRA integrates Context-Aware Retrieval-Augmented Generation, coordinated Multi-Agent Collaboration, and Verbal Reinforcement Learning to emulate human decision-making during refactoring while preserving code correctness and readability. Our empirical study, conducted on 703 instances of "pure refactorings" (i.e., code changes exclusively involving structural improvements), drawn from 10 representative Java projects, covers the six most prevalent refactoring operations. Experimental results demonstrate that MANTRA substantially surpasses a baseline LLM model (RawGPT ), achieving an 82.8% success rate (582/703) in producing code that compiles and passes all tests, compared to just 8.7% (61/703) with RawGPT. Moreover, in comparison to IntelliJ's LLM-powered refactoring tool (EM-Assist), MANTRA exhibits a 50% improvement in generating Extract Method transformations. A usability study involving 37 professional developers further shows that refactorings performed by MANTRA are perceived to be as readable and reusable as human-written code, and in certain cases, even more favorable. These results highlight the practical advantages of MANTRA and emphasize the growing potential of LLM-based systems in advancing the automation of software refactoring tasks.

Key facts. Cited by 10 papers in the map (data through 14 Oct 2026). Placed in Software engineering coding agents, one of 16 directions in LLM agents and tool use. Builds on 18 of its 67 references that are in the map. First posted on arXiv 18 Mar 2025.

Builds on

18 of 67 references.

Closest ancestors · 1

Same direction, newest first

  1. 2024SOEN-101: Code Generation by Emulating Software Process Models Using Large Language Model Agents23 Mar

Other references · 17

  1. 2022Chain-of-Thought Prompting Elicits Reasoning in Large Language Modelscited by 12,459
  2. 2019Sentence-BERT: Sentence Embeddings using Siamese BERT-Networkscited by 9,170
  3. 2023Reflexion: Language Agents with Verbal Reinforcement Learningcited by 4,276
  4. 2023Retrieval-Augmented Generation for Large Language Models: A Surveycited by 2,212
  5. 2023A Survey on Hallucination in Large Language Models: Principles, Taxonomy, Challenges, and Open Questionscited by 1,601
  6. 2020CodeBLEU: a Method for Automatic Evaluation of Code Synthesiscited by 479
  7. 2023ChatGPT Prompt Patterns for Improving Code Quality, Refactoring, Requirements Elicitation, and Software Designcited by 66
  8. 2023AI-assisted coding: Experiments with GPT-4cited by 43
  9. 2023Refactoring Programs Using Large Language Models with Few-Shot Examplescited by 28
  10. 2024How to Refactor this Code? An Exploratory Study on Developer-ChatGPT Refactoring Conversationscited by 12
  11. 2016Why We Refactor? Confessions of GitHub Contributorscited by 10
  12. 2025LLM4EFFI: Leveraging Large Language Models to Enhance Code Efficiency and Correctnesscited by 10
5 more
  1. 2024EM-Assist: Safe Automated ExtractMethod Refactoring with LLMscited by 8
  2. 2020On the Relationship between Refactoring Actions and Bugs: A Differentiated Replicationcited by 5
  3. 2024A Novel Refactoring and Semantic Aware Abstract Syntax Tree Differencing Tool and a Benchmark for Evaluating the Accuracy of Diff Toolscited by 2
  4. 2024Refactoring-aware Block Tracking in Commit Historycited by 2
  5. 2021One Thousand and One Stories: A Large-Scale Survey of Software Refactoringcited by 1

Built on by

Cited by year (2026 to 14 Oct)

Citing papers per year: 2025: 4; 2026: 6.

10 papers.

Similar, not cited

Close in wording, no citation either way

  1. 2025RefAgent: A Multi-agent LLM-based Framework for Automatic Software Refactoring
  2. 2026CodeTaste: Can LLMs Generate Human-Level Code Refactorings?
  3. 2026RefactorAssist: Agentic Refinement for Reliable Code Refactoring
  4. 2026REFINE: A Multi-Agent LLM Approach for Evidence-Guided Code Refactoring
  5. 2026"Refactoring Runaway": Understanding and Mitigating Tangled Refactorings in Coding Agents for Issue Resolution
  6. 2025Agentic Refactoring: An Empirical Study of AI Coding Agents
  7. 2025REFINE: Enhancing Program Repair Agents through Context-Aware Patch Refinement
  8. 2026SWE-Bench ProMax: Benchmarking Agents on Large-Scale Multilingual Code Refactoring