[论文解读] RepairAgent: An Autonomous, LLM-Based Agent for Program Repair
RepairAgent 是首个基于大型语言模型的自治代理,用于程序修复,它使用动态提示、 repairTools 集以及一个引导的有限状态机来修复错误,在 Defects4J 上实现了 164 次正确修复(其中 39 次是之前工作未能修复的),每个缺陷约 0.14 美元。
Automated program repair has emerged as a powerful technique to mitigate the impact of software bugs on system reliability and user experience. This paper introduces RepairAgent, the first work to address the program repair challenge through an autonomous agent based on a large language model (LLM). Unlike existing deep learning-based approaches, which prompt a model with a fixed prompt or in a fixed feedback loop, our work treats the LLM as an agent capable of autonomously planning and executing actions to fix bugs by invoking suitable tools. RepairAgent freely interleaves gathering information about the bug, gathering repair ingredients, and validating fixes, while deciding which tools to invoke based on the gathered information and feedback from previous fix attempts. Key contributions that enable RepairAgent include a set of tools that are useful for program repair, a dynamically updated prompt format that allows the LLM to interact with these tools, and a finite state machine that guides the agent in invoking the tools. Our evaluation on the popular Defects4J dataset demonstrates RepairAgent's effectiveness in autonomously repairing 164 bugs, including 39 bugs not fixed by prior techniques. Interacting with the LLM imposes an average cost of 270,000 tokens per bug, which, under the current pricing of OpenAI's GPT-3.5 model, translates to 14 cents of USD per bug. To the best of our knowledge, this work is the first to present an autonomous, LLM-based agent for program repair, paving the way for future agent-based techniques in software engineering.
研究动机与目标
- 推动自动化程序修复(APR)以及对自治、决策型代理的需求,超越固定提示的 LLM 循环。
- 将 RepairAgent 作为一个自治、具工具能力的 LLM 引入,能够规划、执行并验证错误修复。
- 在 Defects4J 上展示有效性,包括先前方法未达到的修复,并分析资源成本。
提出的方法
- 定义一个自治的 LLM 代理,能够通过一组修复工具规划和执行修复行动。
- 引入一个动态更新的提示格式,引导代理进行错误理解、信息收集和补丁验证。
- 使用有限状态机来约束工具使用并引导修复过程。
- 提供中间件来解析并映射 LLM 输出到工具调用,并包含错误处理启发式。
- 使用 14 个工具(读取/提取代码、搜索/生成代码、测试/打补丁、以及控制)来模拟人类修复工作流。
- 在 Defects4J 数据集上运行修复,并与三个基线(ChatRepair、ITER、SelfAPR)比较。)

实验结果
研究问题
- RQ1RQ1 RepairAgent 在修复真实世界的缺陷上有多有效?
- RQ2RQ2 该方法的成本是多少?
- RQ3RQ3 LLM 代理如何使用可用工具?
主要发现
- RepairAgent 在 Defects4J 中修复了 164 个缺陷,其中 39 个是前期工作未修复的。
- RepairAgent 在 v1.2(74 正确)和 v2.0(90 正确)两版本中均实现修复,共有 186 个可能修复。
- 交互的平均 token 成本约为每个缺陷 270,000 tokens(在 GPT-3.5 定价下约 $0.14)。
- RepairAgent 展现了对单行、多行和多文件缺陷的能力(115 个单行,46 个多行,3 个多文件)。
- 与 ChatRepair、ITER、SelfAPR 相比,RepairAgent 修复的总缺陷数相当,并在 Defects4Jv2 上表现出色,修复 90 个缺陷,而其他方法修复较少。
- 该方法产生若干专属修复,依赖于工具集(例如 find_similar_api_calls、generate_method_body)。

更好的研究,从现在开始
从论文设计到论文写作,大幅缩短您的研究时间。
无需绑定信用卡
本解读由 AI 生成,并经人工编辑审核。