What this thread does
Do first: use from langchain.agents.middleware import HumanInTheLoopMiddleware.
When you need it
Use the middleware when a model-proposed tool action needs review before it runs. The page’s execute_sql policy allows approval or rejection while excluding edits.
Steps
1. Import the agent constructor, middleware, and example checkpointer:
from langchain.agents import create_agent
from langchain.agents.middleware import HumanInTheLoopMiddleware
from langgraph.checkpoint.memory import InMemorySaver
2. With the example tools write_file, execute_sql, and read_data available, add this middleware to create_agent’s middleware list:
HumanInTheLoopMiddleware(
interrupt_on={
"write_file": True,
"execute_sql": {"allowed_decisions": ["approve", "reject"]},
"read_data": False,
},
description_prefix="Tool execution pending approval",
)
3. The page's create_agent call uses model="gpt-6.1-sol", tools=[write_file, execute_sql, read_data], and checkpointer=InMemorySaver(). Keep that checkpointer on the agent to save interrupted state. 4. Invoke with config containing configurable and thread_id, and version="v2". The page’s request is “Delete old records from the database”. Inspect print(result.interrupts) for pending actions. 5. Resume the same conversation after the reviewer approves:
from langgraph.types import Command
agent.invoke(
Command(
resume={"decisions": [{"type": "approve"}]}
),
config=config,
version="v2",
)
Check it worked
The page prints result.interrupts with action_requests naming execute_sql and review_configs listing approve and reject. Approval runs the original proposed arguments; rejection skips the call and returns feedback.
Limits
The page does not name a version requirement for this default batched configuration. A checkpointer and a thread ID are required across interrupts. InMemorySaver is for prototyping; production needs persistent storage. Batched decisions must match action order, with a separate decision for each paused action. The execute_sql policy does not permit edits.
Not for: diagnosing invalid HITL configurations that auto-approve tools; see langchain-invalid-hitl-config-auto-approves-tools.
Sources
- Human-in-the-loop, LangChain documentation, read 2026-11-24: "You must configure a checkpointer to persist the graph state across interrupts."
Checked
2026-11-24; read <https://docs.langchain.com/oss/python/langchain/human-in-the-loop.md>; no command was run.
Started from a post by @LangChain, packaged by the editor. Original post