Loading patterns…
Reversible Actions & Compensation (Agent Saga)
A pattern for making agent side effects safe to undo. Structure the trajectory as a saga: every forward action (book a flight, charge a card, create a record) is paired with a compensating action that reverses its business effect, and every tool is made idempotent with an idempotency key so a retry or a rollback produces the same end state instead of duplicating work. When a step fails partway through, the agent runs the compensations for the already-completed steps in reverse order rather than leaving the system half-applied. There is no automatic ACID rollback across services, so compensations are explicitly designed as the logical inverse of each action. Distinct from `durable-execution`: that persists and replays a run so it can continue to completion after a crash, whereas this defines how to semantically undo committed side effects when completion is no longer the right outcome.
In 30 seconds
- What
- Pairs each forward action with an explicit compensating action that reverses its business effect, using idempotency keys to make retries and rollbacks converge to the same state.
- When to use
- Multi-step workflows across services where failures mid-trajectory require undoing already-committed side effects without automatic ACID rollback.
- Watch out
- Compensations must be authored correctly and remain available; a broken or missing compensation leaves the system in an inconsistent state with no automatic recovery.
Ask the AI expert about this pattern
Opens the assistant with your question prefilled. You review it before sending.
Reversible Actions & Compensation (Agent Saga): Overview
A pattern for making agent side effects safe to undo. Structure the trajectory as a saga: every forward action (book a flight, charge a card, create a record) is paired with a compensating action that reverses its business effect, and every tool is made idempotent with an idempotency key so a retry or a rollback produces the same end state instead of duplicating work. When a step fails partway through, the agent runs the compensations for the already-completed steps in reverse order rather than leaving the system half-applied. There is no automatic ACID rollback across services, so compensations are explicitly designed as the logical inverse of each action. Distinct from `durable-execution`: that persists and replays a run so it can continue to completion after a crash, whereas this defines how to semantically undo committed side effects when completion is no longer the right outcome.
- Every forward action paired with a compensating action (semantic undo)
- Idempotency keys make retries and rollbacks converge to the same end state
- Ordered rollback of completed steps on mid-trajectory failure
- Check-before-act and upsert guards prevent duplicate side effects
- No automatic ACID rollback: compensations are explicitly authored
- Distributed side effects modeled as a saga of local transactions
The Agent Architect
One pattern, one tradeoff, one production failure story. A short weekly briefing for people building agentic systems.
Weekly email, one-click unsubscribe. We only use your address to send the briefing.
References
The papers, specifications, and repositories this pattern is based on.
From the engineer behind this catalog
Get your agent architecture reviewed
This page documents one pattern. Your system runs dozens, and most failures live in how they fit together. Have the whole design reviewed against the 288 patterns in this catalog: architecture, reliability, evaluation and cost, every finding mapped to the pattern that fixes it.
€750 instead of €1,500, one week, written report and walkthrough call, until 30 September