Duplicate approval arrives after cancellation
Detect: Transition guard sees a terminal state and rejects the event.
Recover: Record the rejected callback without reopening the supplier.
Make agent progress an explicit set of states, guarded transitions, and durable events so every action has a permitted execution context.
An agentic state machine defines named states and the events that can move a run between them. States represent operational facts such as awaiting evidence, ready for review, or committed; they should not claim to expose the model's private reasoning. Transition guards enforce business invariants outside the model.
The model can propose an event or classify an observation, but deterministic transition code decides whether it is legal. Persist the state version alongside the transition event to prevent concurrent workers from both advancing the same run. State design is therefore a concurrency and authorization decision as much as an orchestration technique.
A proof of concept often uses booleans such as approved and finished. Replace ambiguous combinations with a small explicit state model before adding external writes.
Production adds transition guards, optimistic concurrency, expiration events, and an operator view. Terminal states must explain whether work succeeded, failed, or was cancelled.
Enterprise deployments require machine-version migration and compatibility for old runs. A new release cannot assume that every persisted execution starts at the first state.
Names legal states, terminal states, accepted events, and transition guards.
Atomically verifies expected state version and records the next state.
Deduplicates callbacks and delivers observations to the correct execution instance.
Starts side effects only after the relevant transition is durably accepted.
Exposes current state, blocked conditions, and permitted operator interventions.
stateDiagram-v2
[*] --> Collecting
Collecting --> Assessing: Required documents received
Assessing --> Reviewing: Assessment validated
Assessing --> Collecting: Evidence missing
Reviewing --> Activating: Authorized approval
Reviewing --> Rejected: Reviewer rejects
Activating --> Active: Directory confirms creation
Activating --> Reconciling: Outcome unknown
Reconciling --> Active: Existing supplier verified
Active --> [*]
Rejected --> [*]sequenceDiagram
participant A as Callback A
participant B as Callback B
participant S as Transition service
participant D as State store
A->>S: Approval for state version 7
B->>S: Cancellation for state version 7
S->>D: Commit approval if version is 7
D-->>S: Accepted as version 8
S->>D: Commit cancellation if version is 7
D-->>S: Version conflict
S-->>B: Reload current state and apply policyBind workflow version, business identifier, and initial state in durable storage.
Authenticate its source and deduplicate its event identifier before considering a transition.
Check required evidence, authority, and expected state version using trusted services.
Atomically record the accepted event and next state; reject competing stale updates.
Start the permitted task through an outbox or equivalent reliable boundary.
Convert success, rejection, timeout, or cancellation into explicit subsequent events.
Enterprise operations · Illustrative enterprise scenario, not a reported customer outcome.
A multinational distributor onboards suppliers across procurement, finance, and compliance teams.
Email-driven status changes permit activation before bank-detail verification or after an approval has expired.
The agent must gather documents and assess completeness while activation remains gated by verified review.
A durable state machine coordinates collection, assessment, approval, activation, and ambiguous-outcome reconciliation.
If the activation call times out, the run enters reconciliation and checks for an existing supplier before any retry.
Monitor time spent in each state, rejected transitions, stale approvals, and reconciliation backlog to reveal process bottlenecks.
| Decision | Benefit | Cost |
|---|---|---|
| Explicit states | Illegal action sequences become testable and visible. | Excessive state granularity can make evolution cumbersome. |
| Atomic transitions | Concurrent callbacks cannot silently overwrite progress. | Contention and storage availability affect advancement. |
| Versioned machines | In-flight work remains interpretable across releases. | Migration logic and operational tooling require maintenance. |
Detect: Transition guard sees a terminal state and rejects the event.
Recover: Record the rejected callback without reopening the supplier.
Detect: State advances but no task completion appears.
Recover: Redeliver the outbox action using the original operation identity.
Store an enumerated state and separate explanatory notes.
Evaluate authority and prerequisites in application code.
Pin machine versions and explicitly map compatible transitions.