Design typed state for a multi-step workflow
In this article (5 sections)
Conversation text is a poor source of operational truth. A multi-step workflow needs typed state that can be validated, checkpointed and resumed without asking a model what happened.
Execute a serializable state contract
The agent controls lab defines a Python dataclass.
from agent_cases import typed_state_case
result = typed_state_case()
assert result["complete"] is True
assert result["serializable"] is True
assert result["state"]["current_step"] == "approval"
assert result["state"]["approval"] is NoneThe record includes run ID, status, current/completed steps, attempts, approval and last error. It contains no hidden model memory.
Separate durable and derived fields
Durable state includes stable identifiers, user scope, validated inputs, completed side effects, idempotency keys, approvals and checkpoint version. Derived summaries can be recomputed and should not override source records.
Define allowed transitions such as running→approval_pending→approved→executing→complete. Reject impossible transitions and unknown schema versions. Keep sensitive content out of state unless necessary and protected.
Test recovery and concurrency
Serialize/deserialize, resume after each step and verify completed actions do not repeat. Handle two workers attempting the same transition with optimistic locking or transactions. Migrate old state versions explicitly.
The Generative & Agentic AI course uses typed state as the base for LangGraph or other orchestration frameworks, rather than binding learning to one library.
Exercise
Define a typed state and transition table for a five-step workflow. Add schema/version validation, simulate concurrent approval and cancellation, and prove one valid terminal result.
Continue learning
This article is part of the Agent workflows and state sequence. Use the neighbouring tasks when you need the prerequisite or the next application.
- Review the prerequisite or neighbouring task in Separate an agent's proposal from an approved action.
- Continue with Checkpoint a workflow and resume after failure.
Reference: LangGraph persistence.
Pankit Kumar has 10 years in Data Science & AI, building and shipping production systems in regulated pharma and clinical environments. He is a freelance trainer at Boston Institute of Analytics, AnalytixLabs and Scaler, and has taught this material to thousands of working professionals.
This article is part of our Generative & Agentic AI programme — 3 months. Add practical GenAI, retrieval and agent-building skills to your existing toolkit.
Explore Generative & Agentic AI