Tutorial
LangGraph Tutorial
A practical tutorial on LangGraph, the graph-based framework for stateful LLM applications, using Python and Claude. Covers state graphs, tool-calling agents, persistence, human-in-the-loop, streaming, multi-agent coordination, observability with LangSmith, and deployment.
Chapters
01
Introduction: What LangGraph Is and Why Graphs
02
State and Graphs: The Core Abstraction
03
Edges and Flow: Branching and Looping
04
Tools and Agents: The Basic Agent Loop
05
Persistence: Checkpointers and Threads
06
Human-in-the-Loop: Interrupts and Approvals
07
Streaming: Watching a Graph Run
08
Subgraphs: Composition and Nesting
09
Multi-Agent: Supervisors, Hierarchies, Handoffs
10
Observability: LangSmith, Studio, and Debugging
11
Deployment: From Notebook to Production
12
Best Practices: State Design and Anti-Patterns
About this tutorial
A practical tour of LangGraph, the graph-based framework for stateful LLM applications, using Python and Claude.
Who This Is For
- Python developers who've called an LLM API and want to build something beyond a single prompt
- Engineers frustrated that LangChain chains are linear when real agents need loops
- Anyone who's tried to bolt "pause, ask the user, continue" onto an agent and felt the pain
Contents
Fundamentals
- Introduction: What LangGraph is, why graphs instead of chains, install, first graph
- State and Graphs: StateGraph, TypedDict state, nodes, reducers, START/END
Core Concepts
- Edges and Flow: Plain edges, conditional edges, cycles, branching
- Tools and Agents: Tool calls with Claude, ToolNode, the agent loop
Advanced
- Persistence: Checkpointers, threads, resuming, inspecting history
- Human-in-the-Loop: Interrupts, approval gates, editing state
- Streaming: Stream modes (values, updates, messages), tokens, events
- Subgraphs: Composition, subgraph state, nesting
Ecosystem
- Multi-Agent: Supervisor, hierarchical teams, handoffs between agents
- Observability: LangSmith tracing, LangGraph Studio, debugging graphs
- Deployment: LangGraph Cloud, self-hosting, FastAPI integration
Mastery
- Best Practices: State design, error handling, anti-patterns
How to Use This Tutorial
- Read sequentially for a complete path from hello-graph to production
- Run every example. LangGraph is a runtime, not a theory; you learn it by executing graphs
- Break things. Add a cycle with no exit condition. Drop a tool call. Watch LangGraph complain
Quick Reference
Install
pip install langgraph langchain-anthropic
export ANTHROPIC_API_KEY="sk-ant-..."
Hello, Graph
from typing import TypedDict
from langgraph.graph import StateGraph, START, END
class State(TypedDict):
messages: list[str]
def greet(state: State) -> State:
return {"messages": state["messages"] + ["hello from the graph"]}
graph = (
StateGraph(State)
.add_node("greet", greet)
.add_edge(START, "greet")
.add_edge("greet", END)
.compile()
)
result = graph.invoke({"messages": ["starting"]})
print(result["messages"])
# ['starting', 'hello from the graph']
Common Patterns
# A graph that decides which node runs next
def route(state: State) -> str:
if state["needs_tool"]:
return "tools"
return END
graph.add_conditional_edges("agent", route, {
"tools": "tools",
END: END,
})
# Persistence: state survives across invocations
from langgraph.checkpoint.memory import MemorySaver
memory = MemorySaver()
graph = builder.compile(checkpointer=memory)
graph.invoke({"messages": [msg]}, config={"configurable": {"thread_id": "user-42"}})
# Streaming: watch the graph run
for chunk in graph.stream(input, stream_mode="updates"):
print(chunk)
# Tool call loop
from langchain_anthropic import ChatAnthropic
from langgraph.prebuilt import ToolNode
llm = ChatAnthropic(model="claude-opus-4-5").bind_tools([my_tool])
tool_node = ToolNode([my_tool])
Learning Path Suggestions
A usable agent in an afternoon (roughly 4 hours)
- Chapters 01 to 04 for the agent loop
- Chapter 05 for persistence so your agent remembers conversations
Production-ready agents (roughly 10 hours)
- All chapters in order
- Chapters 06 and 07 for real UX (pausing, streaming)
- Chapters 10 and 11 for operability
Multi-agent systems (roughly 6 hours)
- Chapters 01 to 04 (the primitives)
- Chapter 08 for subgraphs, 09 for coordination patterns
- Chapter 12 for state design, which matters most in multi-agent
Additional Resources
- LangGraph docs: the canonical reference
- LangGraph repo: source, examples, issues
- LangChain Academy LangGraph course: video walkthrough
- LangSmith: hosted tracing, free tier
- LangGraph Studio: desktop app for visual graph debugging
- Anthropic API docs: Claude's tool-use and messages API
Versions
This tutorial is written for LangGraph 0.2+ with Python 3.11+ and langchain-anthropic 0.3+. Claude examples target claude-opus-4-5 or claude-sonnet-4-5 but work unchanged on other Claude models.