A cheat sheet should compress the right things, not just shrink examples. The goal is to preserve the mental model and the most reusable patterns so you can move quickly without re-learning the whole course every time.
This page gathers the core LangGraph building blocks, current API ideas, and production reminders that repeatedly matter when you design, review, or debug a graph-based workflow.
Treat it as a reference map, not a substitute for the deeper lessons.
Most graphs can be described with a handful of concepts: state schema, nodes, edges, conditional routing, reducers, checkpoints, interrupts, and traces. If you can explain those clearly, you can usually understand any new workflow the team proposes.
| Concept | What It Does | Why It Matters |
|---|---|---|
| State | Shared workflow data | Defines the contract across nodes |
| Node | One named step of work | Keeps logic inspectable and testable |
| Edge | Connects execution steps | Makes control flow explicit |
| Conditional route | Chooses the next node | Enables branching and loops |
| Reducer | Merges updates for a field | Prevents accidental overwrites |
| Checkpoint | Saves execution state | Enables pause, resume, replay |
| Interrupt | Pauses for external input | Enables human-in-the-loop |
The core Graph API loop is always recognizable: define state, add nodes, add edges or routes, compile, then invoke or stream. Once you internalize that shape, examples stop feeling unfamiliar.
The best quick rule is to separate business data, workflow status, and operational metadata. That keeps graphs readable and reduces the temptation to hide everything in one catch-all field.
Routes should be easy to test with tiny state objects. Loops need counters. Every branch should be able to reach a terminal outcome or explicit pause state. Use `Command` when one node should update and route together.
Graphs become production systems only when you add persistence, observability, permission boundaries, and incident habits. This is the section to revisit before shipping anything user-facing.
When reviewing a LangGraph application, start with the state schema before reading node code. The state tells you what the workflow believes exists: user request, messages, retrieved evidence, decisions, approvals, retries, errors, and final output. If the state is vague, every node becomes harder to understand. A precise state schema is the backbone of a graph.
Next review node responsibility. Each node should do one kind of work: classify, retrieve, call a model, execute a tool, validate, ask for approval, or format the result. If a node retrieves data, calls a model, writes to an external system, and decides the next route, it is too large to test confidently. Split it until each node has a small input-output contract.
Then inspect edges and routes. The graph should make control flow visible: where the run starts, where it can pause, where it can retry, where it can fail safely, and where it ends. Loops need counters or progress checks. Conditional routes need small deterministic tests. Human review should be represented as an interrupt or explicit state transition, not hidden inside a long node.
Finally review persistence and operations. If the graph can pause, resume, time travel, or recover after failure, it needs a durable checkpointer and stable thread identifiers. If the graph performs side effects, those side effects must be idempotent or protected by approval and deduplication. A graph that works in memory during a demo may still be unsafe for production if it cannot survive restarts or explain previous decisions.
Use the Graph API when you want the workflow shape to be explicit and reviewable. It is excellent for teams because nodes and edges create an architecture diagram in code. Product managers, security reviewers, and developers can discuss the workflow by pointing at named steps: classify, retrieve, approve, execute, summarize. This clarity is valuable for agents with branching, loops, and human review.
Use the Functional API when the workflow reads more naturally as ordinary Python control flow but still needs durable execution. The `@entrypoint` function describes the main workflow, and `@task` functions wrap work that should be checkpointed, replay-aware, and safe around side effects. It is a good fit for orchestration that is mostly sequential with a few durable calls.
Subgraphs are the composition tool when part of a workflow deserves its own state and lifecycle. A research subgraph, review subgraph, or specialist agent subgraph can stay reusable while the parent graph controls the overall product flow. The design question is whether shared state should be simple and explicit or whether the subgraph needs its own internal state contract.
The LangGraph cheat sheet is most valuable during review. Start with state: are fields typed, owned, and scoped? Then review nodes: does each node do one job and return a small update? Then review routes: are branch names meaningful, testable, and bounded? Finally review persistence: can the workflow resume safely without duplicating side effects?
A good review should include one real trace. Compare the intended graph path to the actual path. Look at state before and after each important node. Confirm that reducers merged data intentionally, interrupts paused at safe boundaries, retries stopped at the right time, and final output was produced from approved evidence.
When the cheat sheet reveals a weak area, convert it into a concrete action. A vague route becomes a tested route function. A broad state field becomes typed fields. A risky side effect becomes an approval gate or idempotent task. This turns reference material into engineering improvement.
Use this when you need to remember the smallest correct Graph API shape.
from typing_extensions import TypedDict
from langgraph.graph import StateGraph, START, END
class State(TypedDict):
question: str
answer: str
def answer_node(state: State) -> dict:
return {"answer": f"Handled: {state['question']}"}
builder = StateGraph(State)
builder.add_node("answer_node", answer_node)
builder.add_edge(START, "answer_node")
builder.add_edge("answer_node", END)
graph = builder.compile()
Use a route function when the next node should be chosen from state.
def route(state):
return "human_review" if state["risk"] == "high" else "publish"
Remember the two-key ideas: use a checkpointer and resume with `Command(resume=...)` on the same thread.
from langgraph.types import interrupt, Command
approved = interrupt("Approve?")
# Later
graph.invoke(Command(resume=True), config={"configurable": {"thread_id": "t-1"}})
State:
- Is every field typed and owned by a node?
- Are reducer fields intentional?
Nodes:
- Does each node have one responsibility?
- Are side effects isolated and idempotent?
Routes:
- Can every branch reach END, retry, or interrupt?
- Do loops have a ceiling?
Persistence:
- Is a durable checkpointer used when resume matters?
- Are thread IDs stable and tenant-safe?
Operations:
- Are traces, errors, retries, and approvals observable?
- Can one risky tool or route be disabled quickly?
Only if you already understand the fundamentals. It is best used as a refresher after the main lessons.
The relationship between state, nodes, and routing. Most API details can be looked up once that mental model is solid.
Your preferred state conventions, route naming rules, tool-governance patterns, and deployment guardrails.
Explore 500+ free tutorials across 20+ languages and frameworks.