A stateful workflow is a multi-step, automated process where the execution engine maintains persistent operational state across steps, enabling long-running, resumable, and compensatable operations. This contrasts fundamentally with a stateless workflow, where each step or invocation is independent and processes inputs in isolation without retaining memory of prior actions.
Key differentiators include:
- Persistence: Stateful workflows durably save context (e.g., intermediate results, step counters, user data) to storage like a database or Write-Ahead Log (WAL), allowing recovery after failures. Stateless workflows have no such persistence.
- Resumability: A stateful workflow can be paused, interrupted by a system crash, and later resumed from the last persisted state checkpoint. A stateless process must be restarted from the beginning.
- Compensation: For complex transactions, stateful workflows can implement Saga patterns, where failed steps trigger compensating actions (e.g., refunds, rollbacks) based on the recorded state. Stateless flows lack the context for such orchestrated rollback.
In agentic systems, a stateful workflow allows an autonomous agent to tackle a multi-day analysis, maintaining its findings and plan across sessions, while a stateless agent would forget everything after each API call.