Skip to content

Commit

Permalink
docs: update Command and multi-agent concepts
Browse files Browse the repository at this point in the history
  • Loading branch information
vbarda committed Dec 10, 2024
1 parent fd2f6df commit 5790ccb
Showing 1 changed file with 0 additions and 53 deletions.
53 changes: 0 additions & 53 deletions docs/docs/concepts/low_level.md
Original file line number Diff line number Diff line change
Expand Up @@ -406,59 +406,6 @@ const myNode = (state: typeof StateAnnotation.State) => {
};
```

A `Command` has the following properties:

| Property | Description |
| --- | --- |
| `graph` | Graph to send the command to. Supported values:<br>- `None`: the current graph (default)<br>- `Command.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()`](https://langchain-ai.github.io/langgraphjs/reference/functions/langgraph.interrupt-1.html). |
| `goto` | Can be one of the following:<br>- name of the node to navigate to next (any node that belongs to the specified `graph`)<br>- sequence of node names to navigate to next<br>- [`Send`](https://langchain-ai.github.io/langgraphjs/reference/classes/langgraph.Send.html) object (to execute a node with the input provided)<br>- sequence of `Send` objects<br>If `goto` is not specified and there are no other tasks left in the graph, the graph will halt after executing the current superstep. |

Here's a complete example:

```ts
import { StateGraph, Annotation, Command } from "@langchain/langgraph";

const StateAnnotation = Annotation.Root({
foo: Annotation<string>,
});

const myNode = async (state: typeof StateAnnotation.State) => {
return new Command({
// state update
update: {
foo: "bar",
},
// control flow
goto: "myOtherNode",
});
};

const myOtherNode = async (state: typeof StateAnnotation.State) => {
return {
foo: state.foo + "baz"
};
};

const graph = new StateGraph(StateAnnotation)
.addNode("myNode", myNode, {
// For compiling and validating the graph
ends: ["myOtherNode"],
})
.addNode("myOtherNode", myOtherNode)
.addEdge("__start__", "myNode")
.compile();

await graph.invoke({
foo: "",
});
```

```ts
{ foo: "barbaz" }
```

With `Command` you can also achieve dynamic control flow behavior (identical to [conditional edges](#conditional-edges)):

```ts
Expand Down

0 comments on commit 5790ccb

Please sign in to comment.