Generative AI and Agentic AILangChain 1.4 · LangGraph 1.2 · Python 3.12 or 3.13
Dashboard
0%

Human in the loop

Human in the loop is a pattern in which an agent pauses its run to wait for a person's answer or approval, keeps its state while it waits, and then continues from the same point.

Last updated: 08 Oct, 2026 · LangChain 1.4 · LangGraph 1.2

Some steps should not run unattended: sending an email, moving money, deleting a record. Others need information only a person has. In both cases the agent must stop, ask, and carry on with the answer, without losing its place.

Pausing a run and resuming it

Pausing a workflow for a person · from the Complete Agentic AI Course video · 4:19:43 to 4:22:15

The video draws a chatbot with two tools: a search tool, and a custom tool for human assistance. When the model calls the human tool, the graph stops and waits. A person gives feedback, and the run continues with that feedback as the tool's result. The video's rule of thumb: in a workflow where something must be approved, execution should not complete unless a person says to go ahead.

The model asks for a tool call, the tool calls interrupt, the run pauses with its state saved, a person approves, edits or rejects, and the run resumes with Command resume on the same thread so the tool returns the person's answer.

Two pieces make this work. interrupt(...) pauses the run at that line and hands a value to whoever called the agent. Command(resume=...) starts the run again and becomes the return value of interrupt. Because the paused state has to be stored somewhere until the person answers, the agent needs a checkpointer, and the resume call must use the same thread id.

Asking a person from inside a tool

A human assistance tool with interrupt and Command · from the Complete Agentic AI Course video · 4:22:15 to 4:27:24

The video builds the graph by hand with a search tool and the human tool. The version here gives the same human tool to create_agent; LangGraph essentials builds the graph form by hand. The tool is an ordinary @tool function with one extra line:

python
from langchain.tools import tool
from langgraph.types import Command, interrupt

@tool
def human_assistance(query: str) -> str:
    """Ask a human expert for help when you are not sure."""
    answer = interrupt({"query": query})
    return answer["data"]

The docstring tells the model when to use the tool. interrupt({"query": query}) pauses the run and passes the dictionary out. Whatever the person sends back with Command(resume=...) is returned by interrupt, and the tool returns its "data" field to the model as the tool result.

Resuming without a checkpointer

Without a checkpointer the run still pauses, but the paused state is kept nowhere, so the resume has nothing to continue:

ExampleAPI keyRun on Groq
from langchain.agents import create_agent

agent = create_agent(
    model="groq:openai/gpt-oss-120b",
    tools=[human_assistance],
    system_prompt="For any question about company policy, call human_assistance.",
)
question = {"messages": [{"role": "user", "content": "What is the refund window in our company policy?"}]}

paused = agent.invoke(question)
print("paused:", "__interrupt__" in paused)
try:
    agent.invoke(Command(resume={"data": "Refunds are allowed within 30 days."}))
except RuntimeError as error:
    print(error)

paused: True shows that the run did stop at the interrupt. The resume then raises a RuntimeError whose message names the problem: Command(resume=...) needs a checkpointer.

The agent with a checkpointer

Adding checkpointer=MemorySaver() is the fix. The run now saves its state when it pauses, and the thread id in the config finds it again.

python
from langchain.agents import create_agent
from langgraph.checkpoint.memory import MemorySaver

agent = create_agent(
    model="groq:openai/gpt-oss-120b",
    tools=[human_assistance],
    system_prompt="For any question about company policy, call human_assistance.",
    checkpointer=MemorySaver(),
)
ExampleAPI keyRun on Groq
config = {"configurable": {"thread_id": "help-1"}}
question = {"messages": [{"role": "user", "content": "What is the refund window in our company policy?"}]}

paused = agent.invoke(question, config)
print(paused["__interrupt__"][0].value)
print(agent.get_state(config).next)

final = agent.invoke(Command(resume={"data": "Refunds are allowed within 30 days."}), config)
print(final["messages"][-1].content)
print(agent.get_state(config).next)
  • The interrupt payload. The first call returned without an answer. paused["__interrupt__"][0].value is the dictionary the tool passed to interrupt: the model's question to the person.
  • The paused state. get_state(config).next is ('tools',) while the run waits inside the tools node. After the resume it is an empty tuple, so nothing is left to run.
  • The answer. The final message uses the 30 days the person typed. The model never knew the policy; the person supplied it.
Watch out. When a run resumes, the node that called interrupt runs again from its first line. Any code placed before interrupt in that tool runs twice. Keep side effects, such as writing a file or sending a message, after the interrupt call.

Approving, editing or rejecting a tool call

The human tool asks a person for information. A different need is to let the model choose a tool freely and have a person review the call before it runs. HumanInTheLoopMiddleware does that for the tools you name. When the model asks for one of them, the run pauses with the pending call, and the person answers with one of three decisions:

  • approve runs the call as the model wrote it.
  • edit runs a call the person changed, with new arguments in edited_action.
  • reject does not run the call. The decision's message field tells the model why, so it can explain or try something else.
python
from langchain.agents import create_agent
from langchain.agents.middleware import HumanInTheLoopMiddleware
from langchain.tools import tool
from langgraph.checkpoint.memory import MemorySaver
from langgraph.types import Command

@tool
def send_email(recipient: str, subject: str, body: str) -> str:
    """Send an email."""
    return f"Email sent to {recipient} with subject '{subject}'."
python
agent = create_agent(
    model="groq:openai/gpt-oss-120b",
    tools=[send_email],
    checkpointer=MemorySaver(),
    middleware=[HumanInTheLoopMiddleware(
        interrupt_on={"send_email": {"allowed_decisions": ["approve", "edit", "reject"]}},
    )],
)

One request, three threads, one decision on each. A decision list has one entry for each pending call, and the resume uses Command(resume={"decisions": [...]}):

ExampleAPI keyRun on Groq
request = {"messages": [{"role": "user", "content": "Send an email to john@test.com with subject 'Hello' and body 'How are you?'"}]}
decisions = {
    "approve": {"type": "approve"},
    "edit": {"type": "edit", "edited_action": {"name": "send_email", "args": {
        "recipient": "mary@test.com", "subject": "Hello", "body": "How are you?"}}},
    "reject": {"type": "reject", "message": "Do not email John today."},
}

for name, decision in decisions.items():
    config = {"configurable": {"thread_id": name}}
    paused = agent.invoke(request, config)
    if name == "approve":
        print(paused["__interrupt__"][0].value["action_requests"])
    result = agent.invoke(Command(resume={"decisions": [decision]}), config)
    print(name, "| tool result:", result["messages"][-2].content[:60])
    print("   reply:", result["messages"][-1].content[:100])
  • The pending call. The first call stopped before the tool ran. The interrupt value lists action_requests: the tool name and the arguments the model wrote.
  • approve. The tool ran with the model's arguments and returned the email sentence.
  • edit. The tool result begins with a note that a human reviewer replaced the call before it ran, so the model knows the call it wrote is not the one that executed.
  • reject. The tool did not run. Its result is the rejection together with the message the person wrote, and the model's reply tells the user the email was not sent.

Human as a tool vs approval middleware

Human assistance toolHumanInTheLoopMiddleware
Who starts the pauseThe model, by choosing the human toolThe middleware, when the model picks a listed tool
What the person suppliesInformation the model lacksA decision on a call the model wrote
What the model sees afterwardsThe person's text as a tool resultThe tool's result, an edited call's result, or the rejection message
FitsQuestions only a person can answerActions with side effects

Where you use human in the loop

  • Approvals. Refunds, payments, emails to customers, deployments: a person approves the exact call.
  • Missing facts. The agent reaches a point where only a person knows the answer, such as a policy or an account detail.
  • Review of drafts. A person reads what the agent plans to send and edits the arguments before the tool runs.
Try it yourself
  • In the approval example, reject with no message field and compare the model's reply with the one that carries a message.
  • Add "read_email": False next to send_email in interrupt_on after adding a second tool, and see that only the listed tool pauses.
  • Resume the checkpointed example with a different data text, such as a 14-day window, and check that the final answer follows the text you sent.
PreviousAgent memory

Every expert started right here.