I built a way to auto-undo the mess when an AI agent fails mid-task

Reddit r/ArtificialInteligence Tools

Summary

A developer built agent-undo, a TypeScript library that adds undo/rollback handlers to AI agent tool calls so that if a step fails mid-task, previously completed steps are automatically reversed.

If you've built any agent that calls multiple tools in a row, you already know this feeling. Everything's going fine, step 1 works, step 2 works, then step 3 throws an error and the whole thing just stops. Except it doesn't stop cleanly, it leaves your database, your Stripe account, or whatever else half touched, and now you're the one manually cleaning it up. I got tired of writing the same "if this fails, go undo the last three things by hand" logic every time, so I built a small library for it. agent-undo wraps your tools with an undo handler. If a step in the chain fails, everything that already succeeded gets automatically rolled back, in reverse order, like a transaction. const chargeCustomer = defineTool({ name: 'charge_customer', execute: async ({ customerId, amount }) => stripe.charges.create({ customerId, amount }), undo: async (charge) => stripe.refunds.create({ chargeId: charge.id }), }); Step 3 fails, charge_customer's undo fires automatically. No manual cleanup, no 2am page. What's in it: Core saga engine with LIFO rollback Adapters for Vercel AI SDK and Mastra An MCP server, so Claude Code or any MCP client can run and roll back a saga through plain tool calls TypeScript, 68 tests passing What it doesn't do yet: No persistence. If the process itself crashes mid saga, not just a step failing, you lose the rollback stack. That's next. No dashboard yet, you read saga.status and saga.steps directly for now. It's early, v0.1. If you've hit this problem before, I'd really like to know how you handled it, and if you try this, tell me where it breaks. npm install u/ramcharan_2020/agent-undo
Original Article

Similar Articles

Can an AI agent safely undo changes it makes to itself?

Reddit r/artificial

This paper introduces EvoUndo, a framework that enforces recoverability as a constraint in self-evolving AI agents, highlighting bottlenecks like state grounding and recovery-language expressivity.

UndoGuard

Product Hunt

UndoGuard is a new product that acts as a Ctrl+Z undo mechanism for autonomous AI agents, letting users revert actions taken by agents.

Do I need a reversibility layer for my agent actions?

Reddit r/AI_Agents

The article questions whether a dedicated reversibility layer is necessary for AI agents in production to handle and undo mistakes, highlighting the manual effort currently required for recovery.