An agent task may involve several steps across different systems. If a later step fails, you cannot roll everything back with a database transaction. Sagas offer an alternative.
The problem
Suppose an agent books a flight, reserves a hotel, and then fails to book a car. The first two actions already happened in separate systems. There is no single transaction to abort.
The saga idea
A saga breaks the work into steps, each paired with a compensating action that undoes its effect. If a later step fails, the runtime runs the compensations for completed steps, usually in reverse order.
Designing compensations
- Cancel the reservation, issue a refund, or restore the previous value.
- Some effects cannot be fully undone, such as a sent email. For these, compensation may mean sending a correction.
- Compensations must themselves be idempotent and retryable.
Record the progress
Persist which steps completed so that after a crash the runtime can resume or compensate correctly.
Order steps by risk
Place steps that are hard to reverse as late as possible, after the easier ones succeed. Where possible, use a reserve-then-confirm pattern.
When to involve a person
If compensation fails or the situation is ambiguous, escalate to a human with a clear summary of what was done.
Takeaway
Plan failure paths when you design the workflow, not after the first incident.
Continue with the book
Explore the full treatment, worked examples, and exercises in Building Production-Grade AI Agents.
Adapted from Building Production-Grade AI Agents, published by Choral Software. Article text and original examples © 2026 Choral Software. All rights reserved.
