A saga chains a long workflow into a sequence of local transactions, each with a compensating action that can undo it. Invented for database transactions that outlive a single session, it is now the correct model for agent workflows that touch the real world.
Agents break atomicity constantly. "Migrate the payment service" means editing code, running migrations, updating configs, redeploying, and verifying — five steps where step 3 failing after step 2 committed leaves the system half-transformed. Distributed databases solved this in the 1980s (Garcia-Molina and Salem's original saga paper) with a simple contract: each step must be committed locally, and every step must ship an inverse — a compensating transaction that semantically, if not physically, undoes it.
For agents this means designing actions as pairs up front: create_resource pairs withdelete_resource, update_config with restore_config(version),send_email with — at best — send_correction, which is why irreversible actions deserve their own design conversation. The agent runtime maintains a compensation stack; any failure unwinds executed steps in reverse order, and the run ends in a state the user recognizes rather than a mystery.
Designing Compensations Honestly
- Semantic, not physical: the inverse of "append to file" is not "delete bytes" but "restore the document to its prior version."
- Ordered unwinding: compensations run LIFO; a pivot table built on a deleted table is worse than no cleanup.
- Pivot steps: some points of no return deserve explicit status — mark them, gate them behind confirmation, and never unwind past them casually.
- Compensations can fail too: log and escalate rather than nesting compensations for compensations.
The payoff is a property agents rarely have: the ability to fail loudly, cleanly, and partially without leaving ruins. A saga-aware agent that completes 80% of a deployment and undoes itself is more trustworthy than one that completes 90% and leaves the system on fire.