ScriptsApr 6, 2026·2 min read

LangGraph — Stateful AI Agent Graphs by LangChain

Framework for building stateful, multi-actor AI agent applications as directed graphs. Supports cycles, branching, persistence, and human-in-the-loop patterns. By LangChain. 8,000+ stars.

AG
Agent Toolkit · Community
Quick Use

Use it first, then decide how deep to go

This block should tell both the user and the agent what to copy, install, and apply first.

pip install langgraph
from langgraph.graph import StateGraph, END
from typing import TypedDict

class State(TypedDict):
    messages: list
    next_step: str

def research(state):
    # Agent researches the topic
    return {"messages": state["messages"] + ["Research complete"]}

def write(state):
    # Agent writes based on research
    return {"messages": state["messages"] + ["Article written"]}

graph = StateGraph(State)
graph.add_node("research", research)
graph.add_node("write", write)
graph.add_edge("research", "write")
graph.add_edge("write", END)
graph.set_entry_point("research")

app = graph.compile()
result = app.invoke({"messages": ["Write about AI agents"], "next_step": ""})

Intro

LangGraph is a framework by LangChain for building stateful, multi-actor AI agent applications as directed graphs with 8,000+ GitHub stars. Unlike chain-based approaches, LangGraph supports cycles (agent loops), conditional branching, persistent state, and human-in-the-loop workflows. Define your agent logic as nodes and edges in a graph, and LangGraph handles state management, checkpointing, and error recovery. Best for building complex agent systems with non-linear workflows. Works with: Claude, GPT-4, any LangChain-supported model. Setup time: under 3 minutes.


Core Concepts

State Graph

Define your workflow as a directed graph:

graph = StateGraph(AgentState)
graph.add_node("plan", plan_step)
graph.add_node("execute", execute_step)
graph.add_node("review", review_step)

# Conditional routing
graph.add_conditional_edges("review", decide_next, {
    "revise": "execute",   # Loop back if needs revision
    "approve": END          # Finish if approved
})

Cycles (Agent Loops)

LangGraph supports loops — agents can iterate until satisfied:

plan → execute → review → execute → review → approve → END
                  ↑___________|
                  (revision loop)

Human-in-the-Loop

Pause execution for human approval:

from langgraph.checkpoint import MemorySaver

graph.add_node("human_review", interrupt_before=True)

# Agent pauses here, human reviews, then continues
app = graph.compile(checkpointer=MemorySaver())

Persistence

Checkpoint state for resuming later:

from langgraph.checkpoint.postgres import PostgresSaver

checkpointer = PostgresSaver(connection_string="...")
app = graph.compile(checkpointer=checkpointer)

# Resume from any checkpoint
result = app.invoke(None, config={"thread_id": "task-123"})

Multi-Agent Patterns

# Supervisor pattern: one agent delegates to specialists
supervisor = create_supervisor(
    agents=[researcher, coder, reviewer],
    model="claude-sonnet-4-20250514"
)

# Each agent is a subgraph node
graph.add_node("supervisor", supervisor)
graph.add_node("researcher", researcher_graph)
graph.add_node("coder", coder_graph)

Key Stats

  • 8,000+ GitHub stars
  • By LangChain team
  • Cycles and conditional branching
  • Persistent checkpointing
  • Human-in-the-loop support

FAQ

Q: What is LangGraph? A: LangGraph is a framework for building stateful AI agent applications as directed graphs with support for cycles, branching, persistence, and human-in-the-loop workflows.

Q: Is LangGraph free? A: Yes, open-source under MIT license. LangGraph Platform (managed hosting) is paid.

Q: How is LangGraph different from CrewAI? A: LangGraph uses graph-based control flow with explicit state management. CrewAI uses role-based agents with implicit orchestration. LangGraph offers finer-grained control.


🙏

Source & Thanks

Created by LangChain. Licensed under MIT.

langgraph — ⭐ 8,000+

Thanks to the LangChain team for making complex agent workflows manageable.

Discussion

Sign in to join the discussion.
No comments yet. Be the first to share your thoughts.

Related Assets