- 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 Middleware
- 0.6 The stand-in model
- 0.7 Common pitfalls
- 0.8 Summary
-
Chapter 1. Chat models
- 1.1 Choosing a model by name
- 1.2 The same code with two models
- 1.3 Tokens
- 1.4 Token usage
- 1.5 Model parameters
- 1.6 Tokens add up in an agent
- 1.7 Common pitfalls
- 1.8 Summary
-
Chapter 2. Messages
- 2.1 Four kinds of message
- 2.2 The system message
- 2.3 A conversation by hand
- 2.4 Content blocks
- 2.5 Response metadata
- 2.6 The tool message and its id
- 2.7 Common pitfalls
- 2.8 Summary
-
Chapter 3. Tools
- 3.1 What the model sees
- 3.2 Writing the description the model reads
- 3.3 The model asks, your program runs
- 3.4 Arguments are checked before the tool runs
- 3.5 When a tool fails
- 3.6 What a tool returns
- 3.7 A schema written by hand (advanced)
- 3.8 Common pitfalls
- 3.9 Summary
-
Chapter 4. Structured output
- 4.1 A reply your program can read
- 4.2 Describing the shape with a Pydantic model
- 4.3 Getting the reply through a tool call
- 4.4 Output strategy: two ways to get the data
- 4.5 When the model gets it wrong: output validation
- 4.6 When not to use structured output
- 4.7 Where this is in the source (advanced)
- 4.8 Common pitfalls
- 4.9 Summary
-
Chapter 5. Streaming
- 5.1 Waiting for the whole answer
- 5.2 One item per step: updates
- 5.3 One item per piece: messages
- 5.4 Progress from inside a tool: custom
- 5.5 Several modes at once
- 5.6 Showing progress in a terminal
- 5.7 What streaming does not change
- 5.8 Common pitfalls
- 5.9 Summary
-
Chapter 6. Short-term memory
- 6.1 What a run carries
- 6.2 Remembering across runs
- 6.3 What the checkpointer saved
- 6.4 What grows
- 6.5 Trimming
- 6.6 A field of your own in the state (advanced)
- 6.7 When not to use memory
- 6.8 Common pitfalls
- 6.9 Summary
-
Chapter 7. Middleware in practice
- 7.1 Hooks
- 7.2 Call limit
- 7.3 Retry policy
- 7.4 Fallback model
- 7.5 Tool errors, ready made
- 7.6 Summarization
- 7.7 The order of the list
- 7.8 Options at a glance (advanced)
- 7.9 When not to use these
- 7.10 Common pitfalls
- 7.11 Summary
-
Chapter 8. Writing your own middleware
- 8.1 Two kinds of hook
- 8.2 Changing one request
- 8.3 Ending a run early
- 8.4 Guardrails
- 8.5 Guardrails of your own
- 8.6 The order of your own middleware
- 8.7 What guardrails do not do
- 8.8 Two more options (advanced)
- 8.9 Common pitfalls
- 8.10 Summary
-
Chapter 9. Asking before acting
- 9.1 A pause before a tool
- 9.2 Continuing a paused run
- 9.3 Four answers
- 9.4 What approval does not do
- 9.5 Options at a glance (advanced)
- 9.6 Common pitfalls
- 9.7 Summary
-
Chapter 10. Runtime context and long-term memory
- 10.1 What the model should not write (advanced)
- 10.2 What the tool runtime holds (advanced)
- 10.3 A store that outlives threads (advanced)
- 10.4 A preference that crosses threads (advanced)
- 10.5 What the store does not do (advanced)
- 10.6 State, context and store (advanced)
- 10.7 Common pitfalls (advanced)
- 10.8 Summary
-
Chapter 11. Several agents
- 11.1 An agent behind a tool (advanced)
- 11.2 What each side sees (advanced)
- 11.3 What isolation saves, and what it costs (advanced)
- 11.4 One, several or none (advanced)
- 11.5 Common pitfalls (advanced)
- 11.6 Summary
-
Chapter 12. Project: a support assistant
- 12.1 Six parts, one assistant
- 12.2 Stages 1 and 2: a reply and a memory
- 12.3 Stage 3: limits and a guardrail
- 12.4 Stage 4: approval and the whole assistant
- 12.5 What goes wrong
- 12.6 What the assistant leaves out
- 12.7 The customer from runtime context (advanced)
- 12.8 A subagent for order history (advanced)
- 12.9 Summary
- Answers to the self-checks
- Glossary
LangChain, Step by Step
13 chapters, 370 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 reliable agents with LangChain 1.x: a model that calls tools, returns structured replies, remembers the conversation, stops after too many calls, blocks sensitive input, and asks a person before it acts.
This book starts from zero. If you know Python but have never used an LLM framework, chapter 0 teaches the basics every later chapter needs: chat models, messages, tools, the agent loop and middleware. If you used the old chains and AgentExecutor, it explains the 1.x design around create_agent. Each new idea comes the same way: a plain-language picture, the smallest example that runs, a figure, and only then the formal definition.
What's inside
- 13 chapters, 370 pages, in one PDF
- Every printed output comes from a real recorded run, not from memory
- Runnable example code for every listing; most examples run offline from the recordings, so you can follow along without paying for model calls
- Self-check questions in every chapter, with answers at the back; exercises in every chapter, with full solutions in the example code
- A final project: a support assistant that looks up orders, replies in a fixed shape, keeps the conversation, stops after too many model calls, masks personal data, and waits for a person to approve a refund
Chapters
- Foundations
- Chat models
- Messages
- Tools
- Structured output
- Streaming
- Short-term memory
- Middleware in practice
- Writing your own middleware
- Asking before acting
- Runtime context and long-term memory
- Several agents
- Project: a support assistant
Not covered: deployment, hosting and operations; model training and fine-tuning; retrieval and vector databases; writing LangGraph graphs by hand; LangSmith; multimodal input; features that only one model provider offers; and a full reference of options.
Verified in November 2026 against langchain 1.5.2, langgraph 1.2.24 and Python 3.11. The recordings use DeepSeek's deepseek-flash model. Running every example once with a real key costs less than US$0.05.
Start free: chapters 0 to 2 are in the sample. The example code is on GitHub at airplanecraft/books-langchain.
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-langchain
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.