Skip to content

Commit 90e2ac4

Browse files
committed
eugene feedback
1 parent f953984 commit 90e2ac4

1 file changed

Lines changed: 18 additions & 12 deletions

File tree

β€Žsrc/oss/langgraph/graph-api.mdxβ€Ž

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1052,7 +1052,7 @@ graph.addConditionalEdges("nodeA", (state) => {
10521052

10531053
- **[Return from nodes](#return-from-nodes)**: Use `update`, `goto`, and `graph` to combine state updates with control flow.
10541054
- **[Input to `invoke`/`stream`](#input-to-invokestream)**: Use `resume` to continue execution after an interrupt.
1055-
- **[Return from tools](#return-from-tools)**: Use `update` to modify graph state from inside a tool.
1055+
- **[Return from tools](#return-from-tools)**: Similar to return from nodes, combine state updates and control flow from inside a tool.
10561056

10571057
### Return from nodes
10581058

@@ -1086,8 +1086,6 @@ Use @[`Command`] when you need to **both** update state **and** route to a diffe
10861086

10871087
When returning @[`Command`] in your node functions, you must add return type annotations with the list of node names the node is routing to, e.g. `Command[Literal["my_other_node"]]`. This is necessary for the graph rendering and tells LangGraph that `my_node` can navigate to `my_other_node`.
10881088

1089-
@[`Command`] only adds dynamic edges β€” static edges defined with `add_edge` still execute. For example, if `node_a` returns `Command(goto="my_other_node")` and you also have `graph.add_edge("node_a", "node_b")`, both `node_b` and `my_other_node` will run.
1090-
10911089
</Note>
10921090

10931091
:::
@@ -1130,13 +1128,13 @@ builder.addNode("myNode", myNode, {
11301128
});
11311129
```
11321130

1133-
<Note>
1131+
:::
11341132

1135-
@[`Command`] only adds dynamic edges β€” static edges defined with `addEdge` still execute. For example, if `nodeA` returns `new Command({ goto: "myOtherNode" })` and you also have `graph.addEdge("nodeA", "nodeB")`, both `nodeB` and `myOtherNode` will run.
1133+
<Warning>
11361134

1137-
</Note>
1135+
@[`Command`] only adds dynamic edges β€” static edges defined with `add_edge` / `addEdge` still execute. For example, if `node_a` returns `Command(goto="my_other_node")` and you also have `graph.add_edge("node_a", "node_b")`, both `node_b` and `my_other_node` will run.
11381136

1139-
:::
1137+
</Warning>
11401138

11411139
Check out this [how-to guide](/oss/langgraph/use-graph-api#combine-control-flow-and-state-updates-with-command) for an end-to-end example of how to use @[`Command`].
11421140

@@ -1197,10 +1195,11 @@ This is particularly useful when implementing [multi-agent handoffs](/oss/langch
11971195

11981196
<Warning>
11991197

1200-
`Command(resume=...)` is the **only** `Command` pattern intended as input to `invoke()`/`stream()`. Do not use `Command(update=...)` as input to continue multi-turn conversations β€” because passing any `Command` as input resumes from the last checkpoint position (skipping `__start__`), the graph will appear stuck. To continue a conversation on an existing thread, pass a plain input dict:
1198+
`Command(resume=...)` is the **only** `Command` pattern intended as input to `invoke()`/`stream()`. Do not use `Command(update=...)` as input to continue multi-turn conversations β€” because passing any `Command` as input resumes from the latest checkpoint (i.e. the last step that ran, not `__start__`), the graph will appear stuck if it already finished. To continue a conversation on an existing thread, pass a plain input dict:
12011199

12021200
```python
1203-
# WRONG β€” graph resumes from end state, appears stuck
1201+
# WRONG β€” graph resumes from the latest checkpoint
1202+
# (last step that ran), appears stuck
12041203
graph.invoke(Command(update={ # [!code --]
12051204
"messages": [{"role": "user", "content": "follow up"}] # [!code --]
12061205
}), config) # [!code --]
@@ -1219,10 +1218,11 @@ graph.invoke( { # [!code ++]
12191218

12201219
<Warning>
12211220

1222-
`new Command({ resume: ... })` is the **only** `Command` pattern intended as input to `invoke()`/`stream()`. Do not use `new Command({ update: ... })` as input to continue multi-turn conversations β€” because passing any `Command` as input resumes from the last checkpoint position (skipping `__start__`), the graph will appear stuck. To continue a conversation on an existing thread, pass a plain input object:
1221+
`new Command({ resume: ... })` is the **only** `Command` pattern intended as input to `invoke()`/`stream()`. Do not use `new Command({ update: ... })` as input to continue multi-turn conversations β€” because passing any `Command` as input resumes from the latest checkpoint (i.e. the last step that ran, not `__start__`), the graph will appear stuck if it already finished. To continue a conversation on an existing thread, pass a plain input object:
12231222

12241223
```typescript
1225-
// WRONG β€” graph resumes from end state, appears stuck
1224+
// WRONG β€” graph resumes from the latest checkpoint
1225+
// (last step that ran), appears stuck
12261226
await graph.invoke(new Command({ update: { messages: [{ role: "user", content: "follow up" }] } }), config); // [!code --]
12271227

12281228
// CORRECT β€” plain object restarts from __start__
@@ -1284,7 +1284,13 @@ Check out the [interrupts conceptual guide](/oss/langgraph/interrupts) for full
12841284

12851285
### Return from tools
12861286

1287-
A common use case is updating graph state from inside a tool. For example, in a customer support application you might want to look up customer information based on their account number or ID in the beginning of the conversation.
1287+
You can return @[`Command`] from tools to update graph state and control flow. Use `update` to modify state (e.g., saving customer information looked up during a conversation) and `goto` to route to a specific node after the tool completes.
1288+
1289+
<Warning>
1290+
1291+
When used inside tools, `goto` adds a dynamic edge β€” any static edges already defined on the node that called the tool will still execute.
1292+
1293+
</Warning>
12881294

12891295
Refer to [this guide](/oss/langgraph/use-graph-api#use-inside-tools) for detail.
12901296

0 commit comments

Comments
Β (0)