This commit is contained in:
vbarda
2024-12-11 09:24:48 -05:00
parent 8f1db66c17
commit 7144f7db41
4 changed files with 9 additions and 11 deletions
+1 -1
View File
@@ -191,7 +191,7 @@ Graph execution can be resumed using the [Command](../reference/types.md#langgra
The `Command` primitive provides several options to control and modify the graph's state during resumption:
1. **Pass a value to the `interrupt`**: Provide data, such as a user's response, to the graph using `Command(resume=value)`. Execution resumes from the beginning of the node where the `interrupt` was used, however, this time the `interrupt(...)` call will return the value passed in the `Command(resume=value)` instead of pausing the graph. THe `resume` value is only used when using `interrupt` as a breakpoint.
1. **Pass a value to the `interrupt`**: Provide data, such as a user's response, to the graph using `Command(resume=value)`. Execution resumes from the beginning of the node where the `interrupt` was used, however, this time the `interrupt(...)` call will return the value passed in the `Command(resume=value)` instead of pausing the graph. The `resume` value is only used when using `interrupt` as a breakpoint.
```python
# Resume graph execution with the user's input.
+4 -4
View File
@@ -2,7 +2,7 @@
!!! tip "This guide uses the new `interrupt` function."
As of LangGraph 0.2.57, the recommended way to set breakpoints is using the [interrupt](../reference/types.md#langgraph.types.interrupt) function as it significantly simpifies **human-in-the-loop** patterns. Please see the [Breakpoints](breakpoints.md) guide for more information.
As of LangGraph 0.2.57, the recommended way to set breakpoints is using the [interrupt](../reference/types.md#langgraph.types.interrupt) function as it significantly simplifies **human-in-the-loop** patterns. Please see the [Breakpoints](breakpoints.md) guide for more information.
If you're looking for the previous version of this conceptual guide, which relied on static breakpoints and `NodeInterrupt` exception, it is available [here](v0-human-in-the-loop.md).
@@ -164,15 +164,15 @@ def human_review_node(state) -> Command[Literal["call_llm", "run_tool"]]:
review_action, review_data = human_review
# Approve the tool call and continue
if review_data == "approve":
if review_action == "continue":
return Command(goto="run_tool")
# Modify the tool call manually and then continue
elif review_action == "update":
...
updated_msg = get_updated_msg(review_data)
# Remember that modify an existing message you will need
# pass the message with a matching ID.
# Remember that to modify an existing message you will need
# to pass the message with a matching ID.
return Command(goto="run_tool", update={"messages": [updated_message]})
# Give natural language feedback, and then pass that back to the agent
@@ -47,7 +47,7 @@
" review_action, review_data = human_review\n",
" \n",
" # Approve the tool call and continue\n",
" if review_data == \"approve\":\n",
" if review_action == \"continue\":\n",
" return Command(goto=\"run_tool\")\n",
" \n",
" # Modify the tool call manually and then continue\n",
@@ -101,7 +101,7 @@
"metadata": {},
"outputs": [
{
"name": "stdin",
"name": "stdout",
"output_type": "stream",
"text": [
"ANTHROPIC_API_KEY: ········\n"
@@ -177,7 +177,7 @@
"id": "ce0fe2bc-86fc-465f-956c-729805d50404",
"metadata": {},
"source": [
"Run until our breakpoint at `human_feedback` - "
"Run until our breakpoint at `human_feedback`:"
]
},
{
@@ -219,7 +219,7 @@
"id": "28a7d545-ab19-4800-985b-62837d060809",
"metadata": {},
"source": [
"Now, we can just manually update our graph state with with the user input - "
"Now, we can manually update our graph state with the user input:"
]
},
{
@@ -485,8 +485,6 @@
}
],
"source": [
"from langchain_core.messages import HumanMessage\n",
"\n",
"config = {\"configurable\": {\"thread_id\": \"2\"}}\n",
"for event in app.stream(\n",
" {\n",