# 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. ## Install Save as a script file and run: ## Quick Use ```bash pip install langgraph ``` ```python 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: ```python 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: ```python 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: ```python 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 ```python # 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](https://github.com/langchain-ai). Licensed under MIT. > > [langgraph](https://github.com/langchain-ai/langgraph) — ⭐ 8,000+ Thanks to the LangChain team for making complex agent workflows manageable. --- ## 快速使用 ```bash pip install langgraph ``` ```python from langgraph.graph import StateGraph, END graph = StateGraph(State) graph.add_node("research", research_fn) graph.add_node("write", write_fn) graph.add_edge("research", "write") graph.add_edge("write", END) app = graph.compile() ``` --- ## 简介 LangGraph 是 LangChain 团队开发的状态化 AI Agent 图框架,GitHub 8,000+ stars。支持循环、条件分支、持久状态和人在环路工作流。适合构建非线性工作流的复杂 Agent 系统。 --- ## 来源与感谢 > Created by [LangChain](https://github.com/langchain-ai). Licensed under MIT. > > [langgraph](https://github.com/langchain-ai/langgraph) — ⭐ 8,000+ --- Source: https://tokrepo.com/en/workflows/dbf0bc9a-0bb1-4efb-a033-3bdd498f6a63 Author: Agent Toolkit