arXiv:2608.23611cs.SEcs.AI2026-08

用多智能体协作自动重构代码,有效减少68%以上代码异味。

REFINE: A Multi-Agent LLM Approach for Evidence-Guided Code Refactoring

论文配图:REFINE: A Multi-Agent LLM Approach for Evidence-Guided Code Refactoring
图 1 · 摘自论文原文
  • 多智能体协同分析代码异味并生成重构建议
  • 在15个开源项目中降低68%-73%的代码异味
  • 适合需要高质量代码重构的开发团队使用

大型语言模型为自动化代码重构带来新可能。然而,生成的修改必须在不引入新问题或改变行为相关结构的前提下解决特定质量问题。我们提出REFINE(面向智能体执行的证据感知重构流程),一种工具无关、证据感知的多智能体方法,用于生成Java文件级别的重构候选。REFINE结合静态分析引导的异味识别、基于异味的规划、基于LLM的转换、自动化再分析、保持性检查和结构化报告。我们在15个开源系统中的450个Java文件上评估REFINE,使用OpenAI GPT-5.5、Google Gemini 3.1 Pro Preview和Anthropic Claude Opus 4.8生成1,350次模型通过输出。三种配置下,代码异味分别减少68.26%、72.79%和68.49%,重大异味改善最为显著。与直接提示基线相比,REFINE实现更高中位数的异味减少,且修改更小、公共方法移除更少。但整体质量提升不稳定,保持性检查揭示残余风险,包括assert/fail调用变更和公共方法移除。因此,REFINE输出应视为需编译、测试、依赖分析和人工审查的重构候选,方可应用于仓库或系统级场景。

原文摘要 · Abstract (English)

Large Language Models (LLMs) offer new opportunities for automated code refactoring. However, generated changes must reduce targeted quality problems without introducing new issues or altering behaviour-relevant code structures. We introduce REFINE (Refactoring with Evidence-aware Flow for Integrated ageNtic Execution), a tool-agnostic, evidence-aware multi-agent approach for generating Java file-level refactoring candidates. REFINE combines static-analysis-guided smell identification, smell-informed planning, LLM-based transformation, automated re-analysis, preservation checks, and structured reporting. We evaluate REFINE on 450 Java files from 15 open-source systems, producing 1,350 model-pass outputs using OpenAI GPT-5.5, Google Gemini 3.1 Pro Preview, and Anthropic Claude Opus 4.8. REFINE reduces detected code smells by 68.26%, 72.79%, and 68.49% across the three configurations, respectively, with the strongest reductions observed for major smells. A matched 150-file direct-prompt baseline shows that REFINE achieves a higher median code-smell reduction with smaller edits and fewer public-method removals. However, broader quality improvements are inconsistent, and preservation checks reveal residual risks, including assert/fail-call changes and public-method removal. Therefore, REFINE outputs should be treated as refactoring candidates requiring compilation, testing, dependency analysis, and human review before adoption in repository- or system-level settings.

代码重构多智能体LLM应用

Thank you to arXiv for use of its open access interoperability. PaperDance 不是 arXiv 官方产品;中文卡片由大模型生成,请以原文为准。