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.

Tutorial·Difficulty: Intermediate·12 chapters·Updated Apr 19, 2026

Chapters

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

  1. Introduction: What LangGraph is, why graphs instead of chains, install, first graph
  2. State and Graphs: StateGraph, TypedDict state, nodes, reducers, START/END

Core Concepts

  1. Edges and Flow: Plain edges, conditional edges, cycles, branching
  2. Tools and Agents: Tool calls with Claude, ToolNode, the agent loop

Advanced

  1. Persistence: Checkpointers, threads, resuming, inspecting history
  2. Human-in-the-Loop: Interrupts, approval gates, editing state
  3. Streaming: Stream modes (values, updates, messages), tokens, events
  4. Subgraphs: Composition, subgraph state, nesting

Ecosystem

  1. Multi-Agent: Supervisor, hierarchical teams, handoffs between agents
  2. Observability: LangSmith tracing, LangGraph Studio, debugging graphs
  3. Deployment: LangGraph Cloud, self-hosting, FastAPI integration

Mastery

  1. Best Practices: State design, error handling, anti-patterns

How to Use This Tutorial

  1. Read sequentially for a complete path from hello-graph to production
  2. Run every example. LangGraph is a runtime, not a theory; you learn it by executing graphs
  3. 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)

  1. Chapters 01 to 04 for the agent loop
  2. Chapter 05 for persistence so your agent remembers conversations

Production-ready agents (roughly 10 hours)

  1. All chapters in order
  2. Chapters 06 and 07 for real UX (pausing, streaming)
  3. Chapters 10 and 11 for operability

Multi-agent systems (roughly 6 hours)

  1. Chapters 01 to 04 (the primitives)
  2. Chapter 08 for subgraphs, 09 for coordination patterns
  3. Chapter 12 for state design, which matters most in multi-agent

Additional Resources

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.