(LangGraph教程)6. Deployment部署——Lesson 1(2):创建部署(未索引)

https://academy.langchain.com/courses/intro-to-langgraph

https://github.com/shangxiang0907/langchain-academy

文章目录

  • [Creating a deployment 创建部署](#Creating a deployment 创建部署)
    • [Code structure 代码结构](#Code structure 代码结构)
    • [CLI 命令行界面(CLI)](#CLI 命令行界面(CLI))
      • [Build Docker Image for LangGraph Server 为 LangGraph 服务器构建 Docker 镜像](#Build Docker Image for LangGraph Server 为 LangGraph 服务器构建 Docker 镜像)
      • [Set Up Redis and PostgreSQL 设置 Redis 和 PostgreSQL](#Set Up Redis and PostgreSQL 设置 Redis 和 PostgreSQL)

Creating a deployment 创建部署

Let's create a deployment of the task_maistro app that we created in module 5.

让我们为我们在模块 5 中创建的 task_maistro 应用创建一个部署。

Code structure 代码结构

The following information should be provided to create a LangGraph Platform deployment:

以下信息应被提供,以创建 LangGraph 平台部署:

  • A LangGraph API Configuration file - langgraph.json

  • The graphs that implement the logic of the application - e.g., task_maistro.py

    • 实现应用逻辑的图(graph)------例如,task_maistro.py
  • A file that specifies dependencies required to run the application - requirements.txt

    • 指定运行应用所需依赖项的文件 --- requirements.txt
  • Supply environment variables needed for the application to run - .env or docker-compose.yml

    • 提供应用运行所需的环境变量 --- .env 或 docker-compose.yml

We have this already in the module-6/deployment directory!

这些文件我们已在 module-6/deployment 目录中准备就绪!

CLI 命令行界面(CLI)

The LangGraph CLI is a command-line interface for creating a LangGraph Platform deployment.

LangGraph CLI 是用于创建 LangGraph 平台部署的命令行接口。

python 复制代码
%%capture --no-stderr
%pip install -U langgraph-cli

To create a self-hosted deployment, we'll follow a few steps.

为创建 自托管部署,我们将按几个步骤操作。

Build Docker Image for LangGraph Server 为 LangGraph 服务器构建 Docker 镜像

We first use the langgraph CLI to create a Docker image for the LangGraph Server.

我们首先使用 langgraph CLI 为 LangGraph 服务器 创建一个 Docker 镜像。

This will package our graph and dependencies into a Docker image.

该操作会将我们的图及其依赖项打包进一个 Docker 镜像。

A Docker image is a template for a Docker container that contains the code and dependencies required to run the application.

Docker 镜像是 Docker 容器的模板,其中包含运行应用所需的代码和依赖项。

Ensure that Docker is installed and then run the following command to create the Docker image, my-image:

请确保已安装 Docker,然后运行以下命令创建名为 my-image 的 Docker 镜像:

复制代码
$ cd module-6/deployment
$ langgraph build -t my-image

Set Up Redis and PostgreSQL 设置 Redis 和 PostgreSQL

If you already have Redis and PostgreSQL running (e.g., locally or on other servers), then create and run the LangGraph Server container by itself with the URIs for Redis and PostgreSQL:

如果你已有正在运行的 Redis 和 PostgreSQL(例如,在本地或其他服务器上),则可 单独 创建并运行 LangGraph 服务器容器,并传入 Redis 和 PostgreSQL 的 URI。

复制代码
docker run \
    --env-file .env \
    -p 8123:8000 \
    -e REDIS_URI="foo" \
    -e DATABASE_URI="bar" \
    -e LANGSMITH_API_KEY="baz" \
    my-image

Alternatively, you can use the provided docker-compose.yml file to create three separate containers based on the services defined:

或者,你可以使用提供的 docker-compose.yml 文件,基于所定义的服务创建三个独立的容器:

  • langgraph-redis: Creates a new container using the official Redis image.

    • langgraph-redis:使用官方 Redis 镜像创建新容器。
  • langgraph-postgres: Creates a new container using the official Postgres image.

    • langgraph-postgres:使用官方 Postgres 镜像创建新容器。
  • langgraph-api: Creates a new container using your pre-built image.

    • langgraph-api:使用你预先构建的镜像创建新容器。

Simply copy the docker-compose-example.yml and add the following environment variables to run the deployed task_maistro app:

只需复制 docker-compose-example.yml,并添加以下环境变量,即可运行已部署的 task_maistro 应用:

  • IMAGE_NAME (e.g., my-image)

  • LANGSMITH_API_KEY

  • OPENAI_API_KEY

Then, launch the deployment!

然后,启动部署!

复制代码
$ cd module-6/deployment
$ docker compose up
相关推荐
梦想不只是梦与想9 小时前
LangGraph的运行时:编译、执行与持久化(三)
大模型·langgraph·checkpointer
lee_curry10 小时前
第七周主题:LangGraph Tool Agent 高级能力
python·agent·langgraph
Dontla14 小时前
(LangGraph教程)3. UX and Human-in-the-Loop——Lesson 5:Time travel时间旅行(未索引)
langgraph
Dontla14 小时前
(LangGraph教程)3. UX and Human-in-the-Loop——Lesson 1: Streaming流式传输(未索引)
langgraph
Dontla15 小时前
(LangGraph教程)3. UX and Human-in-the-Loop-——Lesson 2:Breakpoints断点(未索引)
langgraph
L@ncor2 天前
第六章 框架开发实践 · 学习笔记(AutoGen / AgentScope / CAMEL / LangGraph)
python·框架·autogen·langgraph·agentscope
L@ncor2 天前
第六章可能出现的问题:依赖冲突与成本乘法
python·依赖管理·langgraph·agentscope·避坑
Java的搬运工3 天前
2026 AI Agent 实战:五层架构、MCP 工具调用与十条避坑清单 合集 - AI行业观察
人工智能·架构·智能体·大模型应用·langgraph·aiagent·mcp
梦想不只是梦与想3 天前
LangGraph图:State、Node、Edge(一)
langchain·大模型·langgraph