ALLMAcademy

S5

Typed State, Parallel Work, and Human Gates

15 min2 optional deep dives

Use one explicit state contract to coordinate parallel nodes, retries, checkpoints, and human decisions.

  1. 01Define a typed state object that every node can inspect
  2. 02Merge parallel writes without silent overwrite
  3. 03Pause and resume a graph around a human approval decision

The state object is the shared contract

worked example
type 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:

  1. write the proposed action to state,
  2. checkpoint the graph,
  3. pause,
  4. show the proposal to a person,
  5. 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)

Retrieval Practice

Check one idea at a time

Question 1 of 3

Two parallel workers both write to state.results. What must the graph define?