Building Human-in-the-Loop Agentic Workflows with LangGraph
Prompt & Circuit Editorial
May 15, 2026 · 12 Min Read

Why human-in-the-loop still matters
Models can now run long, multi-step tasks with little supervision, but "little supervision" is not the same as "none". Three properties of LLM-based workflows make a human checkpoint worth its cost:
- LLM output is sampled from a probability distribution. It is usually plausible, not guaranteed to be correct.
- Errors compound. When one step's output becomes the next step's input, a small mistake early on can quietly corrupt everything downstream.
- Some actions are expensive or irreversible: sending money, emailing a customer, changing a production system, filing a compliance report. For these, a few seconds of human review is cheap insurance.
The engineering question is not whether to add review, but how to add it without blocking a server thread while someone gets around to clicking "approve". LangGraph answers that with interrupts and checkpointing.
LangGraph in a nutshell
LangGraph is an open-source library from the LangChain team for building stateful agent workflows as graphs. You define:
- a state schema (for example a
TypedDict) that every node can read and update, - nodes, which are ordinary Python functions that take the state and return updates,
- edges, which decide which node runs next (fixed, conditional, or chosen at runtime with
Command(goto=...)).
Two features make human review practical:
- Checkpointers save the graph state after each step, keyed by a
thread_id. - The
interrupt()function pauses a node, saves state, and hands a payload back to the caller. Later, the caller resumes the same thread withCommand(resume=...), and that value becomes the return value ofinterrupt().
Because state is persisted, the pause can last seconds or days, and the process that resumes the graph does not have to be the one that started it.
A working example: an analyst report with an approval gate
The graph below fetches data, asks a model to draft a short risk summary, then pauses for a human. The reviewer can approve the report or send it back with feedback. After two rejected revisions it escalates instead of looping forever.
Install the dependencies (LangGraph 1.x and LangChain's OpenAI integration) and set OPENAI_API_KEY:
pip install -U langgraph "langchain[openai]"
from typing import Literal, TypedDict
from langchain.chat_models import init_chat_model
from langgraph.checkpoint.memory import InMemorySaver
from langgraph.graph import END, START, StateGraph
from langgraph.types import Command, interrupt
model = init_chat_model("gpt-5.5") # any chat model supported by LangChain works
class State(TypedDict, total=False):
ticker: str
prices: list[float]
report: str
feedback: str
revisions: int
status: str
def fetch_prices(state: State) -> dict:
# Stub: replace with your market-data client.
return {"prices": [189.2, 191.0, 187.4, 183.9, 186.5]}
def analyze(state: State) -> dict:
prompt = (
f"Write a five-line risk summary for {state['ticker']} "
f"based on these daily closing prices: {state['prices']}."
)
if state.get("feedback"):
prompt += f"\nRevise using this reviewer feedback: {state['feedback']}"
return {"report": model.invoke(prompt).text}
def human_review(state: State) -> Command[Literal["deliver", "analyze", "escalate"]]:
# Execution stops here; the dict is surfaced to the caller under "__interrupt__".
decision = interrupt({"question": "Approve this report?", "report": state["report"]})
if decision.get("approved"):
return Command(goto="deliver")
if state.get("revisions", 0) >= 2:
return Command(goto="escalate")
return Command(
goto="analyze",
update={"feedback": decision.get("feedback", ""),
"revisions": state.get("revisions", 0) + 1},
)
def deliver(state: State) -> dict:
# Send by email, Slack, etc. Runs only after approval.
return {"status": "delivered"}
def escalate(state: State) -> dict:
return {"status": "escalated to a senior reviewer"}
builder = StateGraph(State)
builder.add_node("fetch", fetch_prices)
builder.add_node("analyze", analyze)
builder.add_node("review", human_review)
builder.add_node("deliver", deliver)
builder.add_node("escalate", escalate)
builder.add_edge(START, "fetch")
builder.add_edge("fetch", "analyze")
builder.add_edge("analyze", "review")
builder.add_edge("deliver", END)
builder.add_edge("escalate", END)
graph = builder.compile(checkpointer=InMemorySaver())
if __name__ == "__main__":
config = {"configurable": {"thread_id": "report-AAPL-001"}}
result = graph.invoke({"ticker": "AAPL", "revisions": 0}, config)
while "__interrupt__" in result:
payload = result["__interrupt__"][0].value
print("\n=== REPORT PREVIEW ===\n" + payload["report"])
if input("\nApprove? (y/n): ").strip().lower() == "y":
resume = {"approved": True}
else:
resume = {"approved": False, "feedback": input("What should change? ")}
result = graph.invoke(Command(resume=resume), config)
print("Final status:", result["status"])
What is happening here
fetchandanalyzerun normally, and the checkpointer saves state after each step.reviewcallsinterrupt(). The graph stops, andgraph.invokereturns the state with an__interrupt__entry that carries the payload.- The caller shows the report to a person and resumes the same
thread_idwithCommand(resume=...). reviewruns again from the top; this timeinterrupt()returns the resume value, and the node routes withCommand(goto=...)todeliver, back toanalyze, or toescalate.
The input() loop is only a stand-in. In a real system the first call would run in a worker, the payload would be written to a review queue or UI, and a separate request handler would call graph.invoke(Command(resume=...), config) when the reviewer clicks a button.
Rules that trip people up
The LangGraph documentation calls out several behaviours worth knowing before you go to production:
- The node restarts on resume. Code before
interrupt()runs again when the graph resumes. Keep anything above the interrupt idempotent, or move side effects into a separate node or after the interrupt. - Do not wrap
interrupt()in a broadtry/except. The pause is implemented by raising an exception, so a bareexceptswallows it. - Keep interrupt order stable. Resume values are matched to interrupts by position within a node, so do not skip interrupts conditionally or call them a varying number of times.
- Pass JSON-serialisable payloads. No functions or class instances in the interrupt value.
- Resume with the same
thread_id. A new thread starts a new run. - Use a durable checkpointer.
InMemorySaverkeeps checkpoints in RAM, so they disappear when the process restarts. For production, use a database-backed saver such asPostgresSaverfrom thelanggraph-checkpoint-postgrespackage.
Design practices for review steps
- Make pending approvals visible. Surface waiting threads in a queue or dashboard rather than in logs, and show which node is waiting and why.
- Show the reviewer less, not more. Put a validation node before the human step that checks numeric ranges, required fields and formats, so the reviewer sees a short, pre-checked summary instead of raw model output.
- Ask for the rationale. Have the model state the evidence behind each claim. Unsupported reasoning is easier to spot than an unsupported conclusion.
- Bound the loop. As in the example, cap revisions and route to an escalation path instead of letting a reject-revise cycle run forever.
- Add time limits outside the graph. LangGraph will wait indefinitely for a resume; reminders and timeouts belong in your queue or scheduler, which can resume the thread with a default decision if needed.
- Use two reviewers for high-risk actions. A second approval step removes a single point of failure.
- Version prompts and graph changes. Treat prompt edits like code changes so you can trace a regression to a specific revision.
- Keep an audit trail. Persist every payload, decision, reviewer identity and timestamp. The checkpointer's history helps, but compliance usually needs its own log.
Scaling the pattern
The graph code does not change much when you move from one analyst to a team. The infrastructure around it does:
- A durable checkpointer (Postgres or similar) so any worker can resume any thread.
- A review front end that lists interrupted threads and posts decisions back to an API that calls
Command(resume=...). - A queue or workflow scheduler for notifications, reminders and timeouts.
- An audit store for approvals, rejections and the model output each decision was based on.
Summary
- LLM agents are useful but probabilistic, so put human checkpoints in front of costly or irreversible actions.
- In LangGraph,
interrupt()pauses a node and persists state;Command(resume=...)continues the same thread with the human's decision. - Remember that the node re-executes on resume, avoid broad exception handlers around the interrupt, and use a durable checkpointer in production.
- Keep review steps visible, concise, bounded and audited.
Sources
Responses (0)
Sign in to join the conversation and share your thoughts.

Prompt & Circuit Editorial
Contributing Editor
Articles on AI infrastructure for cloud architects, written from official vendor sources and checked claim by claim before publishing.
Continue Reading

Implementing Hybrid Semantic and Lexical Search for RAG with BM25 and Reciprocal Rank Fusion
Dense embeddings miss exact identifiers and BM25 misses paraphrases. This walk-through combines both in Python with rank_bm25, sentence-transformers and Reciprocal Rank Fusion, and explains the trade-offs before you move it to a search engine.

Demystifying LangChain Models: From LLMs to Embeddings in Plain English
A plain-English guide to LangChain's model layer: chat models, legacy text-completion LLMs, embedding models, invoke(), key parameters, and how embeddings power semantic search, with code for the current LangChain 1.x APIs.

MCPRoute on Application Gateway for Containers: One Governed Front Door for MCP Servers
Application Gateway for Containers can now route and aggregate Model Context Protocol servers running in Kubernetes. Here is what the preview changes, where it stops, and what to check before adopting it.