Sequential pipelines
Define a linear workflow where each completed node always leads to the same next node.
AI Agents · Function
addEdge adds an unconditional transition between LangGraph.js nodes. Use START and END to define entry and termination, then compile the builder.
In a LangGraph.js StateGraph, addEdge creates a fixed transition from one node to another. Use START to define the graph entry point and END to terminate execution; after adding nodes and edges, compile the builder before invoking the resulting graph.
addEdge(startKey, endKey)| Name | Type | Description |
|---|---|---|
startKey | string | typeof START | The source node name, or the virtual START node. |
endKey | string | typeof END | The destination node name, or the virtual END node. |
The graph builder, allowing chained graph construction.
addEdge(source, target) for unconditional routing between two nodes.START establishes the graph's entry point.import { END, START, StateGraph, StateSchema } from "@langchain/langgraph";
const State = new StateSchema({ value: z.number() });
const builder = new StateGraph(State)
.addNode("step", (state) => ({ value: state.value + 1 }))
.addEdge(START, "step")
.addEdge("step", END);
const graph = builder.compile();
const result = await graph.invoke({ value: 0 });
console.log(result.value);Creates a graph with one node, connects the virtual start and end nodes, compiles it, and invokes it.
Define a linear workflow where each completed node always leads to the same next node.
Declare the first executable node and the final termination point.
Connect parallel branches or converge fixed workflow stages without runtime routing.
addEdge do?addEdge defines a fixed transition: after the source node completes, the destination node is scheduled. It is appropriate when routing does not depend on state.
Follow-up: How would you route based on state? Use addConditionalEdges with a routing function rather than a fixed edge.
Connect START to the first node and connect the final node to END. These virtual nodes define where execution enters and exits the graph.
Follow-up: What happens if the graph has no outgoing work? Execution halts when there are no more nodes to execute.
The builder is configured with nodes and edges, then compiled into an executable graph. The compiled graph is what you invoke with input state.
Follow-up: What can be used for a multi-step sequence? Add consecutive fixed edges, such as step1 to step2 and then step2 to step3.
StateGraphSTARTENDaddConditionalEdgesaddNode