AI Agent Compensation Workflows: Repair Partial Failure Safely
When an agent cannot make a distributed workflow atomic, compensating actions provide a durable, auditable way to reconcile completed side effects after failure.
An AI travel agent reserves a hotel, fails to book the flight, and then crashes before telling the user. A content agent publishes a page but times out before updating the index. These are not ordinary exceptions. External reality has changed only halfway.
AI agent compensation workflows repair that gap with explicit corrective actions. They are useful when one database transaction cannot span every API, but they are not magical rollback. Canceling a reservation may incur a fee, and deleting a message cannot make recipients forget it.
Model Side Effects as Durable Steps
Give every side-effecting step a stable operation ID, idempotency key, status, external receipt, and compensation policy. Persist intent before calling the provider and record the result before allowing the workflow to advance.
The state should distinguish requested, confirmed, unknown, compensation_requested, and compensated. A network timeout produces unknown, not failed. Reconcile through the provider’s read API before retrying.
Keep the model out of the accounting layer. The model may propose a plan, but code should enforce which step can run and whether its receipt exists.
Design Compensation With the Forward Action
Every new tool integration should answer four questions: Can the action be undone? Until when? At what cost? What evidence proves the corrective action succeeded?
Some compensations are direct: release inventory, cancel a draft deployment, or restore a previous document version. Others are semantic: issue a refund rather than erase a charge, publish a correction rather than delete a widely shared post, or open a human task when reversal is impossible.
Capture these rules in the tool registry. Do not ask the agent to invent a safe reversal during an incident.
Compensate in Dependency Order
A saga usually compensates completed steps in reverse order, but dependencies matter more than chronology. If a shipping label depends on an order, void the label before canceling the order. Parallel branches need a recorded dependency graph and deterministic join.
Compensation itself can fail. Retry with backoff and the same idempotency key, place persistent failures in a durable queue, and alert a human with the original and corrective receipts. Never loop indefinitely inside the model context.
Add Human Gates for Irreversible Damage
Automatic compensation is appropriate when the correction is known, bounded, and no more harmful than the original action. Require approval when it sends a new external message, moves money beyond a defined limit, affects another person’s access, or changes public records.
Show the operator a concise ledger: what completed, what remains uncertain, the proposed correction, expected cost, and deadline. Approval must bind to that exact action digest.
Test the Unhappy Path
Inject failure after every step, including immediately after the provider succeeds but before your receipt is stored. Test duplicate delivery, stale leases, expired cancellation windows, and a compensation provider outage.
The invariant is not “everything rolls back.” It is “every external effect reaches a known, explainable state.” Durable ledgers, provider reconciliation, explicit compensations, and human escalation turn a clever agent into an operable system.
Sources
> Want more like this?
Get the best AI insights delivered weekly.
By subscribing, you agree to our Privacy Policy. You can unsubscribe at any time.
> Related Articles
AI Agent State Snapshots: Resume Long Jobs Without Repeating Side Effects
Durable agents need more than chat history. Snapshot plans, tool results, permissions, and idempotency state so a crash can resume safely instead of replaying the world.
Embedding Model Migration: Change Vectors Without Breaking Search
Embedding upgrades change the geometry of your index. Use versioned vectors, dual writes, shadow queries, and measured cutover instead of mixing incompatible representations.
LLM Request Coalescing: Stop Paying Twice for the Same Answer
When identical LLM requests arrive together, single-flight execution can collapse them into one upstream call—if cache keys, streaming, failures, and tenant boundaries are designed correctly.
Tags
> Stay in the loop
Weekly AI tools & insights.