From 1eeb90ae0d77bbe280df85c620dbbccd16323367 Mon Sep 17 00:00:00 2001 From: vbarda Date: Wed, 4 Dec 2024 19:31:46 -0500 Subject: [PATCH] cr --- docs/docs/concepts/low_level.md | 14 ++++++++------ docs/docs/reference/types.md | 1 + libs/langgraph/langgraph/types.py | 6 ++++-- 3 files changed, 13 insertions(+), 8 deletions(-) diff --git a/docs/docs/concepts/low_level.md b/docs/docs/concepts/low_level.md index b3df3c882..1d059568b 100644 --- a/docs/docs/concepts/low_level.md +++ b/docs/docs/concepts/low_level.md @@ -344,9 +344,9 @@ def my_node(state: State) -> Command[Literal["my_other_node"]]: | Property | Description | | --- | --- | | `graph` | Graph to send the command to. Supported values:
- `None`: the current graph (default)
- `Command.PARENT`: closest parent graph | -| `update` | State update to apply to the graph's state at the current superstep | -| `resume` | Value to resume execution with. Will be used when `interrupt()` is called | -| `goto` | Can be one of the following:
- name of the node to navigate to next (any node that belongs to the specified `graph`)
- list of node names to navigate to next
- `Send` object
- sequence of `Send` objects
If `goto` is not specified and there are no other tasks left in the graph, the graph will halt after executing the current superstep. | +| `update` | Update to apply to the graph's state. | +| `resume` | Value to resume execution with. To be used together with [`interrupt()`][langgraph.types.interrupt]. | +| `goto` | Can be one of the following:
- name of the node to navigate to next (any node that belongs to the specified `graph`)
- sequence of node names to navigate to next
- `Send` object (to execute a node with the input provided)
- sequence of `Send` objects
If `goto` is not specified and there are no other tasks left in the graph, the graph will halt after executing the current superstep. | ```python from langgraph.graph import StateGraph, START @@ -373,13 +373,15 @@ graph = builder.compile() With `Command` you can also achieve dynamic control flow behavior (identical to [conditional edges](#conditional-edges)): ```python -def my_node(state: State) -> Command[Literal["my_other_node", "__end__"]]: +def my_node(state: State) -> Command[Literal["my_other_node"]]: if state["foo"] == "bar": return Command(update={"foo": "baz"}, goto="my_other_node") - else: - return Command(goto="__end__") ``` +!!! important + + 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["node_b", "node_c"]]`. This is necessary for the graph compilation and rendering, and tells LangGraph that `node_a` can navigate to `node_b` and `node_c`. + Check out this [how-to guide](../how-tos/command.ipynb) for an end-to-end example of how to use `Command`. ## Persistence diff --git a/docs/docs/reference/types.md b/docs/docs/reference/types.md index 98b1ef137..b42b11f35 100644 --- a/docs/docs/reference/types.md +++ b/docs/docs/reference/types.md @@ -14,3 +14,4 @@ - StateSnapshot - Send - Command + - interrupt diff --git a/libs/langgraph/langgraph/types.py b/libs/langgraph/langgraph/types.py index 1780c0a7f..d4fb5ab55 100644 --- a/libs/langgraph/langgraph/types.py +++ b/libs/langgraph/langgraph/types.py @@ -249,13 +249,15 @@ class Command(Generic[N]): Args: graph: graph to send the command to. Supported values are: + - None: the current graph (default) - GraphCommand.PARENT: closest parent graph update: update to apply to the graph's state. - resume: value to resume execution with. To be used together with `interrupt()`. + resume: value to resume execution with. To be used together with [`interrupt()`][langgraph.types.interrupt]. goto: can be one of the following: + - name of the node to navigate to next (any node that belongs to the specified `graph`) - - list of node names to navigate to next + - sequence of node names to navigate to next - `Send` object (to execute a node with the input provided) - sequence of `Send` objects """