Lesson 2 of 7 · 4 min read
LangChain and LangGraph
In this lesson
TL;DR: Use LangChain's
create_agentwhen a model-driven tool loop is the right shape and you want hooks around it: middleware can trim context, cap model calls, retry tools, redact data or require human approval. Drop to LangGraph when the path must be explicit: aStateGraphof nodes and edges over typed state, where reducers decide how updates merge and a checkpointer saves state per thread so a run can pause and resume. Pausing usesinterrupt(); resuming sendsCommand(resume=value), and the interrupted node runs again from its first line, so anything with a side effect before the interrupt happens twice unless you move it or make it idempotent.
After this lesson, you should be able to choose between create_agent and a hand-built graph, explain state, reducers, checkpointers and threads, implement an approval with interrupt and resume, and avoid the duplicated side effect that resume semantics invite.
Before you read
Commit to an answer now. The lesson that follows explains it, and having guessed first, even wrongly, makes the explanation easier to remember.
1A LangGraph node sends a confirmation email, then calls interrupt() to ask a manager to approve. The manager approves and the graph resumes. What happens to the email?
Two layers
Checked November 2026: langchain 1.5.2 and langgraph 1.2.24, both MIT, both first released as 1.0.0 on 17 October 2025.
LangChain is the higher layer. create_agent (from langchain.agents) builds an agent that is, in the documentation's words, a model calling tools in a loop until a task is complete. Its configuration takes a model, tools, a system prompt, middleware, a response format for structured output, a checkpointer, and context and state schemas.
Middleware is how you change that loop without rewriting it. Hooks run at fixed points: before_agent, before_model, after_model, after_agent, and wrappers wrap_model_call and wrap_tool_call that surround each call. Built-in middleware covers summarisation, model and tool retries, model call limits, PII handling, to-do lists, subagents and human-in-the-loop approval.
LangGraph is the runtime underneath, described as a low-level orchestration framework and runtime for long-running, stateful agents. You use it directly when the path must be explicit.
The graph model
- State is a typed object, often a
TypedDictwith amessagesfield. - Nodes are functions that read state and return updates.
- Edges connect nodes; conditional edges route on state.
- Reducers say how an update merges: replace a field, or append to a list (
Annotated[list, operator.add]). - Checkpointers save state after each step, per thread.
InMemorySaverfor tests,SqliteSaverorPostgresSaverfor real use. Stores hold data across threads, such as user memory.
# Real API, abridged; checked against docs.langchain.com, November 2026.
from langgraph.graph import StateGraph, START, END
from langgraph.types import interrupt, Command
from langgraph.checkpoint.memory import InMemorySaver
def propose(state):
return {"refund": {"order": state["order"], "amount": 40}}
def approve(state):
decision = interrupt({"question": "Approve this refund?", "refund": state["refund"]})
return {"approved": decision == "yes"}
def execute(state):
if state["approved"]:
issue_refund(state["refund"]) # side effect after the interrupt
return {}
g = StateGraph(RefundState)
g.add_node("propose", propose)
g.add_node("approve", approve)
g.add_node("execute", execute)
g.add_edge(START, "propose")
g.add_edge("propose", "approve")
g.add_edge("approve", "execute")
g.add_edge("execute", END)
app = g.compile(checkpointer=InMemorySaver())
config = {"configurable": {"thread_id": "refund-A17"}}
app.invoke({"order": "A-17"}, config) # stops at the interrupt
app.invoke(Command(resume="yes"), config) # resumes the approve node
The thread_id is what ties the second call to the first. Without a checkpointer and a thread id, there is nothing to resume.
Email and interrupt in one node
Send email
first pass
interrupt()
checkpoint, run stops
Resume: node re-runs
email sent again
duplicate
Outcome, unsafe: Two emails
Email in its own earlier node
notify node
completes, checkpointed
ask node: interrupt()
run stops
Resume at ask
notify not repeated
Outcome, safe: One email
The resume semantics, reproduced
Here is the behaviour that matters, modelled without the library so it runs anywhere. A node runs; if it hits an interrupt with no resume value, the run stops and is checkpointed; on resume, the same node runs again from the top and the interrupt returns the value:
class Interrupt(Exception):
pass
def make_runner(nodes):
def run(state, checkpoint, resume=None):
start = checkpoint.get("node", 0)
for i in range(start, len(nodes)):
ctx = {"resume": resume if i == start else None}
try:
state.update(nodes[i](state, ctx))
except Interrupt:
checkpoint.update(node=i, state=dict(state))
return "paused"
checkpoint.clear()
return "done"
return run
def interrupt(ctx):
if ctx["resume"] is None:
raise Interrupt()
return ctx["resume"]
emails = []
def approve_bad(state, ctx):
emails.append("approval requested") # side effect BEFORE the interrupt
return {"approved": interrupt(ctx) == "yes"}
def ask(state, ctx):
return {"approved": interrupt(ctx) == "yes"}
def notify(state, ctx):
emails.append("approval requested") # side effect in its own earlier node
return {}
for nodes in ([approve_bad], [notify, ask]):
emails.clear()
run, cp, state = make_runner(nodes), {}, {}
run(state, cp)
run(state, cp, resume="yes")
print(len(emails), state["approved"])
# => 1 True
The first design prints 2 True: the email went twice. The second prints 1 True (the annotated line): the notification lives in its own node, which completed and was checkpointed before the pause, so resume starts at ask and does not repeat it. The same rule applies to payments, tickets and any external write.
Deep Agents
Deep Agents (deepagents, create_deep_agent) is LangChain's packaged harness for long, multi-step work. It adds file-system tools (ls, read_file, write_file, edit_file, glob, grep), an execute tool that runs only in a sandbox, subagents through a built-in task tool, an opt-in to-do tool for planning, and interrupt_on to require approval for chosen tools. It is a good reference for what a harness adds on top of a loop; see the harness track for the general pattern.
What it decides and what it leaves
| Question | LangChain and LangGraph |
|---|---|
| Control | Model loop (create_agent) or explicit graph; nest one in the other |
| State | Typed state with reducers; checkpoints per thread; stores across threads |
| Pause and resume | interrupt() and Command(resume=...); the node re-runs from its start |
| Delegation | Subagent middleware, subgraphs, or agents called as tools |
| Integration | @tool from type hints and docstrings; MCP tools in Deep Agents |
| Visibility | LangSmith for tracing, evaluation and deployment (separate product) |
Left to you: which tools need approval, what is idempotent, which checkpointer backs production, retention of checkpoints that contain user data, and the authority checks inside the tools themselves.
Say it in 30 seconds
"LangChain's create_agent is a model-calling-tools loop with middleware: hooks before and after the agent and model, and wrappers around each model and tool call, used for summarisation, retries, call limits, PII handling and human approval. LangGraph underneath is a graph runtime: typed state, nodes, edges and reducers, compiled with a checkpointer that saves state per thread. interrupt() pauses a node and Command(resume=...) continues it, and the interrupted node re-runs from its first line, so I keep side effects after the interrupt or in their own node, or make them idempotent. Both went 1.0 in October 2025 and are MIT."
Check yourself
Answer aloud or on paper before revealing. Producing the explanation unaided is exactly what a panel listens for.
1What two things must exist for a LangGraph interrupt to be resumable?
2When would you choose create_agent with middleware over a hand-built StateGraph?
3What does a reducer decide in LangGraph state?