> ## 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/javascript/langchain/models)和[工具](/oss/javascript/langchain/tools)开始。

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

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

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

<CodeGroup>
  ```bash npm theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
  npm install @langchain/langgraph @langchain/core
  ```

  ```bash pnpm theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
  pnpm add @langchain/langgraph @langchain/core
  ```

  ```bash yarn theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
  yarn add @langchain/langgraph @langchain/core
  ```

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

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

```typescript theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
import { StateSchema, MessagesValue, GraphNode, StateGraph, START, END } from "@langchain/langgraph";

const State = new StateSchema({
  messages: MessagesValue,
});

const mockLlm: GraphNode<typeof State> = (state) => {
  return { messages: [{ role: "ai", content: "hello world" }] };
};

const graph = new StateGraph(State)
  .addNode("mock_llm", mockLlm)
  .addEdge(START, "mock_llm")
  .addEdge("mock_llm", END)
  .compile();

await graph.invoke({ messages: [{ role: "user", content: "hi!" }] });
```

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

## 核心优势

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

* [持久执行](/oss/javascript/langgraph/durable-execution)：构建能够经受故障并可长时间运行的智能体，从上次中断处恢复。
* [人机协作](/oss/javascript/langgraph/interrupts)：通过在任何时间点检查和修改智能体状态来纳入人类监督。
* [全面记忆](/oss/javascript/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/javascript/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>
