- Preface
- How to use this book
-
Chapter 0. Foundations
- 0.1 Setting up
- 0.2 Chat models and messages
- 0.3 Asking for help: the idea
- 0.4 Example: looking up an order
- 0.5 Why a hand-written loop is not enough
- 0.6 The stand-in model
- 0.7 Common pitfalls
- 0.8 Summary
-
Chapter 1. Your first graph
- 1.1 State
- 1.2 Nodes
- 1.3 Edges
- 1.4 The graph
- 1.5 Drawing the graph
- 1.6 A node that calls a model
- 1.7 Common pitfalls
- 1.8 Summary
-
Chapter 2. State and reducers
- 2.1 The state schema
- 2.2 The state update
- 2.3 Reducers
- 2.4 Messages
- 2.5 Putting the rules together
- 2.6 Common pitfalls
- 2.7 Summary
-
Chapter 3. Branching and loops
- 3.1 Conditional edges
- 3.2 Loops
- 3.3 Super-steps
- 3.4 The recursion limit
- 3.5 The Command object
- 3.6 Common pitfalls
- 3.7 Summary
-
Chapter 4. An agent, built by hand
- 4.1 A model node that can ask for a tool
- 4.2 The tool node
- 4.3 The agent loop
- 4.4 A ready-made routing function
- 4.5 A loop that never ends
- 4.6 Watching the messages grow
- 4.7 Two requests in one reply
- 4.8 When a tool fails
- 4.9 Building by hand, or not
- 4.10 Common pitfalls
- 4.11 Summary
-
Chapter 5. Persistence
- 5.1 A graph that forgets
- 5.2 The checkpointer and the thread
- 5.3 Checkpoints
- 5.4 The state snapshot
- 5.5 Continuing a thread
- 5.6 Saved copies last as long as your program
- 5.7 Common pitfalls
- 5.8 Summary
-
Chapter 6. Streaming
- 6.1 The wait
- 6.2 Stream modes
- 6.3 Message chunks
- 6.4 The stream writer
- 6.5 Several modes at once
- 6.6 Common pitfalls
- 6.7 Summary
-
Chapter 7. Asking before acting
- 7.1 The agent loop that never asks
- 7.2 Pausing with interrupt
- 7.3 Resuming with a resume value
- 7.4 The node starts again from its first line
- 7.5 Asking before sending a draft
- 7.6 Approve, edit or reject
- 7.7 Asking inside a tool
- 7.8 Several interrupts in one node
- 7.9 Common pitfalls
- 7.10 Summary
-
Chapter 8. Time travel
- 8.1 A run that went wrong
- 8.2 The state history
- 8.3 Checkpoint replay
- 8.4 Checkpoint replay and a pause
- 8.5 Checkpoint fork
- 8.6 Which node has just run
- 8.7 Common pitfalls
- 8.8 Summary
-
Chapter 9. Errors and retries
- 9.1 A node that fails
- 9.2 What a failed run leaves behind
- 9.3 The retry policy
- 9.4 Which errors, and how long to wait
- 9.5 The error handler
- 9.6 The durability mode
- 9.7 Common pitfalls
- 9.8 Summary
-
Chapter 10. Parallel branches
- 10.1 Three lookups in a row (advanced)
- 10.2 Fan-out (advanced)
- 10.3 Two branches, one key (advanced)
- 10.4 Fan-in (advanced)
- 10.5 The deferred node (advanced)
- 10.6 The Send object (advanced)
- 10.7 When one branch fails (advanced)
- 10.8 Common pitfalls (advanced)
- 10.9 Summary
-
Chapter 11. Subgraphs and several agents
- 11.1 A subgraph inside a parent graph (advanced)
- 11.2 What comes back, and the doubled list (advanced)
- 11.3 Keys that differ: call the subgraph yourself (advanced)
- 11.4 What a subgraph remembers (advanced)
- 11.5 Pausing inside a subgraph (advanced)
- 11.6 Handing the conversation to another agent (advanced)
- 11.7 What the update passes on (advanced)
- 11.8 A real model, and when one agent is enough (advanced)
- 11.9 Common pitfalls (advanced)
- 11.10 Summary
-
Chapter 12. Long-term memory and runtime context
- 12.1 A new thread starts empty (advanced)
- 12.2 The memory store (advanced)
- 12.3 Reaching the store from a node (advanced)
- 12.4 Namespaces keep customers apart (advanced)
- 12.5 A model that knows the preference (advanced)
- 12.6 Runtime context (advanced)
- 12.7 State, context and store side by side (advanced)
- 12.8 Common pitfalls (advanced)
- 12.9 Summary
-
Chapter 13. Project: an email workflow
- 13.1 The plan and the state
- 13.2 Classify, then the agent loop
- 13.3 Asking a person, and watching
- 13.4 When the send fails
- 13.5 Going back and running again
- 13.6 One file with the real model
- 13.7 Two lookups side by side (advanced)
- 13.8 Remembering a preference (advanced)
- 13.9 What is still missing
- 13.10 Common pitfalls
- 13.11 Summary
- Answers to the self-checks
- Glossary
LangGraph, Step by Step
14 chapters, 420 pages, every output from a real recorded run, with runnable example code for every listing. Start free with chapters 0 to 2.
Minimum price
$14.99
$19.99
You pay
Author earns
About
About the Book
Learn to build agents and workflows as graphs with LangGraph 1.x: a program made of named steps and arrows that keeps its data, chooses a path, streams its progress, saves a run, goes back to an earlier point, and stops to ask a person before it acts.
This book starts from an empty file. If you know Python but have never used an LLM framework, chapter 0 sets up the tools and explains every idea the later chapters assume. If you have used a ready-made agent and could not control what it does next, the book shows how such an agent is built from a model, a tool node and one decision, so you can change any part.
What's inside
- 14 chapters, 420 pages, in one PDF
- Every printed output comes from a real recorded run of the code in the book's repository
- Runnable example code for every listing; run an example with OFFLINE=1 and you get the recording back, without a key and without a network
- Self-check questions in every chapter, with answers at the back; exercises in every chapter, with solutions in the example code
- A final project: an email workflow that sorts each email, looks up the order, drafts a reply with a model, retries a failed send, and waits for a person to approve the draft before it sends anything
Chapters
- Foundations
- Your first graph
- State and reducers
- Branching and loops
- An agent, built by hand
- Persistence
- Streaming
- Asking before acting
- Time travel
- Errors and retries
- Parallel branches
- Subgraphs and several agents
- Long-term memory and runtime context
- Project: an email workflow
Not covered: model training and fine-tuning; search over documents and vector databases; LangSmith and the deployment and hosting products around LangGraph; multimodal input; features of one model provider; checkpoints stored in a database (named, not built); and the functional API.
Verified in November 2026 against langgraph 1.2.24 and Python 3.11. The recordings use DeepSeek's deepseek-flash model. Recording all the examples, including the runs that were thrown away, made 136 real model calls and cost US$0.024 in total.
Start free: chapters 0 to 2 are in the sample. The example code is on GitHub at airplanecraft/books-langgraph.
Categories
Feedback
Author
About the Author
Eric W is an independent AI consultant who helps teams build agents that work outside the demo: agents that plan, keep state, hand work to helpers and stop for human approval.
Before going independent, he spent six years in fintech, and earlier worked at IBM, HP and Cisco. That background shapes how he writes: every output in his books comes from a real recorded run, every example ships as runnable code, and the mistakes the model made stay in the book along with how to catch them.
He also builds his own products, including 1000usdinchina.com, a China travel budget planner with an AI trip-planning option.
Example code for this book: https://github.com/airplanecraft/books-langgraph
Contents
Table of Contents
Get the free sample chapters
Click the buttons to get the free sample in PDF or EPUB, or read the sample online here
The Leanpub 60 Day 100% Happiness Guarantee
Within 60 days of purchase you can get a 100% refund on any Leanpub purchase, in two clicks.
See full terms...
Earn $8 on a $10 Purchase, and $16 on a $20 Purchase
We pay 80% royalties on purchases of $7.99 or more, and 80% royalties minus a 50 cent flat fee on purchases between $0.99 and $7.98. You earn $8 on a $10 sale, and $16 on a $20 sale. So, if we sell 5000 non-refunded copies of your book for $20, you'll earn $80,000.
(Yes, some authors have already earned much more than that on Leanpub.)
Learn more about writing on Leanpub
Free Updates. DRM Free.
If you buy a Leanpub book, you get free updates for as long as the author updates the book! Many authors use Leanpub to publish their books in-progress, while they are writing them. All readers get free updates, regardless of when they bought the book or how much they paid (including free).
Most Leanpub books are available in PDF (for computers) and EPUB (for phones, tablets and Kindle). The formats that a book includes are shown at the top right corner of this page.
Finally, Leanpub books don't have any DRM copy-protection nonsense, so you can easily read them on any supported device.
Learn more about Leanpub's ebook formats and where to read them
Write and Publish on Leanpub
You can use Leanpub to easily write, publish and sell in-progress and completed ebooks and online courses!
Leanpub is a powerful platform for serious authors, combining a simple, elegant writing and publishing workflow with a store focused on selling in-progress ebooks.
Leanpub is a magical typewriter for authors: just write in plain text, and to publish your ebook, just click a button. (Or, if you are producing your ebook your own way, you can even upload your own PDF and/or EPUB files and then publish with one click!) It really is that easy.