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

# 应用结构

LangGraph 应用由一个或多个图、一个配置文件（`langgraph.json`）、一个指定依赖项的文件以及一个可选的指定环境变量的 `.env` 文件组成。

本指南展示了应用的典型结构，并向你说明如何提供所需配置以使用 [LangSmith 部署](/langsmith/deployment)来部署应用。

<Info>
  LangSmith 部署是一个用于部署和扩展 LangGraph 智能体的托管平台。它处理基础设施、扩展和运维事务，让你可以直接从仓库部署有状态的、长时间运行的智能体。更多信息请参阅[部署文档](/langsmith/deployment)。
</Info>

## 核心概念

要使用 LangSmith 进行部署，需要提供以下信息：

1. 一个 [LangGraph 配置文件](#configuration-file-concepts)（`langgraph.json`），指定应用所使用的依赖项、图和环境变量。
2. 实现应用逻辑的[图](#graphs)。
3. 一个指定运行应用所需[依赖项](#dependencies)的文件。
4. 应用运行所需的[环境变量](#environment-variables)。

## 文件结构

以下是应用目录结构的示例：

<Tabs>
  <Tab title="Python (requirements.txt)">
    ```plaintext theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
    my-app/
    ├── my_agent # 所有项目代码都在此目录下
    │   ├── utils # 图的工具类
    │   │   ├── __init__.py
    │   │   ├── tools.py # 图的工具
    │   │   ├── nodes.py # 图的节点函数
    │   │   └── state.py # 图的状态定义
    │   ├── __init__.py
    │   └── agent.py # 构建图的代码
    ├── .env # 环境变量
    ├── requirements.txt # 包依赖
    └── langgraph.json # LangGraph 配置文件
    ```
  </Tab>

  <Tab title="Python (pyproject.toml)">
    ```plaintext theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
    my-app/
    ├── my_agent # 所有项目代码都在此目录下
    │   ├── utils # 图的工具类
    │   │   ├── __init__.py
    │   │   ├── tools.py # 图的工具
    │   │   ├── nodes.py # 图的节点函数
    │   │   └── state.py # 图的状态定义
    │   ├── __init__.py
    │   └── agent.py # 构建图的代码
    ├── .env # 环境变量
    ├── langgraph.json  # LangGraph 配置文件
    └── pyproject.toml # 项目依赖
    ```
  </Tab>
</Tabs>

<Note>
  LangGraph 应用的目录结构可能因编程语言和包管理器的不同而有所变化。
</Note>

<a id="configuration-file-concepts" />

## 配置文件

`langgraph.json` 文件是一个 JSON 文件，指定部署 LangGraph 应用所需的依赖项、图、环境变量和其他设置。

有关 JSON 文件中所有支持的键的详细信息，请参阅 [LangGraph 配置文件参考](/langsmith/cli#configuration-file)。

<Tip>
  [LangGraph CLI](/langsmith/cli) 默认使用当前目录中的配置文件 `langgraph.json`。
</Tip>

### 示例

* 依赖项包括一个自定义本地包和 `langchain_openai` 包。
* 将从文件 `./your_package/your_file.py` 中加载一个图，变量为 `variable`。
* 环境变量从 `.env` 文件加载。

```json theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
{
  "dependencies": ["langchain_openai", "./your_package"],
  "graphs": {
    "my_agent": "./your_package/your_file.py:agent"
  },
  "env": "./.env"
}
```

## 依赖项

LangGraph 应用可能依赖其他 Python 包。

通常你需要指定以下信息才能正确设置依赖项：

1. 目录中的一个文件，用于指定依赖项（例如 `requirements.txt`、`pyproject.toml` 或 `package.json`）。

2. [LangGraph 配置文件](#configuration-file-concepts)中的 `dependencies` 键，指定运行 LangGraph 应用所需的依赖项。

3. 任何额外的二进制文件或系统库可以使用 [LangGraph 配置文件](#configuration-file-concepts)中的 `dockerfile_lines` 键来指定。

## 图

使用 [LangGraph 配置文件](#configuration-file-concepts)中的 `graphs` 键来指定在已部署的 LangGraph 应用中可用的图。

你可以在配置文件中指定一个或多个图。每个图通过名称（必须唯一）和路径来标识，路径指向：(1) 已编译的图或 (2) 创建图的函数。

## 环境变量

如果你在本地使用已部署的 LangGraph 应用，可以在 [LangGraph 配置文件](#configuration-file-concepts)的 `env` 键中配置环境变量。

对于生产部署，你通常需要在部署环境中配置环境变量。

***

<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/application-structure.mdx)或[提交 issue](https://github.com/langchain-ai/docs/issues/new/choose)。
  </Callout>
</div>
