Compensation Handler | Agentic Tool Patterns | Arcade

Context

Multi-step operations across systems that can't use traditional transactions.

Problem

Cross-system operations can't be rolled back atomically; completed steps need explicit undo.

Solution

Implement compensation logic:

Examples

Python

@tool
def provision_customer(data: CustomerData) -> ProvisionResult:
    """Provision a new customer across systems.

If any step fails, previous steps are compensated.
    """
    completed = []
    try:
        account = create_account(data)
        completed.append(("account", account.id))

billing = setup_billing(account.id)
        completed.append(("billing", billing.id))

access = grant_access(account.id)
        completed.append(("access", access.id))

return ProvisionResult(success=True, account=account)
    except Exception as e:
        compensate(completed)  # Undo in reverse order
        raise

Considerations

Related Patterns

More in Tool Execution

Compensation Handler

Undo completed steps when a multi-step operation fails.

Category

Tool Execution

Context

Multi-step operations across systems that can't use traditional transactions.

Problem

Cross-system operations can't be rolled back atomically; completed steps need explicit undo.

Solution

Implement compensation logic:

Example (Python)

@tool
def provision_customer(data: CustomerData) -> ProvisionResult:
    """Provision a new customer across systems.

If any step fails, previous steps are compensated.
    """
    completed = []
    try:
        account = create_account(data)
        completed.append(("account", account.id))

billing = setup_billing(account.id)
        completed.append(("billing", billing.id))

access = grant_access(account.id)
        completed.append(("access", access.id))

return ProvisionResult(success=True, account=account)
    except Exception as e:
        compensate(completed)  # Undo in reverse order
        raise

Considerations

Related Patterns


Source: https://arcade.dev/patterns/compensation-handler