Skip to content
masterclassBuddyTech Buzz5 fresh blogs · 5:00 AM IST

AI Agents · Function

add_edge

addEdge adds an unconditional transition between LangGraph.js nodes. Use START and END to define entry and termination, then compile the builder.

How it works

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.

Syntax

addEdge(startKey, endKey)

Parameters

NameTypeDescription
startKeystring | typeof STARTThe source node name, or the virtual START node.
endKeystring | typeof ENDThe destination node name, or the virtual END node.

Returns

The graph builder, allowing chained graph construction.

Key points

  • Use addEdge(source, target) for unconditional routing between two nodes.
  • An edge from START establishes the graph's entry point.
  • Edges determine which node runs next; fixed edges are the non-branching form.
  • The usual construction order is state, nodes, edges, and compilation.

Common mistakes

  • Use addConditionalEdges instead when the next node depends on runtime state; addEdge represents an unconditional transition.

Example: Connect a simple graph

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.

When to use it

Sequential pipelines

Define a linear workflow where each completed node always leads to the same next node.

Graph lifecycle boundaries

Declare the first executable node and the final termination point.

Static workflow topology

Connect parallel branches or converge fixed workflow stages without runtime routing.

Interview questions

QWhat does 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.

QHow do you define graph entry and termination?

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.

QWhen can a fixed edge model a workflow?

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.

  • StateGraph
  • START
  • END
  • addConditionalEdges
  • addNode

Source: Graph API overview - Docs by LangChain. Checked 2026-10-15.