Agents with LangChain and LangGraph
Who it is for
What you will achieve
Prerequisites
Curriculum
- Step 1: What LangChain Is For, and When to Skip It: Five Standard Parts, One Pipe, and a Decision Table
LangChain is a box of standard parts (models, prompts, retrievers, tools, parsers) that snap together with a pipe. The same refund question through the plain Anthropic SDK (1 import, 13 lines) and a chain (3 imports, 14 lines) gives the same answer word for word. It pays off when the bot grows; for one call, the SDK is simpler, with 16 packages instead of 38.
- Step 2: Why Chains Break: No Branch, No Retry, No Pause, and the Same Refund Assistant as a LangGraph Graph
A refund assistant built three ways. The chain runs classify, retrieve, reply once: it answers an opening-hours question with the billing line, misses the 30-day window, and sends a $150 refund with approved False. Plain if/while fixes it but hides the flow; a LangGraph StateGraph puts the branch, the retry loop and the approval stop in the arrows.
- Step 3: LangGraph Nodes, Edges and State: Build Your First Graph, Route With a Conditional Edge, and Read the Run Three Ways
Two small graphs. A refund skeleton: SupportState, a classify node, a route function on a conditional edge, and an Annotated log that appends instead of overwriting. A help desk: classify and answer call a scripted test model, spam goes straight to END after one model call instead of two, and the same run read with invoke, stream values and stream updates.
- Step 4: Human-in-the-Loop and Checkpointing in LangGraph: interrupt, a SQLite Save Slot and Command(resume=...)
A refund under 50 is approved by itself; 120 must wait for a person, maybe until tomorrow. interrupt pauses the graph and returns a question, SqliteSaver keeps the state in refunds.db after the program ends, and a brand new process resumes thread t-big with Command(resume="approve") at ask_human, not at the start.
- Step 5: Multi-Agent Patterns: Hub and Spoke in LangGraph, With Short Briefs, Owned Tools and a Retry the Hub Decides
One agent with six tools and one long prompt picks the wrong tool more often. Split it like a hospital reception: a hub routes each message, and billing, tech and account spokes each get a four-field brief and two tools. Two spokes run side by side, the tech spoke's timeout is retried once, and a twice-failed identity check becomes "A person will follow up".
- Step 6: A Research Agent in LangGraph: Plan, Search, Read, Write, and a Check Node That Rejects Citations Nobody Read
A research agent reads three notes (mrr, ndcg, hit-rate) and writes a cited answer whose last sentence cites [hybrid-search], a note it never opened. Without a check, nothing stops it. A check node compares cited with read, sends the draft back with a fix line, draft 2 cites [hit-rate], problems is [] and the graph ends; max_drafts=2 stops a model that never learns.