S5
Typed State, Parallel Work, and Human Gates
Use one explicit state contract to coordinate parallel nodes, retries, checkpoints, and human decisions.
- 01Define a typed state object that every node can inspect
- 02Merge parallel writes without silent overwrite
- 03Pause and resume a graph around a human approval decision
The state object is the shared contract
worked exampletype ResearchState = {
question: string;
plan: string[];
findings: Finding[];
draft?: string;
approval?: "pending" | "approved" | "rejected";
budgetRemaining: number;
};Every node reads only the fields it needs and writes declared fields back.
Parallel work needs a merge rule
If 5 research workers finish at nearly the same time, they cannot all replace
state.findings. The graph needs a reducer such as “append each worker’s findings, then
deduplicate by source URL.”
Without that rule, parallelism creates a race condition.
A human gate is a normal node
Before a consequential action:
- write the proposed action to state,
- checkpoint the graph,
- pause,
- show the proposal to a person,
- resume with approved, rejected, or edited state.
The process can wait minutes or days because the decision is durable, not held in one web request.
Production failure modes
- Parallel workers silently overwrite each other's state.
- A handoff drops constraints the receiving agent still needs.
- A human approval page shows less detail than the tool will actually execute.
- A cyclic graph has a soft quality target but no hard maximum budget.
Deep dive: Handoffs vs. shared-state nodes
A handoff transfers control to a specialist agent. A shared-state node keeps one graph in control and invokes a specialist as one step. Prefer the shared-state pattern when auditability and central budgets matter more than conversational autonomy.
References & deeper reading (3)
- LangGraph PersistenceLangChain Docs
- InterruptsLangChain Docs
- Agents SDK HandoffsOpenAI Agents SDK
Retrieval Practice
Check one idea at a time
Two parallel workers both write to state.results. What must the graph define?