# Nodes and edges

Nodes are functions that do one step. Edges say which node runs next.

AI developers · Part 06: LangChain / LangGraph · Card 9 of 14 · Last updated 2026-10-13

## Analogy

Route handlers and the router config that wires them together.

## Code example

`graph.ts`

```typescript
import { StateGraph, MessagesAnnotation, START, END } from "@langchain/langgraph";

const graph = new StateGraph(MessagesAnnotation)
  .addNode("router", routerNode)
  .addNode("docsAgent", docsAgentNode)
  .addNode("ticketsAgent", ticketsAgentNode)
  .addEdge(START, "router")
  .addConditionalEdges("router", (state) => state.route, ["docsAgent", "ticketsAgent"])
  .addEdge("docsAgent", END)
  .addEdge("ticketsAgent", END)
  .compile({ checkpointer });
```

## In an agent

Seeing the control flow as a graph makes multi-step agents much easier to debug.

## Questions people ask

### What are nodes and edges in LangGraph?

Nodes are functions that each do one step, such as calling the model or running tools. Edges say which node runs next. You add nodes with addNode, connect them with addEdge, and mark the START and END. The result is the agent's control flow drawn as a graph you can read and debug.

### Why model an agent as a graph?

A graph makes the control flow visible. You can see every step and every possible path, test nodes one at a time, and find where a run went wrong. A plain loop is fine for simple agents, but routers, approvals and retries are much easier to follow as a graph.

## Related concepts

- [LangGraph.js](https://studyvisually.com/learn/tech/ai-developers/langchain-langgraph/langgraph)
- [Graph state](https://studyvisually.com/learn/tech/ai-developers/langchain-langgraph/graph-state)
- [Conditional edges](https://studyvisually.com/learn/tech/ai-developers/langchain-langgraph/conditional-edges)
- [createReactAgent](https://studyvisually.com/learn/tech/ai-developers/langchain-langgraph/create-react-agent)

Web page: https://studyvisually.com/learn/tech/ai-developers/langchain-langgraph/nodes-and-edges
Study this card in the app: https://studyvisually.com/app/learn?category=ai-developers&card=nodes-and-edges
