Scripts2026年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.

TO
TokRepo精选 · Community
快速使用

先拿来用,再决定要不要深挖

这里应该同时让用户和 Agent 知道第一步该复制什么、安装什么、落到哪里。

pip install langgraph
from langgraph.graph import StateGraph, START, END

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

graph = StateGraph({"messages": list})
graph.add_node("chatbot", chatbot)
graph.add_edge(START, "chatbot")
graph.add_edge("chatbot", END)
app = graph.compile()

介绍

LangGraph is a framework by LangChain for building stateful, multi-actor AI agent applications modeled as graphs. Unlike simple chain-based workflows, LangGraph supports cycles, conditional branching, state persistence, human-in-the-loop interactions, and streaming — essential for production agents. 28,000+ GitHub stars.

Best for: Developers building complex, stateful AI agents that need persistence and human oversight Works with: OpenAI, Anthropic, Google, any LangChain-supported model


Key Concepts

State Graphs

Define agent logic as a directed graph with nodes (functions) and edges (transitions):

graph.add_node("research", research_fn)
graph.add_node("write", write_fn)
graph.add_conditional_edges("research", route_fn, {"done": "write", "more": "research"})

Persistence & Checkpoints

Save and resume agent state across sessions:

from langgraph.checkpoint.memory import MemorySaver
app = graph.compile(checkpointer=MemorySaver())

Human-in-the-Loop

Pause execution for human approval before critical actions:

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

Streaming

Stream intermediate results, tool calls, and token-by-token output.

LangGraph Platform

Deploy agents as scalable APIs with built-in monitoring via LangGraph Cloud.


FAQ

Q: What is LangGraph? A: A LangChain framework for building stateful AI agents as directed graphs, with support for cycles, persistence, human-in-the-loop, and streaming. 28K+ GitHub stars.

Q: Do I need LangChain to use LangGraph? A: LangGraph can work standalone, but integrates seamlessly with LangChain for model providers, tools, and retrievers.


🙏

来源与感谢

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

相关资产