LangGraph API Cheat Sheet
This quick reference guide summarizes the core API methods when building state machines with LangGraph.
1. Graph Setup Operators Reference
| Method | Target Behavior | Code Example |
addNode | Register a new worker node function | .addNode("nodeName", nodeFunc) |
addEdge | Connect two nodes in a normal sequence | .addEdge("fromNode", "toNode") |
addConditionalEdges | Route dynamically based on status output | .addConditionalEdges("node", conditionFunc, routesMap) |
setEntryPoint | Define the entry node of the graph | .setEntryPoint("firstNode") |
2. Shared State Annotation Declaration
Use Annotation.Root to declare properties and reducer logic:
import { Annotation } from "@langchain/langgraph";
const StateAnnotation = Annotation.Root({
messages: Annotation<any[]>({
reducer: (current, update) => current.concat(update),
default: () => [],
}),
isApproved: Annotation<boolean>(),
});3. Human-in-the-Loop API Reference
interruptBefore: Compile option key to halt execution before a node runs.
const app = workflow.compile({ checkpointer, interruptBefore: ["nodeName"] });getState(config): Retrieve the state values at the active checkpoint.updateState(config, values): Modify the state values of a specific thread or checkpoint.getStateHistory(config): Load the list of all historical checkpoints stored for a thread.
Published on Last updated: