Open SourcePythonTypeScript

LangGraph

by LangChain Inc.Updated Jun 15, 2025

Graph-based framework for building stateful, multi-actor LLM applications with cycles, controllability, and persistence. LangGraph models agent workflows as state machines where nodes are functions and edges define transitions, including conditional routing. It provides built-in checkpointing, human-in-the-loop support, and seamless LangSmith integration for debugging.

Architecture Overview

LangGraph represents agent logic as a directed graph (StateGraph) where nodes are Python functions that read and write to a shared state object. Edges connect nodes and can be conditional, allowing dynamic routing based on state. The graph compiles into a runnable that executes nodes in topological order, supporting cycles for iterative agent loops. A checkpointer persists state between runs, enabling human-in-the-loop workflows and fault tolerance.

When to Use LangGraph

  • Complex multi-step agent workflows with branching logic
  • Human-in-the-loop approval and review systems
  • Stateful conversational agents with memory
  • Multi-agent systems with supervisor patterns
  • Production RAG pipelines with agentic retrieval

Strengths & Weaknesses

Strengths

  • Fine-grained control over execution flow via graph structure
  • Built-in persistence and checkpointing for fault tolerance
  • Excellent debugging and observability with LangSmith
  • Supports complex patterns: cycles, branching, parallel execution
  • First-class streaming support for real-time applications

Weaknesses

  • Steeper learning curve than simpler frameworks
  • Graph abstraction can feel verbose for simple agents
  • Tightly coupled with the LangChain ecosystem

Quick Start

python
from typing import Annotated, TypedDict
from langgraph.graph import StateGraph, START, END
from langgraph.graph.message import add_messages
from langgraph.prebuilt import ToolNode, tools_condition
from langchain_openai import ChatOpenAI
from langchain_core.tools import tool

@tool
def get_weather(city: str) -> str:
    """Get the current weather for a city."""
    return f"Sunny, 72°F in {city}"

class State(TypedDict):
    messages: Annotated[list, add_messages]

llm = ChatOpenAI(model="gpt-4o").bind_tools([get_weather])

def chatbot(state: State):
    return {"messages": [llm.invoke(state["messages"])]}

# Build the graph with conditional tool routing
graph = StateGraph(State)
graph.add_node("chatbot", chatbot)
graph.add_node("tools", ToolNode([get_weather]))
graph.add_edge(START, "chatbot")
graph.add_conditional_edges("chatbot", tools_condition)
graph.add_edge("tools", "chatbot")

app = graph.compile()
result = app.invoke({"messages": [{"role": "user", "content": "What's the weather in Tokyo?"}]})
print(result["messages"][-1].content)

Features at a Glance

DeveloperLangChain Inc.
LanguagePython, TypeScript
LicenseMIT
GitHub Stars8k+
MCP SupportYes
Multi-AgentYes

Notable Users

ElasticReplitRakutenLangChain

Resources

Explore Related Content