Velamuvi AIAcademy
LangGraph

Lesson 7 of 11 · Agents

Human-in-the-Loop

Pause a LangGraph graph for a person with interrupt(), resume with Command(resume=...), handle approve, edit and reject, and why nodes restart when resumed.

  • 6 min read
  • Advanced
  • Reviewed
In this lesson you will learn
  • Pause a graph inside a node with interrupt() and show what it's waiting for
  • Resume a paused thread with Command(resume=...)
  • Handle approve, edit and reject decisions
  • Explain why a node restarts from the top when resumed
  • Use update_state and static breakpoints for review and debugging

Pausing for a person

Some steps need a person: approving a large refund, checking a draft before it's sent, choosing between options. LangGraph can pause a run at that point, save everything, and wait as long as needed, minutes or days, before continuing.

Approve, edit or reject

from typing import TypedDict
from langgraph.checkpoint.memory import InMemorySaver
from langgraph.graph import END, START, StateGraph
from langgraph.types import Command, interrupt

class State(TypedDict):
    refund: dict
    status: str

def propose(state: State) -> dict:                     # an agent would work this out
    return {"refund": {"order": "A-881", "amount": 350.0, "reason": "frame damaged on delivery"}}

def review(state: State) -> dict:
    print("  review node starts")
    decision = interrupt({"question": "Approve this refund?", "refund": state["refund"]})  # pause here
    if decision["action"] == "approve":
        return {"status": "approved"}
    if decision["action"] == "edit":
        return {"refund": {**state["refund"], "amount": decision["amount"]}, "status": "approved with edits"}
    return {"status": f"rejected: {decision['reason']}"}

def execute(state: State) -> dict:
    if state["status"].startswith("approved"):
        return {"status": f"{state['status']}; refunded {state['refund']['amount']:.2f} EUR"}
    return {}

builder = StateGraph(State)
builder.add_node("propose", propose)
builder.add_node("review", review)
builder.add_node("execute", execute)
builder.add_edge(START, "propose")
builder.add_edge("propose", "review")
builder.add_edge("review", "execute")
builder.add_edge("execute", END)
graph = builder.compile(checkpointer=InMemorySaver())     # interrupts need a checkpointer

config = {"configurable": {"thread_id": "refund-881"}}
result = graph.invoke({"status": "new"}, config)
print("Waiting for:", result["__interrupt__"][0].value)

# ...minutes or days later, a manager answers. Resume the same thread with their decision:
result = graph.invoke(Command(resume={"action": "edit", "amount": 300.0}), config)
print("Final:", result["status"])
Output
  review node starts
Waiting for: {'question': 'Approve this refund?', 'refund': {'order': 'A-881', 'amount': 350.0, 'reason': 'frame damaged on delivery'}}
  review node starts
Final: approved with edits; refunded 300.00 EUR

Step by step:

  1. interrupt(...) pauses the graph. The result contains __interrupt__, holding the value you passed in: everything a reviewer needs to decide. Your application shows it in a review screen, a Slack message or an email.
  2. The thread waits in its checkpoint. Nothing runs, and nothing is lost if your server restarts (with a durable checkpointer).
  3. invoke(Command(resume=...), config) continues the same thread. Inside the node, interrupt now returns the resume value, and the node carries on.

Interrupts require a checkpointer: the paused state has to be saved somewhere.

Nodes restart when resumed

Look at the output again: “review node starts” appears twice. When a thread resumes, LangGraph runs the interrupted node again from its first line; this time interrupt() returns the answer instead of pausing. Here's that mechanism in plain Python:

Try it yourselfPython
# How interrupt() works, in plain Python: the node raises a "pause" carrying a question.
# The runner saves where it stopped. On resume, the node runs AGAIN from its first line,
# and this time interrupt() returns the person's answer instead of pausing.
class Pause(Exception):
    def __init__(self, question): self.question = question

saved = {}                                         # stands in for the checkpointer

def interrupt(question):
    if "answer" in saved:
        return saved.pop("answer")                 # resuming: hand back the answer
    raise Pause(question)                          # first time: pause the graph

side_effects = []
def review(state):
    side_effects.append("email sent to manager")   # careful: code BEFORE interrupt runs twice
    decision = interrupt(f"Approve refund of {state['amount']} EUR?")
    return {"status": "approved" if decision == "yes" else "rejected"}

def run(state):
    try:
        return {**state, **review(state)}
    except Pause as p:
        saved["state"] = state
        print("Paused, asking:", p.question)

run({"amount": 350})
saved["answer"] = "yes"                            # a person answers later
print("Resumed:", run(saved["state"]))
print("Side effects:", side_effects)

The email to the manager was sent twice, because it came before the interrupt.

Designing the review

The approval-gate rules from the Agent Security and Guardrails course apply here:

  • Show the exact action: the order, the amount, the reason, not “approve refund?”.
  • Offer edit, not just yes or no: a reviewer who can correct the amount doesn't have to reject and start over.
  • Validate the answer: a resume value is input like any other. Check edited amounts and fields before acting on them (the exercise below does this).
  • Handle silence: if nobody answers, the thread simply stays paused. Decide what happens after a deadline, for example a reminder or an automatic rejection by a scheduled job.

Other ways to involve people

  • graph.update_state(config, {...}) edits a paused (or finished) thread's state directly, for example to fix an extracted field, before resuming with invoke(None, config).
  • Static breakpoints: compile(interrupt_before=["execute"]) pauses before a node every time, without changing its code. They're mainly for debugging and step-by-step testing; for real approval flows, interrupt() inside a node is clearer.

Common mistakes

Practice exercise

Handle a reviewer's resume value safely: an edit is still input, so check it before the graph acts on it.

Your solutionPython
refund = {"order": "A-881", "amount": 350.0}
decisions = [{"action": "approve"}, {"action": "edit", "amount": 300.0},
             {"action": "edit", "amount": 9000.0}, {"action": "delete everything"}]

# For each decision print the outcome:
# approve -> "refund 350.0"; edit -> "refund <new amount>" but only if 0 < amount <= the original,
# otherwise "invalid edit"; anything else -> "rejected"
Knowledge check

A node calls send_email() and then interrupt(). The graph pauses and is later resumed. What happens?

Summary

  • interrupt(value) pauses a graph inside a node, saving its state; the caller sees the value in __interrupt__.
  • Command(resume=...) continues the same thread; interrupt() then returns the answer.
  • Interrupts need a checkpointer and the same thread ID to resume.
  • The interrupted node restarts from the top: keep side effects after the interrupt.
  • Offer approve, edit and reject, validate edits, and use update_state or static breakpoints where they fit.

Next: streaming.

Finished reading? Tick it off to track your progress.