Safety & Control

Compensating Action

Pair every irreversible-looking agent action with a compensating action that can undo or counteract it.

Problem

Most agent tool palettes do not offer distributed transactions across the third-party systems the agent talks to, so there is no built-in mechanism to roll back a multi-step plan when one step fails. Without an explicit undo strategy, a failure halfway through the plan leaves the world in an inconsistent state: the flight is booked but the hotel is not, the card has been charged but the account does not exist. The agent then either retries blindly and double-books, or stops and leaves a human to clean up by hand.

Solution

For each forward action, define a compensating action (delete-after-create, refund-after-charge, archive-after-publish). On failure mid-plan, run compensators in reverse order to restore the prior state. Idempotent compensators.

When to use

  • Agent actions are irreversible-looking and distributed transactions are unavailable.
  • For each forward action a meaningful undo (delete-after-create, refund-after-charge) can be defined.
  • Compensators can be made idempotent so retrying them is safe.

Open the full interactive page

Diagram, neighbourhood map, code examples, related patterns and full provenance.

Related