State and reducers
Words made simple
A few useful meanings before you read the explanation.
- State
- The data describing where a workflow is now, what it already knows, and what still needs to happen.
- Deterministic
- Following steps or rules defined by code. The model does not decide which step should run next in a deterministic workflow.
- Checkpoint
- A saved snapshot of workflow progress that can help it continue later.
More words from this lesson
- Persistence
- Saving information so it remains available after a request ends or a process restarts.
- Authentication
- Checking who a user or service is, such as by verifying a login session.
Overview
- State is the structured data shared by graph steps, such as current intent, evidence IDs, and task phase.
- A reducer specifies how a new update combines with an existing state field.
- Some fields replace earlier values; others safely combine multiple updates.
Why this matters
Nodes need explicit inputs and predictable updates, especially when parallel branches write results.
An everyday example
A shared case file contains one current status but can contain many evidence entries.
A technical example
Replace phase; merge evidence by source ID; add bounded event records rather than replacing the entire event list accidentally.
How it works
- Node returns partial update
- Graph applies each field's update rule
- Resulting state becomes input to subsequent nodes
- Persist at configured boundaries.
Architecture and flow
Current state + node updates → reducers → next state.
The insurance assistant example
Two independent document-checking branches contribute findings without overwriting one another.
When to use it
Explicit state for any graph; reducers when multiple updates need combination.
When to avoid it
Do not store full PDFs, credentials, database clients, or unrestricted histories in checkpoints.
Interview answer
“State is the graph's execution contract; reducers define how updates are applied, including safe merging for parallel results.”
Benefits, trade-offs, and production considerations
- Prefer deterministic, associative merging for concurrent results and deduplicate by stable IDs.
- Appending arrays blindly can grow state and duplicate replayed records.
- Runtime authentication should be freshly verified and kept distinct from model-editable fields.
Can you explain it without the notes?
State and reducers
Use your own words. Explain an example and one limitation before checking the explanation.
Check your explanation
State is the structured data shared by graph steps, such as current intent, evidence IDs, and task phase. A reducer specifies how a new update combines with an existing state field. Some fields replace earlier values; others safely combine multiple updates.
Turn this concept into a clear answer.
Practice this conceptAdapted from 13_AI.MD · “State and reducers”. Examples are study fragments; framework behavior can depend on your version.