LangGraph 概览与生态:定位、全家桶与 Hello World
本文是《LangGraph 文档精读:完整知识总结》系列第 01 篇,内容来自 LangGraph 官方文档(docs.langchain.com/oss/python/langgraph/)实抓精读。
本篇结构速览
LangGraph 文档精读:完整知识总结
来源:https://docs.langchain.com/oss/python/langgraph/ 官方文档(2026-08-22 实抓精读)
涵盖页面:overview、pregel、thinking-in-langgraph、workflows-agents、persistence、checkpointers、add-memory、stores、streaming、event-streaming、interrupts(=human-in-the-loop)、fault-tolerance
第一部分:LangGraph 概览(Overview)
1.1 LangGraph 是什么
“Gain control with LangGraph to design agents that reliably handle complex tasks”
LangGraph 是一个低层(low-level)编排框架和运行时,用于构建、管理和部署长时间运行、有状态(stateful)的 Agent。被 Klarna、Uber、J.P. Morgan 等公司采用。
核心定位:
- 低层:专注 Agent 编排(orchestration),不抽象 prompt 或架构
- 细粒度控制:在同一个图(graph)里混合确定性的手写步骤与LLM 驱动的智能体步骤
- 有状态:支持持久化、流式、人工介入(human-in-the-loop)等生产级能力
⚠️ 重要:LangGraph 不依赖 LangChain——可以用 LangChain 组件集成模型和工具,但不是必须。
1.2 产品生态定位(LangChain 全家桶)
| 产品 | 定位 |
|---|---|
| Deep Agents | Agent harness:规划、子 Agent、文件系统工具、上下文管理(构建在 LangGraph 之上) |
| LangChain | Agent 框架:模型、工具、Agent 循环的抽象与集成 |
| LangGraph | 编排运行时:持久化执行、流式、人工介入、持久化 |
| LangSmith | 平台:追踪、评测、prompt 管理、跨框架部署 |
| LangSmith Engine | 检测 LangGraph agent 追踪中的问题并提议修复(可一键开 PR) |
| LangSmith Fleet | 无代码 Agent 构建器:模板、集成、日常自动化 |
1.3 安装与 Hello World
pip install -U langgraph
# 或 uv add langgraph
最简单的图:
from langgraph.graph import StateGraph, MessagesState, START, END
def mock_llm(state: MessagesState):
return {"messages": [{"role": "ai", "content": "hello world"}]}
graph = StateGraph(MessagesState)
graph.add_node(mock_llm)
graph.add_edge(START, "mock_llm")
graph.add_edge("mock_llm", END)
graph = graph.compile()
graph.invoke({"messages": [{"role": "user", "content": "hi!"}]})
1.4 六大核心收益
- 混合确定性与智能体步骤:手写逻辑(可靠性、可审计)+ LLM 决策(灵活性)在同一图中,精确控制 AI 用在哪儿
- 持久化(Persistence):Agent 能扛住失败、长时间运行,从断点恢复
- 人工介入(Human-in-the-loop):随时检查/修改 Agent 状态
- 全面记忆(Comprehensive memory):短期工作记忆(当前推理)+ 长期跨会话记忆
- LangSmith 调试:可视化追踪执行路径、状态转换、运行时指标
- 生产级部署:为有状态长运行工作流设计的可扩展基础设施
1.5 设计来源
- 受 Pregel(Google 图计算系统)和 Apache Beam 启发
- 公共接口受 NetworkX(Python 图库)启发

288

被折叠的 条评论
为什么被折叠?



