mirror of
https://github.com/langchain-ai/langgraph.git
synced 2026-09-02 14:28:46 +02:00
x
This commit is contained in:
@@ -14,24 +14,24 @@ A **human-in-the-loop** (or "on-the-loop") workflow integrates human input into
|
||||
Key use cases for **human-in-the-loop** workflows in LLM-based applications include:
|
||||
|
||||
1. **🛠️ [Reviewing tool calls](#reviewing-tool-calls)**: Humans can review, edit, or approve tool calls requested by the LLM before tool execution.
|
||||
2. **✅ Validating LLM outputs**: Ensure accuracy by reviewing, editing, or approving the LLM's generated outputs.
|
||||
3. **💡 Providing context**: Enable the LLM to explicitly request human input for clarification or additional details, improving decision-making and accuracy.
|
||||
4. **🔍 Debugging**: Investigate and correct errors in the LLM's decision-making process. This is mostly developer facing.
|
||||
|
||||
2. **✅ Validating LLM outputs**: Ensure accuracy by reviewing, editing, or approving content generated by the LLM.
|
||||
3. **💡 Providing context**: Enable the LLM to explicitly request human input for clarification or additional details.
|
||||
4. **🔍 Debugging**: Investigate and correct errors in the LLM's decision-making process.
|
||||
|
||||
## Interrupt & Resume
|
||||
|
||||
**Human-in-the-loop** works in the following manner:
|
||||
|
||||
1. [**Persistence**](./persistence.md): the graph state is saved after each graph step, enabling **pausing** and **resuming** execution.
|
||||
2. [**Interrupting execution**](#interrupting-execution): the [`interrupt`](../reference/types.md#langgraph.types.interrupt) function is used to **pause** the graph at specific points for user input.
|
||||
2. [**Interrupting execution**](#interrupting-execution): the [`interrupt`](../reference/types.md#langgraph.types.interrupt) function is used to **pause** the graph at specific points for **human input**.
|
||||
3. [**Running the graph**](#run): the graph is executed until it reaches the **breakpoint**.
|
||||
4. [**Resuming execution**](#resuming-execution): the [`Command`](../reference/types.md#langgraph.types.Command) primitive allows **resuming** execution based on user input.
|
||||
4. [**Resuming execution**](#resuming-execution): the [`Command`](../reference/types.md#langgraph.types.Command) primitive allows **resuming** execution based on **human input**.
|
||||
|
||||
> **Note:** While there are other ways to set breakpoints (e.g., static breakpoints or dynamic exceptions) and resume execution (e.g., by relying on state updates `graph.update_state`), this guide focuses on the `interrupt` function and `Command` primitive as the recommended methods.
|
||||
|
||||
### Interrupt
|
||||
|
||||
Use the [interrupt](../reference/types.md/#langgraph.types.interrupt) function to **pause** the graph at specific points to collect user input. The `interrupt` function surfaces interrupt information to the client, allowing you to collect user input, validate the graph state, or make decisions before resuming execution. The graph must be compiled with a [checkpointer](./persistence.md) to maintain state persistence.
|
||||
Use the [interrupt](../reference/types.md/#langgraph.types.interrupt) function to **pause** the graph at specific points to collect user input. The `interrupt` function surfaces interrupt information to the client, allowing you to collect user input, validate the graph state, or make decisions before resuming execution. The graph must be compiled with a [checkpointer](./persistence.md) so graph execution can be paused and resumed.
|
||||
|
||||
```python
|
||||
from langgraph.types import interrupt
|
||||
@@ -87,7 +87,7 @@ for event in graph.stream(inputs, thread_config, stream_mode="values"):
|
||||
|
||||
??? note "Using with `invoke` and `ainvoke`"
|
||||
|
||||
`invoke` and `ainvoke` do not return the interrupt information. To access this information, you must use the `get_state` method to retrieve the graph state after calling `invoke` or `ainvoke`.
|
||||
`invoke` and `ainvoke` do not return the interrupt information. To access this information, you must use the [get_state](../reference/graphs.md#langgraph.graph.graph.CompiledGraph.get_state) method to retrieve the graph state after calling `invoke` or `ainvoke`.
|
||||
|
||||
```python
|
||||
# Run the graph up to the breakpoint
|
||||
@@ -112,6 +112,10 @@ You should see the following output printed by to the `print` function in the `n
|
||||
Value received from interrupt: {'age': '25'}
|
||||
```
|
||||
|
||||
## Resuming Execution
|
||||
|
||||
Execution is always resumed from the **beginning** of the **graph node** where the `interrupt` was used.
|
||||
|
||||
## Options for resuming execution
|
||||
|
||||
After an `interrupt`, graph execution can be resumed using the [Command](../reference/types.md#langgraph.types.Command) primitive. The `Command` primitive provides several options to control and modify the graph's state during resumption:
|
||||
|
||||
Reference in New Issue
Block a user