Skills2026年3月30日·1 分钟阅读

LangGraph — Build Stateful AI Agents as Graphs

LangChain framework for building resilient, stateful AI agents as graphs. Supports cycles, branching, persistence, human-in-the-loop, and streaming. 28K+ stars.

Agent 就绪

Agent 可直接安装

这个资产可安装;Agent 先选择当前运行时、检查安装计划,再运行匹配命令。

Native · 98/100策略:允许
Agent 入口
任意 MCP/CLI Agent
类型
Skill
安装
Single
信任
信任等级:Established
入口
LangGraph — Build Stateful AI Agents as Graphs
直接安装命令
npx -y tokrepo@latest install cc1a6ed2-0d82-4379-94f4-15632b4d4967 --target codex

先 dry-run 确认安装计划,再运行此命令。

TL;DR
LangGraph models AI agents as stateful graphs with cycles, branching, persistence, and human-in-the-loop. The go-to framework for production-grade LangChain agents.
§01

Why graphs beat chains for agents

LangChain's original Chain abstraction assumed linear sequences: step A → step B → step C. But real AI agents loop ("retry until valid"), branch ("if answer is long, summarize"), and wait ("ask human for approval"). LangGraph drops the linear assumption and models agents as directed graphs with state, borrowing from dataflow systems and actor models.

§02

The hello world

from langgraph.graph import StateGraph, START, END
from typing import TypedDict, List

class State(TypedDict):
    messages: List[str]

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

graph = StateGraph(State)
graph.add_node("chatbot", chatbot)
graph.add_edge(START, "chatbot")
graph.add_edge("chatbot", END)
app = graph.compile()

The state flows through nodes. Each node mutates or enriches state. Edges route based on conditions you define.

§03

Core features that make it production-ready

Persistence

State is automatically checkpointed. If a node crashes mid-execution, you resume from the last checkpoint. Supports PostgreSQL, SQLite, and Redis checkpointers.

Human-in-the-loop

interrupt_before and interrupt_after pause execution at any node, waiting for external input (approval, edit, rejection) before continuing.

Streaming

Stream state updates, tokens, or both. Built-in support for Server-Sent Events (SSE) means your UI updates in real time as the agent works.

Time travel

Replay past executions with different inputs. Critical for debugging complex multi-step agents.

§04

LangGraph vs LangChain (the relationship)

LangChain is the library of building blocks (LLM wrappers, tool schemas, prompt templates). LangGraph is the orchestrator for connecting those blocks into a running agent. Since 2024 LangChain's official recommendation for agents has been "use LangGraph, not Chains."

§05

Real-world patterns

Pattern 1: ReAct agent with validation loop

plan → execute tool → validate output → [loop back to plan if invalid]

Pattern 2: Multi-agent team with supervisor

supervisor → {researcher | coder | reviewer} → supervisor → END

Pattern 3: Human approval gate

research → draft → interrupt_before(publish) → publish | reject → END

Pattern 4: Parallel branch + merge

research → {search_google, search_docs, search_memory} → merge → synthesize
§06

Deployment options

  1. LangGraph Cloud (LangChain-hosted) — $39/mo starting, includes observability.
  2. Self-hosted via Docker — single-command deploy, Postgres checkpointer recommended.
  3. Inline in your app — just pip install langgraph, compile your graph, call .invoke() or .stream().
§07

Observability via LangSmith

Every node execution is traced in LangSmith (LangChain's observability platform). Token usage, latency, tool calls — all visible in a timeline view. Costs $0 for small projects, scales with usage.

§08

When LangGraph is overkill

If your agent is:

  • 1 tool call and done — use the provider SDK directly
  • A single LLM completion — use LangChain's simpler LLMChain
  • Purely reactive (no state) — use an event queue

But once you need retries, branching, or human intervention, LangGraph pays off fast.

常见问题

When should I use LangGraph vs LangChain?+

Use LangChain for the building blocks — LLM wrappers, tool definitions, prompt templates. Use LangGraph to orchestrate those blocks into agents with loops, branching, or human approval. Since 2024 LangChain's official recommendation for any non-trivial agent is to use LangGraph rather than the deprecated Chain abstractions.

Does LangGraph support persistence across restarts?+

Yes. State is automatically checkpointed between nodes, with backends for PostgreSQL, SQLite, and Redis. If a node crashes or your server restarts, the agent resumes from the last checkpoint rather than from scratch.

How does human-in-the-loop work?+

Use interrupt_before or interrupt_after on any node. Execution pauses, returns control to your application, and resumes when you provide input. This is how you build approval gates, edit-then-continue flows, or rejection branches.

What observability does LangGraph provide?+

Every node execution is automatically traced to LangSmith when a LANGCHAIN_API_KEY is set. You get token usage, latency per node, tool call traces, and a timeline view. LangSmith has a free tier for small projects.

Can LangGraph run without LangChain?+

Yes, technically. LangGraph only depends on langchain-core (which is lightweight). You can model any stateful graph without using LangChain's full LLM or prompt abstractions. However, most users pair the two.

引用来源 (3)
🙏

来源与感谢

Created by LangChain. Licensed under MIT. langchain-ai/langgraph — 28,000+ GitHub stars

讨论

登录后参与讨论。
还没有评论,来写第一条吧。

相关资产