这是用户在 2025-8-7 15:08 为 https://docs.langchain.com/langgraph-platform/application-structure 保存的双语快照页面,由 沉浸式翻译 提供双语支持。了解如何保存?

Overview  概述

A LangGraph application consists of one or more graphs, a configuration file (langgraph.json), a file that specifies dependencies, and an optional .env file that specifies environment variables.
一个 LangGraph 应用程序由一个或多个图、一个配置文件( langgraph.json )、一个指定依赖关系的文件,以及一个可选的 .env 文件(指定环境变量)组成。
This guide shows a typical structure of an application and shows how the required information to deploy an application using the LangGraph Platform is specified.
本指南展示了应用程序的典型结构,并说明了如何使用 LangGraph 平台指定部署应用程序所需的信息。

Key Concepts  关键概念

To deploy using the LangGraph Platform, the following information should be provided:
要使用 LangGraph 平台进行部署,应提供以下信息:
  1. A LangGraph configuration file (langgraph.json) that specifies the dependencies, graphs, and environment variables to use for the application.
    一个 LangGraph 配置文件( langgraph.json ),用于指定应用程序所需的依赖项、图和环境变量。
  2. The graphs that implement the logic of the application.
    实现应用程序逻辑的图。
  3. A file that specifies dependencies required to run the application.
    一个指定运行应用程序所需依赖项的文件。
  4. Environment variables that are required for the application to run.
    应用程序运行所需的环境变量。

File Structure  文件结构

Below are examples of directory structures for Python and JavaScript applications:
以下是一些 Python 和 JavaScript 应用程序的目录结构示例:
my-app/
├── my_agent # all project code lies within here
│   ├── utils # utilities for your graph
│   │   ├── __init__.py
│   │   ├── tools.py # tools for your graph
│   │   ├── nodes.py # node functions for your graph
│   │   └── state.py # state definition of your graph
│   ├── __init__.py
│   └── agent.py # code for constructing your graph
├── .env # environment variables
├── requirements.txt # package dependencies
└── langgraph.json # configuration file for LangGraph
The directory structure of a LangGraph application can vary depending on the programming language and the package manager used.
LangGraph 应用程序的目录结构可能因编程语言和所使用的包管理器而异。

Configuration File  配置文件

The langgraph.json file is a JSON file that specifies the dependencies, graphs, environment variables, and other settings required to deploy a LangGraph application.
langgraph.json 文件是一个 JSON 文件,用于指定部署 LangGraph 应用所需的依赖项、图、环境变量和其他设置。
See the LangGraph configuration file reference for details on all supported keys in the JSON file.
有关 JSON 文件中所有支持键的详细信息,请参阅 LangGraph 配置文件参考。
The LangGraph CLI defaults to using the configuration file langgraph.json in the current directory.
LangGraph CLI 默认使用当前目录中的配置文件 langgraph.json

Examples  示例

  • The dependencies involve a custom local package and the langchain_openai package.
    依赖项包括一个自定义本地包和 langchain_openai 包。
  • A single graph will be loaded from the file ./your_package/your_file.py with the variable variable.
    一个图将从文件 ./your_package/your_file.py 加载,变量为 variable
  • The environment variables are loaded from the .env file.
    环境变量从 .env 文件加载。
{
    "dependencies": [
        "langchain_openai",
        "./your_package"
    ],
    "graphs": {
        "my_agent": "./your_package/your_file.py:agent"
    },
    "env": "./.env"
}

Dependencies  依赖项

A LangGraph application may depend on other Python packages or JavaScript libraries (depending on the programming language in which the application is written).
一个 LangGraph 应用程序可能依赖于其他 Python 包或 JavaScript 库(具体取决于应用程序所编写的编程语言)。
You will generally need to specify the following information for dependencies to be set up correctly:
为了正确设置依赖项,您通常需要指定以下信息:
  1. A file in the directory that specifies the dependencies (e.g. requirements.txt, pyproject.toml, or package.json).
    一个指定依赖项的文件(例如 requirements.txtpyproject.tomlpackage.json )。
  2. A dependencies key in the LangGraph configuration file that specifies the dependencies required to run the LangGraph application.
    LangGraph 配置文件中的一个 dependencies 键,用于指定运行 LangGraph 应用所需的依赖项。
  3. Any additional binaries or system libraries can be specified using dockerfile_lines key in the LangGraph configuration file.
    任何额外的二进制文件或系统库都可以使用 dockerfile_lines 键在 LangGraph 配置文件中指定。

Graphs  

Use the graphs key in the LangGraph configuration file to specify which graphs will be available in the deployed LangGraph application.
在 LangGraph 配置文件中使用 graphs 键指定部署的 LangGraph 应用中将可用的图。
You can specify one or more graphs in the configuration file. Each graph is identified by a name (which should be unique) and a path for either: (1) the compiled graph or (2) a function that makes a graph is defined.
您可以在配置文件中指定一个或多个图。每个图由一个名称(应唯一)和一个路径标识,该路径可以是:(1) 编译后的图或(2) 定义图的函数。

Environment Variables  环境变量

If you’re working with a deployed LangGraph application locally, you can configure environment variables in the env key of the LangGraph configuration file.
如果您在本地使用部署的 LangGraph 应用,可以在 LangGraph 配置文件的 env 键中配置环境变量。
For a production deployment, you will typically want to configure the environment variables in the deployment environment.
对于生产部署,您通常需要在部署环境中配置环境变量。