Implementation guides, worked examples, and interactive labs
Agent-planned saga: catalogue checks, the pivot and who compensates
Run a fulfilment plan proposed by an agent through a saga orchestrator and see which checks keep a failed plan from leaving effects behind.
Synthetic fixtures · deterministic model · nothing is called over the networkExperiment inputs
Complete-run results
Decision trace
What this experiment demonstrates
An agent reads a customer request for order 4471, worth 180, and proposes a fulfilment plan: reserve stock, authorise the payment, apply a goodwill credit, capture the payment, create the shipment and send a confirmation. The plan goes to a saga orchestrator that knows a catalogue of five steps with their kinds: reserve and authorise are compensable, capture is the pivot, shipment and confirmation are retriable. The goodwill credit is not in the catalogue. The orchestrator validates the plan, executes it, asks for approval before a capture above the threshold, and on a failure before the pivot runs compensations in reverse order with idempotency keys.
Nothing here calls a language model. The agent is a fixed policy that proposes the same plan every run, so every difference in the outcome is traceable to a control you changed rather than to model randomness.
Run controlled comparisons
Start with the defaults and read the trace. The validator removes the goodwill credit and tells the agent why, the two compensable steps succeed, and the saga pauses at the pivot because 180 is above the approval threshold of 150. Raise the threshold to 200 and the whole plan completes. Now make the payment authorisation fail permanently: the orchestrator releases the reservation, the first release call times out and is retried, and the idempotency key makes the retry a no-op. Switch idempotent compensation off and the stock is released twice.
Hand compensation to the agent instead of the orchestrator and make the capture fail with the threshold at 200: two compensable steps took effect, but the agent undoes only the most recent one, and the stock reservation is left standing. Let the plan run without catalogue validation and the goodwill credit executes as an unregistered step. Make the shipment fail permanently after the pivot: with the orchestrator in charge the saga is marked for a human, because nothing after the pivot can be compensated; with the agent in charge it improvises a refund that nobody planned. Finally, change the pivot approval to none while the amount is above the threshold and watch the capture run unapproved.
Notice what does not change. With validation on, the orchestrator owning compensation and idempotent keys, moving the failure between steps only changes how many compensations run; every invariant still holds. The unsafe counts appear exactly when one of those three deterministic controls is switched off.
Inspect the trace and keep evidence
The step table lists every step in the agent plan with its catalogue kind, what the validator decided, how many attempts it took and its final state, followed by any compensations or improvised actions. Metrics count executed steps, compensations, pending approvals and escalations, and four invariant violations: effects left uncompensated, unregistered steps executed, double compensations and a pivot run without approval. Start trace hides the steps, Next step reveals them one at a time, and Show all or the slider returns to the full sequence. Reset restores the defaults, and Export JSON downloads the inputs, the step table and the trace so two runs can be compared side by side.
Limits and production translation
The catalogue has five steps and one order; real sagas carry dozens of step types, concurrent sagas on the same stock and compensations that can themselves fail for business reasons. Approval here is a single threshold on the amount, timeouts happen at fixed points, and the agent re-plans at most once. What carries over is structural: plans are validated against a catalogue before any effect, the orchestrator owns the compensation log and the keys, the pivot is gated by policy code, and a failure after the pivot goes to a person rather than to an improvised undo.