Module 1: Architecture and State Contracts
LangGraph State Management
Learning objectives
- Explain the core mental model behind LangGraph State Management
- Apply LangGraph State Management within Architecture and State Contracts
- Identify important boundaries, trade-offs, and failure modes
- Produce concrete evidence from the practice exercise
Related: LangGraph Core Concepts | LangGraph State Graph | LangGraph Nodes and Edges | LangGraph Index
State as TypedDict
State is a TypedDict with optional Annotated fields for reducers.
from typing import TypedDict, Annotated
from operator import add
class State(TypedDict):
question: str
context: Annotated[list[str], add]
answer: strquestion— no reducer; overwritten by node returnscontext—addreducer; new lists are concatenated
Reducers
Reducers define how state updates merge.
| Reducer | Behavior |
|---|---|
| None (default) | Overwrite |
add (lists) | Concatenate |
operator.or_ (dicts) | Merge dictionaries |
| Custom function | Your logic |
Custom reducer:
from typing import Annotated
def merge_dicts(existing: dict, update: dict) -> dict:
return {**existing, **update}
class State(TypedDict):
metadata: Annotated[dict, merge_dicts]State Scope
State is scoped to a thread (conversation). Two threads do not share state.
result = graph.invoke(state, config={"configurable": {"thread_id": "abc123"}})Threads enable multi-tenancy: user A and user B each have their own state history.
State Hygiene
- Keep state small. Large state objects serialize slowly and bloat checkpoints.
- Use reducers intentionally. Overwriting when you meant to append causes data loss.
- Type everything.
TypedDictgives you autocomplete and validation. - Don't put secrets in state. Checkpoints persist state to disk.
Related
- LangGraph Core Concepts — state definition
- LangGraph State Graph — building graphs with state
- LangGraph Persistence and Checkpoints — persisting state
- LangGraph Index — full topic map
Practice lab
Implement the smallest runnable agent workflow that demonstrates LangGraph State Management. Trace inputs, state, model and tool calls, outputs, and cost; inject one failure and add a regression test that prevents it from returning. Add an operational constraint such as concurrency, recovery, security, latency, or cost, and defend the resulting design trade-off.
Review questions
- What problem does LangGraph State Management solve, and what assumptions does it rely on?
- Which boundary or failure case is easiest to miss, and how would you expose it?
- What alternative design would you consider, and what trade-off would change the decision?
- What artifact, trace, test, or metric proves that your implementation is correct?
Completion evidence
- A working artifact, annotated trace, or reproducible experiment
- At least one normal case and one deliberately failing or boundary case
- A concise explanation of the design choice and its trade-offs
- Saved output showing how correctness was evaluated