HumanInTheLoopMiddleware(
self,
interrupt_on: dict[str, bool | InterruptOnConfig],
*,
description_prefix: Logic to run before the agent execution starts.
Async logic to run before the agent execution starts.
Logic to run before the model is called.
Async logic to run before the model is called.
Intercept and control model execution via handler callback.
Intercept and control async model execution via handler callback.
Logic to run after the agent execution completes.
Async logic to run after the agent execution completes.
| Name | Type | Description |
|---|---|---|
interrupt_on* | dict[str, bool | InterruptOnConfig] | Mapping of tool name to allowed actions. If a tool doesn't have an entry, it's auto-approved by default.
|
description_prefix | str | Default: 'Tool execution requires approval'The prefix to use when constructing action requests. This is used to provide context about the tool call and the action being requested. Not used if a tool has a |
edit_notice | str | None | Default: _EDIT_NOTICE |
interrupt_mode | InterruptMode | Default: 'batched' |
| Name | Type |
|---|---|
| interrupt_on | dict[str, bool | InterruptOnConfig] |
| description_prefix | str |
| edit_notice | str | None |
| interrupt_mode | InterruptMode |
Pause the agent so a person can review tool calls before they run.
Each tool in interrupt_on needs a decision before it runs: approve, edit, reject,
or respond. The pause is a LangGraph interrupt, so the agent needs a checkpointer,
and the run continues with Command(resume=...).
interrupt_mode sets how the agent pauses:
"batched" (default): one interrupt per model turn. Its value is a HITLRequest
listing every gated call, answered with a HITLResponse whose decisions match
the calls by position."per_call": one interrupt per gated tool call, as the call starts. Its value is
a ToolApprovalRequest and its response_schema lists the decisions that tool
allows. Each is answered with a single Decision keyed by interrupt ID, and
LangGraph checks the answer against the schema before saving it. "per_call"
is planned to become the default in the next major release.Text prepended to the result of a tool call a reviewer replaced
via an edit decision. Pass None to add nothing.
How the agent pauses for review.
"batched" (default): one interrupt per model turn for all gated
tool calls, answered with a HITLResponse."per_call": one ToolApprovalRequest interrupt per gated tool
call, with a typed response_schema, answered with a single
Decision keyed by interrupt ID.In per_call mode, LangGraph checks each answer before saving it:
args_schema run when the tool
does. For a tool whose arguments are a JSON schema rather than a
Pydantic model, edits are shown in response_schema but not
checked.pydantic.ValidationError and isn't
saved, so the same interrupt can be answered again.If one of several answers sent together is invalid, the others'
tools may already have run even if they still show as pending,
and answering them again would run them twice. Check answers
against response_schema before sending them together, or send
one at a time.
per_call modeThe review happens as the tool call starts, inside the tool-call
middleware chain. List this middleware before tool retry or
error-handling middleware so it wraps them, and don't enable it
on subclasses that raise their own interrupts in after_model.
On resume, each paused tool call runs the middleware listed
before this one again up to the pause, so that middleware must
not have side effects before calling handler. The tool itself
runs only after the answer.
As in batched mode, running the agent asynchronously (ainvoke,
astream) needs Python 3.11 or later.