> ## Documentation Index
> Fetch the complete documentation index at: https://docs.langchain.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Build checklist for the Graph API

> Decide state, control flow, Send, Command, and node options as you build with the Graph API.

This guide walks through the decisions you make when building a graph. For install and an end-to-end agent example, see the [LangGraph quickstart](https://docs.langchain.com/oss/javascript/langgraph/quickstart.md). For a design walkthrough, see [Thinking in the Graph API](https://docs.langchain.com/oss/javascript/langgraph/thinking-in-graph-api.md). For concepts, see the [Graph API overview](https://docs.langchain.com/oss/javascript/langgraph/graph-api.md).

## Build your graph

Work through these decisions in order. Each step includes a short example and links to the how-to for full recipes.

**1. Define shared state**

Decide what data nodes share and how updates merge.

* Pick a schema (`TypedDict`, dataclass, or `StateSchema` in TypeScript).
* Add a [reducer](https://docs.langchain.com/oss/javascript/langgraph/graph-api.md#reducers) for any key that multiple nodes write (for example, appending messages).
* Use private or input/output schemas when the graph should hide internal channels from callers.

```ts theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
import { StateSchema, ReducedValue } from "@langchain/langgraph";
import * as z from "zod";

const State = new StateSchema({
  foo: z.number(),
  bar: new ReducedValue(
    z.array(z.string()).default(() => []),
    { reducer: (left, right) => left.concat(right) }
  ),
});
```

Here `foo` overwrites. `bar` concatenates.

For schemas, reducers, messages, and private state, see [Define and update state](https://docs.langchain.com/oss/javascript/langgraph/graph-api-state.md).

**2. Choose control flow**

Decide how work moves between nodes.

* **Sequence**: Fixed steps in order.
* **Branch**: Conditional edges pick the next node from state.
* **Parallel**: Fan-out to several nodes, then fan-in (often with reducers).
* **Loop**: Cycle until a termination condition, or cap runs with a [recursion limit](https://docs.langchain.com/oss/javascript/langgraph/graph-api.md#recursion-limit).

This sequence checks whether a number is even, then formats a message:

```ts theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
import {
  END,
  START,
  StateGraph,
  StateSchema,
  type GraphNode,
} from "@langchain/langgraph";
import * as z from "zod";

const State = new StateSchema({
  number: z.number(),
  isEven: z.boolean().optional(),
  message: z.string().optional(),
});

const checkEven: GraphNode<typeof State> = (state) => ({
  isEven: state.number % 2 === 0,
});

const formatMessage: GraphNode<typeof State> = (state) => ({
  message: state.isEven ? "The number is even." : "The number is odd.",
});

const graph = new StateGraph(State)
  .addNode("checkEven", checkEven)
  .addNode("formatMessage", formatMessage)
  .addEdge(START, "checkEven")
  .addEdge("checkEven", "formatMessage")
  .addEdge("formatMessage", END)
  .compile();

await graph.invoke({ number: 7 });
```

For branches, parallel paths, and loops, see [Build sequences, branches, and loops](https://docs.langchain.com/oss/javascript/langgraph/graph-api-control-flow.md).

**3. Decide if you need Send or Command**

Most graphs only need nodes, edges, and conditional edges. Keep routing in edges unless you hit one of the cases below. For patterns and examples, see [Use Send and Command](https://docs.langchain.com/oss/javascript/langgraph/graph-api-send-command.md).

Reach for the extras when the default model is not enough:

* Use [`Send`](https://reference.langchain.com/javascript/langchain-langgraph/index/Send) when you must run the same node once per item, each with its own input, and the item count is only known at runtime (map-reduce / orchestrator-worker).
* Use [`Command`](https://reference.langchain.com/javascript/langchain-langgraph/index/Command) when one step must both update state and choose the next node, resume after an [interrupt](https://docs.langchain.com/oss/javascript/langgraph/interrupts.md), or update state from a tool.

```ts theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
import { Command, Send } from "@langchain/langgraph";

// Send: fan out one worker per item
graph.addConditionalEdges("nodeA", (state) => {
  return state.subjects.map(
    (subject) => new Send("generateJoke", { subject })
  );
});

// Command: update state and route in one return
graph.addNode(
  "myNode",
  (state) => {
    return new Command({
      update: { foo: "bar" },
      goto: "myOtherNode",
    });
  },
  { ends: ["myOtherNode"] }
);
```

**4. Configure nodes as needed**

Add runtime options when reliability or cost matters:

* Retries and timeouts for flaky or slow steps
* Error handlers and graph-wide node defaults
* Caching for expensive repeated work
* Runtime context or config for dependencies that do not belong in state

```ts theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
const graph = new StateGraph(State)
  .addNode("nodeName", nodeFunction, { retryPolicy: {} })
  .compile();
```

See [Configure nodes](https://docs.langchain.com/oss/javascript/langgraph/graph-api-nodes.md).

**5. Visualize the graph**

Render a Mermaid or PNG diagram to review topology and debug routing.

```ts theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
const drawableGraph = await graph.getGraphAsync();
console.log(drawableGraph.drawMermaid());
```

See [Visualize your graph](https://docs.langchain.com/oss/javascript/langgraph/graph-api-visualize.md).

## Next steps

* [Thinking in the Graph API](https://docs.langchain.com/oss/javascript/langgraph/thinking-in-graph-api.md): Design walkthrough with the email agent
* [Graph API overview](https://docs.langchain.com/oss/javascript/langgraph/graph-api.md): Concepts for state, nodes, edges, `Send`, and `Command`
* [Define and update state](https://docs.langchain.com/oss/javascript/langgraph/graph-api-state.md)
* [Build sequences, branches, and loops](https://docs.langchain.com/oss/javascript/langgraph/graph-api-control-flow.md)
* [Use Send and Command](https://docs.langchain.com/oss/javascript/langgraph/graph-api-send-command.md)
* [Configure nodes](https://docs.langchain.com/oss/javascript/langgraph/graph-api-nodes.md)
* [Visualize your graph](https://docs.langchain.com/oss/javascript/langgraph/graph-api-visualize.md)
* [LangGraph quickstart](https://docs.langchain.com/oss/javascript/langgraph/quickstart.md): End-to-end calculator agent

***

[Connect these docs](https://docs.langchain.com/use-these-docs.md) to your agent of choice via MCP for real-time answers.

[Edit this page on GitHub](https://github.com/langchain-ai/docs/edit/main/src/oss/langgraph/use-graph-api.mdx) or [file an issue](https://github.com/langchain-ai/docs/issues/new/choose).
