← govind p lal
AI and ML Bootcamp · Lecture 21 · lecture notes

LangGraph - State, Nodes, Edges, Checkpoints, Interrupts

In short — A plain while-loop agent keeps everything in RAM and can't be paused or resumed. This lecture shows what LangGraph adds: a shared state, nodes and edges, checkpointing, human-in-the-loop interrupts and time travel. It ends with the hello-world graph, a tool-calling agent and subgraphs.

Problem with the while-loop agent

builds on Lecture 9: Week 8 - AI&ML | From APIs to Agents | 07/03/2026, Lecture 9: Week 8 - AI&ML | From APIs to Agents | 07/03/2026

The Problem In a bare while-loop agent, state lives in local variables and control flow lives in if / while / break.

The Solution Keep one clearly defined state that stores every turn, message and tool call. -> LangGraph. It is a framework (opinionated about what it adds or drops) around the same agent loop.

Graph view of the agent: nodes and edges

builds on Lecture 9: Week 8 - AI&ML | From APIs to Agents | 07/03/2026
tool call?no tool callresultSTARTAgentLLM callToolsruns toolEND
The agent loop as a graph with one conditional edge.
!

The model never runs a tool. It only says which tool and which arguments (e.g. get_score with team names and date). The tool node executes it and feeds the result back.

State: the whiteboard

Three primitives: State, Nodes, Edges. State is a whiteboard in a room. Every node writes what it did. Anyone can read it. No node erases what another wrote.

Reducers When a node returns something, there are two choices: overwrite the old value or append to it.

Building a graph in code

builds on Lecture 9: Week 8 - AI&ML | From APIs to Agents | 07/03/2026, Lecture 9: Week 8 - AI&ML | From APIs to Agents | 07/03/2026
from langgraph.graph import StateGraph, MessagesState, START, END

def echo(state):
    return {"messages": [("ai", "hello world")]}  # update only

g = StateGraph(MessagesState)
g.add_node("echo", echo)
g.add_edge(START, "echo")
g.add_edge("echo", END)
app = g.compile()
app.invoke({"messages": [("user", "hi")]})

Compile - final step after all nodes and edges are decided. It checks the structure, attaches the thread ID.">checkpointer, and gives a runnable graph. The graph can also be visualised.

Tool-calling agent

def route(state):
    last = state["messages"][-1]
    return "tools" if last.tool_calls else END

Example: 'weather in Paris and Tokyo?' -> two get_weather calls -> results (18 C clear, 24 C raining) -> final answer. The whole run is visible in the state.

Checkpointing and persistence

Checkpointer -> after every step, take a photo of the whiteboard. A thread ID labels which run the photos belong to, so their order is known.

UnlockedHow
MemoryRead saved state of the thread
Human in the loopPause at a checkpoint, wait for a reply
Time travelList checkpoints and go back to one
Fault toleranceAgent stuck or crashed -> resume from last checkpoint

Checkpointer vs Store

Interrupt and human in the loop

Interrupt -> a function that pauses the graph and asks a human (yes / no, approve / reject). It needs a checkpointer, because state must be saved while waiting. Time does not matter: the snapshot waits.

What happens on resume LangGraph does not continue from the interrupt line. It stores the human's answer and re-runs the node from the start. This time interrupt returns the stored answer and execution goes on.

!

Rules: no important side effects before interrupt (or make them idempotent), keep interrupt calls in the same order each run, keep values JSON-serialisable. A flag stored in state can skip already-done work.

Time travel

Subgraphs and multi-agent

doneSupervisor agentWeather agentMath agentEND
A supervisor graph whose nodes are themselves agents.

A node is just a function, so it can be a full agent with its own graph. A supervisor routes to worker agents (researcher, engineer, weather, math) and ends when the work is done.

When to use LangGraph

Glossary

Node
A unit of work in a LangGraph graph, such as an LLM call or a tool execution.
Edge
A route connecting nodes; fixed or conditional.
State
Shared dictionary (whiteboard) that all nodes read and update.
Reducer
Rule for merging a node's update into state: overwrite or append.
Compile
Final step that validates the graph and makes it runnable.
Checkpointer
Saves a snapshot of state after each step, keyed by thread ID.
Thread ID
Label identifying the run whose snapshots are stored.
Interrupt
Pauses the graph to wait for a human response.
Command
Object carrying the human's reply to update state or route.
Fork
Branching a new run from an earlier checkpoint.