After this lesson, you will be able to: Use LangGraph to build graph-based agentic workflows with conditional branching, cyclic loops, and persistent checkpointing.
AgentExecutor is fine for simple loops. Real workflows have conditionals, branches, parallel steps, and human-in-the-loop checkpoints. LangGraph models agents as state graphs, nodes are functions, edges are control flow, and state flows between them. This lesson builds a multi-step research agent with branching.
AgentExecutor = loop. LangGraph = graph. Same model deciding what to do, but you control where it can go next, what state persists, when to stop. Production agent code lives in LangGraph today.
1. `pip install langgraph langchain-anthropic`
2. Mental model: a graph has State (the dict that flows through), Nodes (functions that read+update state), and Edges (where to go next, conditionally).
3. You compile the graph; calling it runs from START until END.
Three nodes, conditional edges, persistent state.
from typing import TypedDict, Annotatedfrom langgraph.graph import StateGraph, START, ENDfrom langgraph.graph.message import add_messagesfrom langchain_anthropic import ChatAnthropicmodel = ChatAnthropic(model='claude-sonnet-4-6')class State(TypedDict):topic: strplan: strresearch: list[str]draft: strdef plan(state: State):p = model.invoke(f'Make a 3-bullet research plan for: {state["topic"]}').contentreturn {'plan': p}def research(state: State):r = model.invoke(f'Plan: {state["plan"]}\nResearch this and return facts.').contentreturn {'research': state.get('research', []) + [r]}def write(state: State):d = model.invoke(f'Plan: {state["plan"]}\nFacts: {state["research"]}\nWrite a 300-word piece.').contentreturn {'draft': d}g = StateGraph(State)g.add_node('plan', plan)g.add_node('research', research)g.add_node('write', write)g.add_edge(START, 'plan')g.add_edge('plan', 'research')g.add_edge('research', 'write')g.add_edge('write', END)app = g.compile()result = app.invoke({'topic': 'why ravens are smart'})print(result['draft'])
Pass `checkpointer=MemorySaver()` (or PostgresSaver for prod) to `g.compile()`. Each step's state is saved. You can resume mid-flow, replay, or fork, invaluable for long-running agents.
Sign in and purchase access to unlock this lesson.