You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Use `respond` when the tool is intentionally a placeholder for human input — for example, an `ask_user` tool that prompts the agent to collect information from the user.
277
+
</Note>
278
+
262
279
## Building the ApprovalCard
263
280
264
-
Here is a full approval card component that handles all three decision types:
281
+
Here is a full approval card component that handles all four decision types:
Copy file name to clipboardExpand all lines: src/oss/langchain/human-in-the-loop.mdx
+59-6Lines changed: 59 additions & 6 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -7,17 +7,18 @@ When a model proposes an action that might require review—for example, writing
7
7
8
8
It does this by checking each tool call against a configurable policy. If intervention is needed, the middleware issues an @[interrupt] that halts execution. The graph state is saved using LangGraph's [persistence layer](/oss/langgraph/persistence), so execution can pause safely and resume later.
9
9
10
-
A human decision then determines what happens next: the action can be approved as-is (`approve`), modified before running (`edit`), or rejected with feedback (`reject`).
10
+
A human decision then determines what happens next: the action can be approved as-is (`approve`), modified before running (`edit`), rejected with feedback (`reject`), or responded to directly (`respond`) for "ask user" style tools.
11
11
12
12
## Interrupt decision types
13
13
14
-
The [middleware](/oss/langchain/middleware/built-in#human-in-the-loop) defines three built-in ways a human can respond to an interrupt:
14
+
The [middleware](/oss/langchain/middleware/built-in#human-in-the-loop) defines four built-in ways a human can respond to an interrupt:
15
15
16
16
| Decision Type | Description | Example Use Case |
@@ -473,6 +474,58 @@ When multiple actions are under review, provide a decision for each action in th
473
474
```
474
475
:::
475
476
477
+
</Tab>
478
+
479
+
<Tabtitle="💬 respond">
480
+
Use `respond` for "ask user" style tools where the tool's real implementation is the human's reply. The `message` content is returned directly as the tool result; the tool itself is not executed.
481
+
482
+
:::python
483
+
```python
484
+
agent.invoke(
485
+
Command(
486
+
# Decisions are provided as a list, one per action under review.
487
+
# The order of decisions must match the order of actions
488
+
# in the interrupt request.
489
+
resume={
490
+
"decisions": [
491
+
{
492
+
"type": "respond",
493
+
# The human's reply, returned directly as the tool result
494
+
"message": "Blue.",
495
+
}
496
+
]
497
+
}
498
+
),
499
+
config=config, # Same thread ID to resume the paused conversation
500
+
version="v2",
501
+
)
502
+
```
503
+
:::
504
+
505
+
:::js
506
+
```typescript
507
+
await agent.invoke(
508
+
new Command({
509
+
// Decisions are provided as a list, one per action under review.
510
+
// The order of decisions must match the order of actions
511
+
// in the interrupt request.
512
+
resume: {
513
+
decisions: [
514
+
{
515
+
type: "respond",
516
+
// The human's reply, returned directly as the tool result
517
+
message: "Blue.",
518
+
}
519
+
]
520
+
}
521
+
}),
522
+
config // Same thread ID to resume the paused conversation
523
+
);
524
+
```
525
+
:::
526
+
527
+
The `message` is returned to the agent as a successful `ToolMessage`. Use `respond` when the tool is intentionally a placeholder for human input—for example, an `ask_user` tool that prompts for clarification.
528
+
476
529
</Tab>
477
530
</Tabs>
478
531
@@ -567,7 +620,7 @@ The middleware defines an `after_model` hook that runs after the model generates
567
620
2. The middleware inspects the response for tool calls.
568
621
3. If any calls require human input, the middleware builds a `HITLRequest` with `action_requests` and `review_configs` and calls @[interrupt].
569
622
4. The agent waits for human decisions.
570
-
5. Based on the `HITLResponse` decisions, the middleware executes approved or edited calls, synthesizes @[ToolMessage]'s for rejected calls, and resumes execution.
623
+
5. Based on the `HITLResponse` decisions, the middleware executes approved or edited calls, synthesizes @[ToolMessage]'s for rejected calls, returns human replies directly as @[ToolMessage]'s for `respond` decisions, and resumes execution.
0 commit comments