Moosa Memon
← Index of work

Rollback for agents that touch the real world

agent-saga-engine: a transactional runtime that executes agent tool calls as a Saga, each forward step paired with a compensating inverse, so a failure at step 3 automatically undoes steps 2 and 1 instead of leaving them permanently committed.

Type
Agents
Stack
Python / Pydantic v2 / Event sourcing / Framework-agnostic
Status
Core runtime built with tests and integration examples

Problem

Agent frameworks route prompts and plan tool calls. But when those tools mutate the real world (payments, cloud infrastructure, inventory, email), a failure at step 3 leaves steps 1 and 2 committed. Reserve a flight, book a hotel, charge the card, card fails: the framework reports an error and the customer has a hotel booking they never paid for. None of the popular frameworks address this, because it’s a distributed-systems problem, not a prompting one.

System

Tool calls execute as a Saga: a sequence of forward transactions T1…Tn, each registered with a compensating inverse Ci. On failure at step k, the engine runs C(k−1)…C1 in strict reverse order. An event-sourced write-ahead log records every step’s intent before it runs, so a crash mid-saga can be recovered and compensated on restart rather than left half-done.

Worth knowing

The dual-schema contract. A tool cannot be registered without its compensating inverse, or an explicit pivot=True marking a point of no return. That’s enforced by Pydantic validators at construction time, not discovered mid-incident. The interesting design question is which steps are pivots: sending an email can’t be un-sent, so everything before it must be safe to commit and everything after must be safe to fail.

This sits underneath LangChain, LangGraph, CrewAI or AutoGen rather than replacing them, which is the right layer for a correctness guarantee.

Have a workflow that looks like this?

Most of these start as a messy, manual process someone got tired of. Twenty minutes is usually enough to sketch how I'd approach yours.