SAFEdit: Does Multi-Agent Decomposition Resolve the Reliability Challenges of Instructed Code Editing?
作者: Noam Tarshish, Nofar Selouk, Daniel Hodisan, Bar Ezra Gafniel, Yuval Elovici, Asaf Shabtai, Eliya Nachmani
分类: cs.SE, cs.AI
发布日期: 2026-04-28
备注: Accepted to the EQUISA (Evaluation of Qualitative Aspects of Intelligent Software Assistants) workshop at EASE (Evaluation and Assessment in Software Engineering) 2026
💡 一句话要点
SAFEdit:多智能体分解框架提升指令驱动代码编辑的可靠性
🎯 匹配领域: 支柱九:具身大模型 (Embodied Foundation Models)
关键词: 代码编辑 多智能体系统 大型语言模型 指令驱动 自动化软件工程
📋 核心要点
- 现有大型语言模型在指令驱动的代码编辑任务中表现不佳,难以保证编辑的可靠性和准确性。
- SAFEdit通过引入多智能体框架,将代码编辑任务分解为规划、编辑和验证等专门角色,提升编辑质量。
- 实验结果表明,SAFEdit在EditBench基准测试中显著优于单智能体方法,验证了其有效性。
📝 摘要(中文)
指令驱动的代码编辑对于大型语言模型(LLMs)来说是一个重要的挑战。在EditBench基准测试中,40个评估模型中有39个的任务成功率(TSR)低于60%,突出了通用代码生成与在可执行测试约束下执行指令驱动编辑的能力之间的差距。为了解决这个问题,我们提出了SAFEdit,一个用于指令驱动代码编辑的多智能体框架,它将编辑过程分解为专门的角色,以提高可靠性并减少意外的代码更改。一个规划器智能体产生一个显式的、可见性感知的编辑计划,一个编辑器智能体应用最小的、字面上的代码修改,一个验证器智能体执行真实的测试运行。当测试失败时,SAFEdit使用一个失败抽象层(FAL)将原始测试日志转换为结构化的诊断反馈,反馈给编辑器以支持迭代改进。我们将SAFEdit与EditBench上报告的先前单模型结果以及在相同评估条件下实现的ReAct单智能体基线进行比较。我们使用EditBench在五种语言(英语、波兰语、西班牙语、中文和俄语)的445个代码编辑实例上,在不同的空间上下文变体下评估了SAFEdit。SAFEdit实现了68.6%的TSR,优于单模型基线3.8个百分点,优于ReAct单智能体基线8.6个百分点。迭代改进循环对SAFEdit的总体成功率贡献了17.4个百分点。SAFEdit的自动错误分析进一步表明,与单智能体方法相比,指令级别的幻觉有所减少,为解释通过或失败结果之外的失败提供了一个额外的框架组件。
🔬 方法详解
问题定义:论文旨在解决大型语言模型在指令驱动代码编辑任务中可靠性不足的问题。现有方法,特别是单智能体方法,难以在保证代码功能正确性的前提下,准确地根据指令修改代码,容易引入错误或产生意外的代码更改。
核心思路:论文的核心思路是将复杂的代码编辑任务分解为多个由不同智能体负责的子任务,每个智能体专注于特定的角色,从而提高整体的可靠性和效率。通过显式的编辑计划和迭代改进机制,减少了指令理解偏差和代码修改错误。
技术框架:SAFEdit框架包含三个主要智能体:Planner Agent(规划器智能体)、Editor Agent(编辑器智能体)和 Verifier Agent(验证器智能体)。Planner Agent负责生成编辑计划,Editor Agent负责根据计划进行代码修改,Verifier Agent负责执行测试并验证修改的正确性。此外,Failure Abstraction Layer (FAL) 用于将测试日志转换为结构化反馈,供 Editor Agent 进行迭代改进。整个流程是一个迭代循环,直到代码通过所有测试。
关键创新:SAFEdit的关键创新在于多智能体分解和迭代改进机制。多智能体分解允许每个智能体专注于特定的任务,减少了单个智能体的认知负担。迭代改进机制通过 Failure Abstraction Layer (FAL) 提供的结构化反馈,使 Editor Agent 能够逐步改进代码,提高成功率。与单智能体方法相比,SAFEdit 减少了指令级别的幻觉。
关键设计:Planner Agent 的设计需要考虑代码的可见性,确保生成的编辑计划是可行的。Editor Agent 的设计强调最小化修改,避免引入不必要的更改。Verifier Agent 使用真实的测试运行来验证代码的正确性。Failure Abstraction Layer (FAL) 的设计至关重要,它需要将复杂的测试日志转换为 Editor Agent 可以理解的结构化反馈。
🖼️ 关键图片
📊 实验亮点
SAFEdit在EditBench基准测试中取得了显著的性能提升,任务成功率(TSR)达到68.6%,优于单模型基线3.8个百分点,优于ReAct单智能体基线8.6个百分点。迭代改进循环对SAFEdit的总体成功率贡献了17.4个百分点。自动错误分析表明,SAFEdit减少了指令级别的幻觉。
🎯 应用场景
SAFEdit框架可应用于自动化代码修复、代码重构、代码迁移等领域。该研究成果有助于提高软件开发的效率和质量,降低维护成本。未来,可以将SAFEdit扩展到更复杂的代码编辑任务,并与其他自动化软件工程工具集成,实现更智能化的软件开发流程。
📄 摘要(原文)
Instructed code editing is a significant challenge for large language models (LLMs). On the EditBench benchmark, 39 of 40 evaluated models obtain a task success rate (TSR) below 60 percent, highlighting a gap between general code generation and the ability to perform instruction-driven editing under executable test constraints. To address this, we propose SAFEdit, a multi-agent framework for instructed code editing that decomposes the editing process into specialized roles to improve reliability and reduce unintended code changes. A Planner Agent produces an explicit, visibility-aware edit plan, an Editor Agent applies minimal, literal code modifications, and a Verifier Agent executes real test runs. When tests fail, SAFEdit uses a Failure Abstraction Layer (FAL) to transform raw test logs into structured diagnostic feedback, which is fed back to the Editor to support iterative refinement. We compare SAFEdit against both prior single-model results reported for EditBench and an implemented ReAct single-agent baseline under the same evaluation conditions. We used EditBench to evaluate SAFEdit on 445 code editing instances in five languages (English, Polish, Spanish, Chinese, and Russian) under varying spatial context variants. SAFEdit achieved 68.6 percent TSR, outperforming the single-model baseline by 3.8 percentage points and the ReAct single-agent baseline by 8.6 percentage points. The iterative refinement loop was found to contribute 17.4 percentage points to SAFEdit's overall success rate. SAFEdit's automated error analysis further indicates a reduction in instruction-level hallucinations compared to single-agent approaches, providing an additional framework component for interpreting failures beyond pass or fail outcomes.