> ## Documentation Index
> Fetch the complete documentation index at: https://cndoc-langchain.site/llms.txt
> Use this file to discover all available pages before exploring further.

# LangGraph 概述

> 使用 LangGraph 掌控能力，设计能够可靠处理复杂任务的智能体

LangGraph 受到众多塑造智能体未来的公司信赖——包括 Klarna、Uber、J.P. Morgan 等——它是一个用于构建、管理和部署长时间运行、有状态智能体的底层编排框架和运行时。

LangGraph 是一个非常底层的框架，完全专注于智能体的**编排**。在使用 LangGraph 之前，我们建议您先熟悉一些用于构建智能体的组件，从[模型](/oss/python/langchain/models)和[工具](/oss/python/langchain/tools)开始。

我们将在整个文档中常用 [LangChain](/oss/python/langchain/overview) 组件来集成模型和工具，但您无需使用 LangChain 即可使用 LangGraph。如果您刚开始接触智能体或希望使用更高层次的抽象，我们建议您使用 LangChain 的[智能体](/oss/python/langchain/agents)，它提供了用于常见 LLM 和工具调用循环的预构建架构。

LangGraph 专注于对智能体编排至关重要的底层能力：持久执行、流式处理、人机协作等。

## <Icon icon="download" size={20} /> 安装

<CodeGroup>
  ```bash pip theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
  pip install -U langgraph
  ```

  ```bash uv theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
  uv add langgraph
  ```
</CodeGroup>

然后，创建一个简单的 hello world 示例：

```python theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
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!"}]})
```

<Tip>
  使用 [LangSmith](/langsmith/home) 来跟踪请求、调试智能体行为并评估输出。设置 `LANGSMITH_TRACING=true` 和您的 API 密钥即可开始。
</Tip>

## 核心优势

LangGraph 为*任何*长时间运行、有状态的工作流或智能体提供底层支持基础设施。LangGraph 不抽象提示词或架构，并提供以下核心优势：

* [持久执行](/oss/python/langgraph/durable-execution)：构建能够经受故障并可长时间运行的智能体，可从上次中断处恢复。
* [人机协作](/oss/python/langgraph/interrupts)：通过在任何时间点检查和修改智能体状态来融入人类监督。
* [全面记忆](/oss/python/concepts/memory)：创建具有短期工作记忆（用于持续推理）和跨会话长期记忆的有状态智能体。
* [使用 LangSmith 调试](/langsmith/home)：通过可视化工具深入洞察复杂智能体行为，这些工具可跟踪执行路径、捕获状态转换并提供详细的运行时指标。
* [生产就绪部署](/langsmith/deployment)：使用专为处理有状态、长时间运行工作流的独特挑战而设计的可扩展基础设施，自信地部署复杂的智能体系统。

## LangGraph 生态系统

虽然 LangGraph 可以独立使用，但它也能与任何 LangChain 产品无缝集成，为开发者提供构建智能体的全套工具。为了提升您的 LLM 应用开发效率，请将 LangGraph 与以下产品搭配使用：

<Columns cols={1}>
  <Card title="LangSmith 可观测性" icon="https://mintcdn.com/other-405835d4/zfoblcQReEYa-is2/images/brand/observability-icon-dark.png?fit=max&auto=format&n=zfoblcQReEYa-is2&q=85&s=a5ea23e3bf9ca95c33f73f9b2c93339d" href="/langsmith/observability" arrow cta="了解更多" width="200" height="200" data-path="images/brand/observability-icon-dark.png">
    在一个地方跟踪请求、评估输出并监控部署。使用 LangGraph 进行本地原型设计，然后通过集成的可观测性和评估功能投入生产，以构建更可靠的智能体系统。
  </Card>

  <Card title="LangSmith 部署" icon="https://mintcdn.com/other-405835d4/zfoblcQReEYa-is2/images/brand/deployment-icon-dark.png?fit=max&auto=format&n=zfoblcQReEYa-is2&q=85&s=3b88c161a1ecff6713c623bfa4f2d6f0" href="/langsmith/deployment" arrow cta="了解更多" width="200" height="200" data-path="images/brand/deployment-icon-dark.png">
    使用专为长时间运行、有状态工作流构建的部署平台，轻松部署和扩展智能体。在团队中发现、重用、配置和共享智能体——并通过 Studio 中的可视化原型设计快速迭代。
  </Card>

  <Card title="LangChain" icon="https://mintcdn.com/other-405835d4/zfoblcQReEYa-is2/images/brand/langchain-icon.png?fit=max&auto=format&n=zfoblcQReEYa-is2&q=85&s=3377e4992cfffbfbbe06886b192014b1" href="/oss/python/langchain/overview" arrow cta="了解更多" width="195" height="195" data-path="images/brand/langchain-icon.png">
    提供集成和可组合组件，以简化 LLM 应用开发。包含构建在 LangGraph 之上的智能体抽象。
  </Card>
</Columns>

## 致谢

LangGraph 的灵感来源于 [Pregel](https://research.google/pubs/pub37252/) 和 [Apache Beam](https://beam.apache.org/)。其公共接口的灵感来自 [NetworkX](https://networkx.org/documentation/latest/)。LangGraph 由 LangChain 的创建者 LangChain Inc 构建，但可以不依赖 LangChain 使用。

***

<div className="source-links">
  <Callout icon="terminal-2">
    [将这些文档连接](/use-these-docs)到 Claude、VSCode 等，通过 MCP 获取实时答案。
  </Callout>

  <Callout icon="edit">
    [在 GitHub 上编辑此页面](https://github.com/langchain-ai/docs/edit/main/src/oss/langgraph/overview.mdx) 或 [提交问题](https://github.com/langchain-ai/docs/issues/new/choose)。
  </Callout>
</div>
