读见

编程智能体犯错后,怎样才能真正撤销自己的操作?

原题Your Coding Agent Can't Undo Its Own Mistakes - Tanmay Sah & Dolly Sah

约 8 分钟原文英文已翻译

视频由 YouTube 提供

看前速览

3 个要点

UndoBench 测量编程智能体何时无法恢复,EvoUndo 则要求先证明能恢复,才允许智能体修改自己的运行环境。

  1. 完成任务与恢复能力要分开测

    84% 的常规成功率和 47% 的条件恢复率分母不同。常规流程测试通过,仍需单独验证故障恢复。

  2. 先确认故障发生在哪个阶段

    状态尚未改变时,重试通常可行。如果操作已经提交,只是响应丢了,下一步可能是先查证状态,或者执行补偿。

  3. 允许自我修改前,要验证能否恢复

    EvoUndo 保存变更前的状态,在测试中执行恢复计划,再独立核对。实验中,扩充恢复操作后,197 项有恢复缺陷的变更里有 180 项能恢复。

完整摘要

Tanmay Sah 和 Dolly Sah 区分了两种能力:完成任务,以及发生故障后恢复原先的状态。UndoBench 做了 2,880 组配对试验。常规试验的成功率是 84%,而在原本能成功的试验中,注入故障后只有 47% 能正确恢复。创建工单后丢失响应的例子说明,直接重试可能带来重复的副作用。EvoUndo 会记录变更前的状态,在测试环境执行变更及恢复计划,并在准入前由独立验证器确认恢复结果。600 项自我改进任务中,有 478 项提升了能力,其中 197 项存在恢复缺陷。扩充恢复语言后,197 项里有 180 项得以恢复,允许的改进从 281 项增加到 461 项。作者还区分了安全重试、恢复原状、补偿已提交的外部操作,以及无法验证恢复时上报。

章节

文字稿

查看原文

简要描述Brief Description

你的编码智能体无法撤销自己的错误——Tanmay Sah 和 Dolly SahYour Coding Agent Can't Undo Its Own Mistakes - Tanmay Sah & Dolly Sah

目录Table of Contents

  • 内容
    Content
  • UndoBench 与失败阶段
    UndoBench and the failure phases
  • 状态见证数据与恢复工具链
    State witnesses and recovery tooling
  • EvoUndo 准入检查
    The EvoUndo admission check
  • 恢复、补偿或升级处理
    Recover, compensate, or escalate

内容Content

大家好,我是 Tanmay。今天我和 Dolly 一起,为大家介绍编程智能体缺少的“取消”按钮。Hello everyone. I am Tanmay. Today I'm with Dolly, and we're going to introduce the missing "cancel" button for programming agents.

那么,设想一个编程代理正在代码仓库中解决问题。他应用了补丁,运行了测试,一切都顺利通过了。它甚至创建了一个发布标签,但随后底层集成却失败了。So, imagine a programming agent working on a problem in a repository. He applies the patch, runs the tests, and everything passes successfully. It even creates a release tag, but then the lower-level integration fails.

现在问题来了:代理真的能将一切恢复到之前的状态吗?Git 可以告诉我们仓库中发生了哪些变化,但 Git 之外的变更呢?例如外部 API 调用、运行时配置或通知。况且,简单地重试某项操作,并不一定能撤销已经发生的事情。Now the question arises. Can the agent actually return everything to its previous state? Git can tell us what has changed in the repository, but what about changes outside of Git, such as external API calls, runtime configurations, or notifications? And simply retrying an operation doesn't necessarily undo what has already happened.

UndoBench 与故障阶段UndoBench and the failure phases

因此,我们想了解的不仅是智能体能否执行任务,还想知道出了问题时它们能否恢复。这就引出了我们的第一篇研究论文 UndoBench。我们想探究,智能体完成任务的能力是否也意味着它具备从失败中恢复的能力。我们对智能体进行了 2,880 组配对试验,将正常情况下的表现与人为制造故障时的表现进行比较。在正常情况下,智能体有 84% 的成功率;但引入故障后,原本能够成功完成任务的试验中,只有 47% 得到了妥善恢复。请注意,这两个百分比的分母不同。不过,即使智能体能够成功完成任务,恢复能力仍然是一个严峻的问题。So we wanted to understand not only whether agents could perform tasks, but also whether they could recover when something went wrong. This brings us to our first research paper, UndoBench. We wanted to investigate whether an agent's ability to complete a task also implies its ability to recover from failure. We evaluated agents on 2,880 paired trials, comparing normal performance with performance during an artificially created failure. So, under normal conditions, the agent succeeded 84% of the time, but when we introduced failures, only 47% of normally successful trials recovered properly. Note that these two percentages have different denominators, but yes, even when an agent can successfully complete a task, recovery remains a serious problem.

现在来看一种具体的故障场景。设想一个编程代理向外部系统发送请求,以创建一张工单。请求已经发送出去,代理正在等待响应。随后,服务器收到请求并成功创建了编号为 781 的工单,但确认信息在传回代理的途中丢失了。从代理的角度来看,请求超时了,但它并不知道工单已经创建。超时意味着没有收到响应,并不意味着操作失败。因此,代理没有确认第一次操作是否已完成,就重复发送了请求。结果,现在出现了两张工单,尽管代理原本只想创建一张。在 UndoBench 中,这类试验里,盲目重试有 54% 导致了重复操作。因此,我们需要区分响应失败和操作失败。Now let's look at a specific failure scenario. Imagine that a programming agent sends a request to an external system to create a ticket. The request has been sent and the agent is waiting for a response. Next, the server receives the request and successfully creates ticket number 781, but the confirmation is lost on the way to the agent. From the agent's perspective, the request timed out, but he doesn't know that the ticket has already been created. A timeout means that a response was not received, not that the operation failed. Therefore, the agent repeats the request without checking whether the first operation was completed. And now we have two tickets, even though the agent intended to create only one. So, in UndoBench, naive retries resulted in duplicate effects in 54% of such trials. This is why we need to distinguish between a failed response and a failed operation.

现在,故障发生阶段也会影响响应方式。我的意思是,恢复也取决于故障发生的时间。变更之前,重试通常是安全的,因为什么都没有改变。但在变更过程中,系统可能已经被部分修改,因此我们需要检查其状态。而在变更之后,即使确认消息丢失,操作也可能已经被记录。正如我们刚才看到的,重试可能会造成重复。因此,我们需要根据故障发生阶段采用不同的恢复策略。Now the failure phase also changes the response. I mean, recovery also depends on when the failure occurred. Before mutation, retrying is usually safe because nothing has changed. But during the mutation, the system could have been partially changed, so we need to check its state. And after the mutation, the operation could be recorded even if the confirmation was lost. As we just saw, retrying can create duplicates. So, we need different recovery strategies depending on the failure phase.

状态见证与恢复工具State witnesses and recovery tooling

那么,为什么我们不能直接使用 Git revert 呢?Git 可以撤销对代码库所做的更改,但编码智能体还会改变自身的执行状态,包括工具注册表、中间件和配置。它们还可能造成外部影响,例如部署或写入数据库。因此,Git revert 无法撤销所有这些更改。恢复机制应与智能体造成的影响类型相匹配。当编码智能体开始改变自身的执行环境,或者说我们所称的智能体“刚性”时,这一点就显得尤为重要。这包括提示词、工具、中间件、事件监听器、资源和路由配置。此类更改可以提升智能体的性能,但也可能让恢复变得更加困难。换句话说,智能体可能变得更有能力,但与此同时也更难恢复。这就是为什么撤销一项操作需要的不只是一个反向命令。Now, why can't we just use Git revert? Git can revert changes to the repository, but coding agents also change their execution state, including tool registries, middleware, and configurations. They can also cause external effects, such as deployment or database writes. Therefore, Git revert does not undo all these changes. The recovery mechanism should match the type of effect created by the agent. And this becomes especially important when coding agents start to change their own execution environment, or what we call the “rigidity” of the agent. This includes prompts, tools, middleware, event listeners, resources, and routing configurations. Such changes can improve agent performance, but they can also make recovery more difficult. In other words, an agent can become more capable, but at the same time less recoverable. And that's why undoing an action requires more than just a reverse command.

现在,撤销一项更改并不总是像执行反向命令那么简单。假设某个智能体将等待时间从 30 改为 60。要撤销这项更改,它需要知道原始值是 30。这就是 EvoUndo 在应用变更之前会捕获先前状态的见证记录的原因。该见证记录提供了恢复原始状态所需的信息,也能进一步验证恢复是否确实成功。接下来就会产生一个问题:高级配置失败的频率有多高?因此,我们在 EvoUndo 中评估了 600 项演进任务。其中,478 项提升了智能体的能力,但这类提升中有 197 项存在恢复缺陷。这约占能力成功提升案例的 42%。因此,关键结论是:一项变更可能会提升智能体的能力,却使系统无法可靠地恢复。Now, undoing a change isn't always as simple as executing the reverse command. Suppose an agent changes the wait time from 30 to 60. To undo this change, it needs to know that the original value was 30. This is why EvoUndo captures a witness of the previous state before applying the mutation. And this witness provides information for restoring the original state and further verifying that the restoration actually worked. Now the question arises: how often do advanced configurations fail? So, in EvoUndo we have evaluated 600 evolution tasks. Of these, 478 resulted in improved capabilities, but 197 of these improvements had recovery defects. This is about 42% of cases of successful improvement of capabilities. So, the key takeaway here is that a mutation can improve an agent's capabilities but leave the system incapable of reliable recovery.

现在我们可以解释为什么“请撤销”这个请求不起作用了。于是,我们自然想利用这些提示词告诉智能体:“嘿,你能把这些恢复错误都修好吗?”我们测试了四种由验证器引导的修复策略,但在原有恢复语言的框架内,没有一种能修复197个实际发生的故障。问题未必出在智能体的推理能力上。有些情况下,智能体缺乏关于初始状态的准确信息;另一些情况下,恢复语言无法表达撤销这条操作链所需的操作。因此,我们分别研究了这两项局限,也就是两个“瓶颈”:一是关于初始状态的准确信息,二是恢复语言的表达能力。Now we can say why the request " please undo" didn't work. So naturally, we wanted to use the prompts and tell the agent, "Hey, could you just fix all these recovery errors?" We tested four verifier-guided remediation strategies, but within the original recovery language, none of them fixed 197 natural failures. The problem wasn't necessarily the agent's reasoning. In some cases, the agent lacked accurate information about the initial state. In others, the recovery language could not express the operation required to undo the chain. Therefore, we investigated these two limitations separately. So, two "bottlenecks". The first is accurate information about the initial state, and the second is the expressiveness of the recovery.

当我们提供了关于发生了哪些变化以及变化位置的精确信息时,48 个案例中成功恢复的数量从 0 个提高到 38 个。第二个因素是恢复工具的表达能力。因此,当我们实现了更丰富的撤销操作后,143 个案例中成功恢复的数量从 0 个显著提高到 142 个。这些结果来自两个不同的实验子集,但合在一起说明了为什么恢复既需要准确的状态信息,也需要执行必要撤销操作的能力。When we provided precise information about what had changed and where, recovery improved from 0 to 38 out of 48 cases. The second is the expressiveness of the recovery tools. So, when we implemented richer undo operations, recovery improved significantly from 0 to 142 cases out of 143. These results are from two different experimental subsets, but together they show why recovery requires both accurate state information and the ability to perform the necessary undo operation.

现在的问题是,更好的取消机制能否挽救失败的变更?如果赋予智能体更强的恢复能力,会发生什么?使用原始的恢复语言时,对于需要恢复的 197 次变更,我们一次都无法恢复;但扩展这种语言后,我们成功恢复了其中 180 次,约占 92%。因此,可接受的改进数量从 600 个任务中的 281 个增加到了 461 个。这提升了 30 个百分点,也引出了下一个问题:如何将这些恢复检查融入智能体的演进流程?接下来,我把时间交给 Dolly,由她介绍 Evo-Undo 算法。Now we have the question of whether a better cancellation mechanism can rescue failed mutations. So what happens if we give the agent better recovery capabilities? With the original recovery language, we were unable to recover any of the 197 mutations that needed recovery, but after expanding this language, we successfully recovered 180 cases out of 197. That's about 92%. As a result, the number of allowable improvements increased from 281 to 461 out of 600 tasks. That's a 30 percentage point improvement, and that brings us to the next question. How do we build these recovery checks into the agent evolution process? Now I'll turn the floor over to Dolly to talk about the Evo-Undo algorithm.

EvoUndo 准入检查The EvoUndo admission check

好的,谢谢你,Tanmay。接下来我们来看看 Evo-Undo 的实际工作原理。首先,我们从代理开始——或者更确切地说,由代理自行启动。代理会结合当前状态、效果契约和恢复计划来处理变更。在应用变更之前,我们会捕获一个代表初始状态的状态见证。而在此之前,也就是在测试环境中进行测试时,代理会应用变更并执行恢复计划。独立验证器也会检查原始状态是否已恢复。OK. Thank you, Tanmay. Well, let's get to how Evo-Undo actually works. So, first we will start with the agent, or rather, the agent will start himself. The agent processes the mutation taking into account the current state, the effects contract, and the recovery plan. And before applying the mutation, we capture a state witness that represents the initial state. And even before that, during testing in the test environment, the agent will apply the mutation and execute the recovery plan. The independent verifier will also check whether the original state has been restored.

如果根据用户的标准,该变更提升了能力,并且通过了恢复检查,智能体就会接受这些更改。否则,智能体会尝试纠正问题,或者验证器会彻底拒绝该变更。因此,韧性成为准入决策的一部分,而不再是我们在部署 AI 智能体之后才要策略性规划的事项。If the mutation improves the capabilities according to the user's criteria and passes the recovery check, the agent accepts the changes. Otherwise, the agent tries to correct the situation or the verifier rejects the mutation completely. Thus, resiliency becomes part of the admission decision, rather than something we strategically plan for after the AI agent is deployed.

好的,谢谢。接下来,我们通过一个例子来看看 Tanmay 已经讲解过的内容。让我演示一下这个例子在实践中会是什么样子:计时器从 30 变为 60。我们先从初始状态开始,这是一个简单的例子,我们的智能体的时间值为 30。在进行任何更改之前,EvoUndo 会先读取初始值。然后,它会存储并捕获这个初始值,将其作为状态见证。这样我们就确切知道需要恢复什么;如果必须恢复,我们也会清楚哪个状态才是真实状态,从而可以返回到该状态。Okay, thank you. Next, we will go through what Tanmay has already explained with an example. Let me demonstrate what that example would look like in practice with the timer changing from 30 to 60. So, let's start with the initial state, a simple example where our agent has a time value of 30. Before changing anything, EvoUndo first reads the initial value. And then it stores, it captures the initial value as a state witness. We know exactly what needs to be restored, if we have to do it, we will know exactly what state is real so we can return to it.

现在,智能体按照我们的要求将等待时间从 30 改为 60。如果需要恢复,撤销操作会使用已保存的见证将超时时间恢复为 30。独立验证器也会确认恢复后的值与原始值一致。因此,不能仅仅因为执行了撤销命令就认定恢复成功;验证器还会检查接收到的状态,确保我们确实将状态恢复到了预期值。Now the agent changes the wait time from 30 to 60, as we request. And if a restore is needed, undo uses the saved witness to restore the timeout to 30. Now an independent verifier will also confirm that the restored value matches the original. So, a restore is not considered successful simply because the undo command was executed, the verifier also checks the received state to make sure we are actually performing a restore to the desired state.

恢复、补偿或升级处理Recover, compensate, or escalate

现在,一个更重要的问题出现了。我们已经有了这个恢复选项。那么,我们是否应该一视同仁地使用它,对所有故障都应用恢复机制呢?当然不应该。并非所有故障都能用同一种方式修复。Well, now a more important question arises. So, we have this recovery option in our arsenal. Should we use it evenly and apply the recovery mechanism to all failures? Well, of course not. Not every failure can be fixed in the same way.

如果什么都没有改变,那么……如果系统中没有任何变化,我们只希望它恢复,我们只希望它安全地重试。我们希望代理只需再试一次,并尝试达到我们需要的状态。然而,如果我们有一个初始状态,就可以将其恢复;但如果外部操作已经被记录,我们就需要一个补偿机制,也就是一个补偿操作,来抵消其影响。If nothing has changed, then it's just, if nothing has changed in the system, we would just like it to recover, we would just like it to retry safely. We would like the agent to simply try again and try to reach the state we need. However, if we have an initial state, we can restore it, but if the external action has already been recorded, we will need a compensation mechanism, a compensatory action, to cancel its effect.

如果我们无法恢复、无法验证恢复操作的安全性,或者验证器拒绝了恢复操作,那么智能体就应该停止,并将问题上报给更高层级。具体该如何应对,显然取决于实际发生了什么,以及哪些操作可以安全撤销、哪些不能。这几乎就把我带到了最后一页,在那里我们会总结关于两项工作的所有内容:UndoBench 和 EvoUndo。And if we cannot restore, cannot verify the safety of the restoration, or the verifier rejected the restoration, then the agent should stop and pass it on to a higher level. The right response definitely depends on what actually happened and what can be safely undone and what cannot. This brings me almost to the last slide, where we summarize everything about our two works: UndoBench and EvoUndo.

所以,这里的关键结论是:第一,UndoBench 展示了任务的成功完成。UndoBench 表明,成功完成一项任务并不总能保证其能够成功恢复。第二,EvoUndo 算法提供了一套结构化流程:固定初始状态、应用变更、独立验证恢复情况,然后进行还原。因此,EvoUndo 算法的运行方式完全符合我们的预期。第三,只有在同时满足功能性和可恢复性要求时,我们才应允许自我进化变更。归根结底,赋予智能体更多自主权的同时,我们也应为其提供更可靠的行动恢复方式。好的。So, the key takeaways here are: first, UndoBench shows successful task completion. UndoBench shows that successfully completing a task does not always guarantee its successful recovery. Second, the EvoUndo algorithm provides a structured process: fixing the initial state, applying the mutation, independent verification of the recovery, and restoration. So, the EvoUndo algorithm works exactly as we intended. Third, we should allow self-evolutionary changes only when the requirements for both functionality and recoverability are met. Ultimately, by giving agents more autonomy, we should also provide them with more robust ways to recover from their actions. OK.

最后,希望大家还记得一开始的那个智能体。它当时在找“取消”按钮。现在,它终于找到了。我们通过研究项目 EvoUndo 开始构建这项能力。大家可以在 GitHub 仓库中了解详情,也可以扫描屏幕上的二维码访问项目页面。我们的目标是让恢复能力成为 AI 智能体的一项基础能力,这样它们不仅能执行操作,还能在出现问题时恢复。非常感谢。And finally, I hope you remember the agent from the beginning. He was looking for the "cancel" button. Well, now he has it. We started building this capability through our research project EvoUndo. You can check it out in the repository on GitHub. You can scan the QR code on the screen to go to the page. Our goal is to make recovery a fundamental capability of AI agents, so that they can not only perform an action, but also recover if something goes wrong. Thank you very much.

值得记下

  1. 超时意味着没有收到响应,不能据此判断操作失败。
  2. 恢复机制应该与智能体造成的影响类型相匹配。