# Command

> **Class** in `@langchain/langgraph`

📖 [View in docs](https://reference.langchain.com/javascript/langchain-langgraph/index/Command)

One or more commands to update the graph's state and send messages to nodes.
Can be used to combine routing logic with state updates in lieu of conditional edges

## Signature

```javascript
class Command
```

## Constructors

- [`constructor()`](https://reference.langchain.com/javascript/langchain-langgraph/index/Command/constructor)

## Properties

- `[COMMAND_SYMBOL]`
- `goto`
- `graph`
- `lc_direct_tool_output`
- `lg_name`
- `resume`
- `update`
- `PARENT`

## Methods

- [`toJSON()`](https://reference.langchain.com/javascript/langchain-langgraph/index/Command/toJSON)

## Examples

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

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

// Define the nodes
const nodeA = async (_state: typeof StateAnnotation.State) => {
  console.log("Called A");
  // this is a replacement for a real conditional edge function
  const goto = Math.random() > .5 ? "nodeB" : "nodeC";
  // note how Command allows you to BOTH update the graph state AND route to the next node
  return new Command({
    // this is the state update
    update: {
      foo: "a",
    },
    // this is a replacement for an edge
    goto,
  });
};

// Nodes B and C are unchanged
const nodeB = async (state: typeof StateAnnotation.State) => {
  console.log("Called B");
  return {
    foo: state.foo + "|b",
  };
}

const nodeC = async (state: typeof StateAnnotation.State) => {
  console.log("Called C");
  return {
    foo: state.foo + "|c",
  };
}

import { StateGraph } from "@langchain/langgraph";

// NOTE: there are no edges between nodes A, B and C!
const graph = new StateGraph(StateAnnotation)
  .addNode("nodeA", nodeA, {
    ends: ["nodeB", "nodeC"],
  })
  .addNode("nodeB", nodeB)
  .addNode("nodeC", nodeC)
  .addEdge("__start__", "nodeA")
  .compile();

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

// Randomly oscillates between
// { foo: 'a|c' } and { foo: 'a|b' }
```

---

[View source on GitHub](https://github.com/langchain-ai/langgraphjs/blob/5e9f3cb532bd006012ec0eab2bb5b005b22c2ebb/libs/langgraph-core/src/constants.ts#L447)