Build a workflow
Registering application logic as a step in a stateful workflow.
AI Agents · Function
Adds a named node to a LangGraph.js StateGraph. The node implementation runs when graph execution reaches it and can return updates to the graph state.
In the JavaScript graph builder, addNode registers a named node implementation in a StateGraph. The node can be a function that returns state updates; after adding edges, compile the builder and invoke the resulting graph.
graph.addNode(name, node)| Name | Type | Description |
|---|---|---|
name | string | The node name used to identify the node and reference it from edges. |
node | NodeAction | The node implementation that runs when the graph reaches this node. |
The StateGraph builder, enabling chained graph construction.
import { Annotation, StateGraph, START, END } from "@langchain/langgraph";
const State = Annotation.Root({
result: Annotation<string>(),
});
const node = () => ({ result: "done" });
const graph = new StateGraph(State)
.addNode("node", node)
.addEdge(START, "node")
.addEdge("node", END)
.compile();
console.log(await graph.invoke({}));Defines a state graph, registers a node by name, connects it between START and END, compiles the graph, and invokes it.
Registering application logic as a step in a stateful workflow.
Connecting an agent or tool operation to graph control flow.
Embedding a compiled subgraph when state keys are shared.
StateGraphaddEdgeSTARTcompileinvoke