SpecRover: Code Intent Extraction via LLMs
作者: Haifeng Ruan, Yuntong Zhang, Abhik Roychoudhury
分类: cs.SE, cs.AI
发布日期: 2024-08-05 (更新: 2024-12-11)
备注: Haifeng Ruan and Yuntong Zhang contributed equally to this work. To appear in ICSE 2025
💡 一句话要点
SpecRover:利用LLM进行代码意图提取,提升自动程序改进效果
🎯 匹配领域: 支柱九:具身大模型 (Embodied Foundation Models)
关键词: 代码意图提取 大型语言模型 自动程序修复 规约推断 代码搜索
📋 核心要点
- 自动程序改进依赖于对程序意图的准确理解,而现有方法在复杂场景下难以有效推断代码意图。
- SpecRover通过迭代的代码搜索和规约推断,从项目结构和行为中学习代码意图,从而生成高质量的程序补丁。
- 实验表明,SpecRover在SWE-Bench上显著优于现有方法AutoCodeRover,并在成本可控的情况下提高了问题解决的有效性。
📝 摘要(中文)
本文提出了一种名为SpecRover(AutoCodeRover-v2)的方法,用于在LLM Agent中进行迭代式的规约推断,以实现自动程序改进,例如自动修复bug和添加新功能。该方法通过结合代码搜索和规约推断,从项目结构和行为中推断代码意图。SpecRover使用审查Agent来评估补丁,并提供对补丁的置信度度量。在包含2294个GitHub issue的SWE-Bench上的评估表明,SpecRover的有效性比AutoCodeRover提高了50%以上,并且在解决SWE-Bench lite中的平均GitHub issue时,成本适中(每个issue 0.65美元)。SpecRover生成的解释能够为开发者提供更好的“信号”,以便更有信心地接受建议的补丁。该研究表明,即使在LLM时代,规约推断在自动程序修复中仍然具有重要意义。
🔬 方法详解
问题定义:论文旨在解决自动程序改进中,如何更有效地从代码中提取意图的问题。现有方法,特别是依赖大型语言模型(LLM)的自动程序修复技术,在缺乏明确规约的情况下,难以生成高质量的补丁。现有的痛点在于,如何低成本、高效地进行规约推断,从而提升自动程序修复的准确性和可靠性。
核心思路:SpecRover的核心思路是结合代码搜索和规约推断,通过迭代的方式从项目结构和行为中学习代码意图。它利用LLM Agent进行代码搜索,并根据搜索结果推断代码的预期行为。这种迭代过程允许Agent逐步完善对代码意图的理解,从而生成更准确的补丁。
技术框架:SpecRover建立在开源LLM Agent AutoCodeRover之上,其整体框架包含以下几个主要阶段:1) 问题分析:分析GitHub issue,确定需要解决的问题;2) 代码搜索:利用LLM Agent在代码库中搜索相关代码;3) 规约推断:根据搜索到的代码和项目上下文,推断代码的预期行为;4) 补丁生成:基于推断的规约,生成修复问题的补丁;5) 补丁评估:使用审查Agent评估补丁的质量和置信度。
关键创新:SpecRover的关键创新在于其迭代式的规约推断方法。与传统的单次规约推断相比,SpecRover通过多次迭代的代码搜索和规约推断,能够更准确地捕捉代码意图。此外,SpecRover还引入了审查Agent,用于评估补丁的质量和置信度,从而提高了自动程序修复的可靠性。
关键设计:SpecRover的关键设计包括:1) 使用LLM进行代码搜索,利用其强大的代码理解能力;2) 设计迭代式的规约推断流程,逐步完善对代码意图的理解;3) 引入审查Agent,对生成的补丁进行评估和验证。具体的参数设置和损失函数等技术细节在论文中未详细说明,属于未知信息。
🖼️ 关键图片
📊 实验亮点
SpecRover在SWE-Bench数据集上进行了评估,结果表明其有效性比AutoCodeRover提高了50%以上。此外,SpecRover在解决SWE-Bench lite中的平均GitHub issue时,成本适中,每个issue仅需0.65美元。这些结果表明,SpecRover在自动程序改进方面具有显著的优势。
🎯 应用场景
SpecRover可应用于软件开发的多个领域,例如自动bug修复、代码自动补全、代码理解和文档生成等。通过自动推断代码意图,SpecRover可以帮助开发者更高效地理解和维护代码,减少人工干预,提高软件开发的效率和质量。未来,该技术有望在自动化软件工程中发挥更大的作用。
📄 摘要(原文)
Autonomous program improvement typically involves automatically producing bug fixes and feature additions. Such program improvement can be accomplished by a combination of large language model (LLM) and program analysis capabilities, in the form of an LLM agent. Since program repair or program improvement typically requires a specification of intended behavior - specification inference can be useful for producing high quality program patches. In this work, we examine efficient and low-cost workflows for iterative specification inference within an LLM agent. Given a GitHub issue to be resolved in a software project, our goal is to conduct iterative code search accompanied by specification inference - thereby inferring intent from both the project structure and behavior. The intent thus captured is examined by a reviewer agent with the goal of vetting the patches as well as providing a measure of confidence in the vetted patches. Our approach SpecRover (AutoCodeRover-v2) is built on the open-source LLM agent AutoCodeRover. In an evaluation on the full SWE-Bench consisting of 2294 GitHub issues, it shows more than 50% improvement in efficacy over AutoCodeRover. Compared to the open-source agents available, our work shows modest cost ($0.65 per issue) in resolving an average GitHub issue in SWE-Bench lite. The production of explanation by SpecRover allows for a better "signal" to be given to the developer, on when the suggested patches can be accepted with confidence. SpecRover also seeks to demonstrate the continued importance of specification inference in automated program repair, even as program repair technologies enter the LLM era.