Definition

LangGraph is a low-level orchestration framework for building stateful, multi-actor applications with LLMs. It models execution as a directed graph over shared state, providing native support for cycles (loops), persistence, and human-in-the-loop (HIL) interactions.

In 2026, LangGraph is the industry standard for moving beyond linear chains into complex agentic workflows.


The Core Model: Graphs Over State

Unlike linear pipelines, LangGraph relies on three primitives:

  1. State: A typed schema (usually a TypedDict or Zod object) that is shared and mutated by all nodes.
  2. Nodes: Functions that receive the current state and return a partial update to the state.
  3. Edges: Direct or conditional transitions between nodes.

Applied Tutorial: Persistent Support Agent

This project builds a customer support agent that can remember conversation history across sessions and pause for human approval on sensitive actions.

1. Environment Setup

npm install @langchain/langgraph @langchain/openai @langchain/core

2. Define the State

The state defines what the agent "knows" at any point.

import { Annotation } from "@langchain/langgraph";
import { BaseMessage } from "@langchain/core/messages";

const AgentState = Annotation.Root({
  messages: Annotation<BaseMessage[]>({
    reducer: (x, y) => x.concat(y),
    default: () => [],
  }),
  requires_approval: Annotation<boolean>(),
});

3. Implement Nodes

Nodes are asynchronous functions that perform work.

const callModel = async (state: typeof AgentState.State) => {
  const response = await model.invoke(state.messages);
  return { messages: [response] };
};

const humanApproval = async (state: typeof AgentState.State) => {
  // This node is a "wait" state. It doesn't actually execute logic
  // but acts as a target for a breakpoint.
  return { requires_approval: false };
};

4. Compose the Graph

Define the flow and conditional logic.

import { StateGraph, START, END } from "@langchain/langgraph";

const workflow = new StateGraph(AgentState)
  .addNode("agent", callModel)
  .addNode("approval", humanApproval)
  .addEdge(START, "agent");

// Conditional routing: if model wants to call a tool, go to approval
workflow.addConditionalEdges("agent", (state) => {
  const lastMsg = state.messages[state.messages.length - 1];
  if (lastMsg.tool_calls?.length > 0) return "approval";
  return END;
});

workflow.addEdge("approval", "agent");

5. Compile with Persistence

Checkpointers enable durable execution (resuming after a crash or a pause).

import { MemorySaver } from "@langchain/langgraph";

const checkpointer = new MemorySaver();
const app = workflow.compile({ 
  checkpointer,
  interruptBefore: ["approval"] // Pause before this node
});

6. Execute with Thread ID

const config = { configurable: { thread_id: "user-123" } };

// First run: Agent reaches the breakpoint and pauses
await app.invoke({ messages: [{ role: "user", content: "Refund order #55" }] }, config);

// Later: Human "approves" by continuing execution
await app.invoke(null, config);

Why use LangGraph for this?

  1. Durable State: By providing a thread_id, you can resume a conversation days later; the state is automatically reloaded from the checkpointer.
  2. Control: You decide exactly when the agent loops and when it stops for human intervention.
  3. Observability: Integrates natively with LangSmith to visualize the exact path taken through the graph.

Production Heuristics

1. Minimize State Size

Only store what is necessary for the next node's decision. For large documents, store a reference (ID) and fetch the content inside the node.

2. Use "Short-term" vs "Long-term" Memory

LangGraph handles short-term (checkpointed) memory. Use an external database (Postgres/Redis) to load long-term user preferences into the state at START.

3. Implement Token Budgets

Agents can loop infinitely if not bounded. Add a loop_count to your state and use a conditional edge to force END if it exceeds a threshold (e.g., 5 iterations).

4. Prefer Managed Checkpointers

In production, replace MemorySaver with SqliteSaver or PostgresSaver to ensure state survives container restarts.


References

  1. LangGraph JS Documentation — langchain-ai.github.io/langgraphjs/
  2. Persistence & Checkpointing — langchain-ai.github.io/langgraphjs/how-tos/persistence/
  3. Multi-Agent Systems Guide — langchain-ai.github.io/langgraphjs/concepts/multi_agent/