Nodes and edges
Nodes are functions that do one step. Edges say which node runs next.
Last updated
Analogy
Route handlers and the router config that wires them together.
Code example
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.