flowchart TB
core["langchain-core<br/>messages · BaseChatModel · tool specs · Runnable"]
lg["langgraph<br/>StateGraph · nodes · edges · loops<br/>checkpointers · prebuilt ToolNode"]
lc["langchain<br/>create_agent · middleware"]
da["deepagents<br/>planning · sub-agents · file tools"]
classic["langchain-classic<br/>chains · LCEL · prompt templates · parsers"]
prov["Provider packages<br/>langchain-openai, langchain-anthropic, …<br/>ChatOpenAI · embeddings"]
app["Your graph<br/>(the agent you build here)"]
lg --> core
lc --> lg
da --> lc
classic --> core
prov --> core
app -. "builds on" .-> lg
app -. "imports ChatOpenAI" .-> prov
app -. "imports messages" .-> core
Preface

This is a book about LangGraph1, the low-level framework for wiring language models into graphs you control. It builds an AI agent one part at a time: a state, a node, an edge, a loop, a tool, a checkpoint, a pause for a human. By the end you can see exactly where the model’s decisions enter the program and where your own code keeps the guardrails.
Each chapter is built around one runnable example to explore a topic. You can read the code, run it, change it, and watch what happens.
Who this book is for
You need to know a bit of Python to read and run the code. You do not need to know LangChain; the few pieces the book imports from it are introduced where the examples use them. You do not need to have built an agent before.
What you need on your machine:
- Python 3.11 or newer, and the companion repository, github.com/LgISP/langgraph-in-small-pieces, which holds one runnable program per chapter under
code/. - For Part I, nothing else. Every example runs on hard-coded logic: no model, no API key, no account.
- For Parts II and III, a local model. The book runs one with LM Studio, a free desktop app, on a laptop with about 16 GB of memory. If your machine cannot hold it, Appendix A — Using Other LLMs points the same code at a hosted model instead; running the whole book that way costs well under a dollar.
Only one section needs an account of any kind: the LangSmith part of 24 Observability, and it is optional.
How the book is organized
Three parts. First you build the machine with no model in it. Then you give it a real model to decide with. Then you build what it takes to run it for real.
Part I — Building Graphs teaches the core primitives: state, nodes, edges, branching, loops, tool nodes, persistence, human approval, parallel branches, subgraphs. By the end you have a working document-answering bot, and you have not called a language model once. Part I is self-contained; finish it and you can build real graphs.
Part II — Empowering Graphs with LLMs puts a real model into that bot: structured output and its failure modes, tool-calling, typed state schemas, the Functional API, multi-agent supervisors, memory across turns, streaming, middleware, and testing. This is where a graph stops being a hard-coded machine and starts making decisions.
Part III — Graphs in Production builds the mechanisms a deployed agent needs: error handling and retries, serving over HTTP, async at scale, observability, external tools over MCP, the internals of persistence, a full retrieval-augmented generation (RAG) pipeline, and an evaluation harness to prove it works.
What this book does not cover
- Hosted deployment. LangSmith Deployment (Cloud, Hybrid, Standalone with
langgraph.json) and Studio. The book serves a graph over plain HTTP (22 Serving over HTTP), to stay on LangGraph itself. - SaaS infrastructure. Authentication, thread ownership, rate limits and budgets, secret management, trace redaction, tool and document trust boundaries, schema migrations. Nine things shipping asks for names all nine and what breaks without each; none of them is implemented.
- Concurrency beyond one process. 23 Async at Scale runs a graph through the async door, caps the calls in flight and names the failures, all inside one process. Several processes can share one checkpointer, and the Gold challenge of 22 Serving over HTTP does exactly that. What is not covered is distributing the work itself: the queues and workers that hand runs between machines.
- Generative UI and front ends.
useStream, React streaming. Reading the stream on the client reads the stream from a plain browserfetch.
How to read it
The code. Each example is a single self-contained file. The complete, runnable versions live in the companion repository, a few of them spanning several files, with pinned dependencies and the end-of-chapter Challenge solutions under code/answers/. The book was tested on Python 3.11 with LangGraph 1.2.19. The 3.11 floor is the book’s, not LangGraph’s: the State schemas use typing.NotRequired, and LangGraph itself requires only 3.10+.
The versions. To keep the output consistent, the package versions are pinned in the companion’s requirements.txt. Feel free to use your own versions, but be warned: your output may diverge from what the book shows.
The boxes. Three kinds of callout appear throughout:
An internal detail or a sharper mental model. Skippable on a first read, valuable on the second.
A mistake that will bite you. These are almost always things the author hit by running the code, not by reading the docs.
A small change to make and re-run, so the lesson sticks.
The challenges. Most chapters end with a Challenge, graded by how far it takes you from the chapter. 🥉 Bronze checks a claim the chapter made, usually by breaking something and reading the failure. 🥈 Silver extends the chapter’s code into a case it did not cover. 🥇 Gold, which many chapters carry, takes the idea past where the chapter stopped, and is open-ended enough to be a small project. You can find the answers in the companion repository’s code/answers/ folder on GitHub.
LangGraph and LangChain
LangGraph and LangChain are developed by the same team. They are frameworks at different abstraction levels.
The LangChain docs offer three tiers for building agents. Deep Agents is the batteries-included harness: planning, sub-agents, file tools, ready to go. create_agent, in the langchain package, is a minimal, configurable harness: a model, some tools, and middleware hooks. LangGraph is the layer under both, for when you need fine-grained control and want to mix deterministic steps with agentic ones. This book teaches the bottom tier. create_agent compiles to exactly the StateGraph + ToolNode loop you will wire by hand in Part II, and The whole loop in one line: create_agent shows the seam where the hand-built loop and the one-liner meet.
LangGraph is the low-level library for stateful, branching, looping, multi-step control — in a word, agents. It is the subject of this book.
LangChain today means two things. Since LangChain 1.0 the langchain package is an agent harness, create_agent plus middleware, and it is built on LangGraph: langchain 1.3 requires langgraph, and what create_agent returns is a compiled LangGraph graph with two nodes, model and tools. The original toolkit (chains, LCEL, prompt templates, output parsers, document loaders) lives on as a separate package, langchain-classic. Both rest on the same foundation, langchain-core, which holds the message types and the BaseChatModel interface.
So LangGraph does not depend on LangChain; the reverse is now true. Inside a graph you will still import a model class (ChatOpenAI, from langchain-openai) and the message types (from langchain-core); the book explains each one where it appears.
The one thing to unlearn: LangChain’s old AgentExecutor. It now lives in langchain-classic; LangGraph is the recommended way to build agents, and it is what the book uses throughout.
Drawn as a dependency picture, it is a short stack: everything rests on one shared base, LangGraph sits directly on it, and the langchain harness sits on LangGraph.
Need your comment
This online edition is a beta book in the old sense: every paragraph, code block and figure takes a comment. Hover beside one and click the mark that appears (on a phone, the marks follow you down the page).
You can subscribe to the mailing list to hear about major updates, and about the next book, Coding Agent in Small Pieces, which takes one real agent apart and rebuilds it as a minimal runnable graph.
With that, let’s set up the environment as the first step.
Official documentation: https://docs.langchain.com/oss/python/langgraph; API reference: https://reference.langchain.com/python/langgraph.↩︎

