(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
相关推荐
承渊政道2 天前
LangChainAI应用开发框架【LangChain与LangGraph介绍】
langchain·大模型·langgraph·ai应用开发
专职9 天前
LangGraph写React的Agent并调用远程MCP工具
langgraph
一只游鱼9 天前
langgraph快速入门 —— 从本地脚本到 HTTP 服务
agent·langgraph
寻道码路9 天前
AI Agent 工程化开发实战(五):持久化与断点恢复——Checkpointer 与 Store
人工智能·大模型·checkpoint·持久化·ai agent·langgraph·ai工程化
一只游鱼11 天前
LangGraph快速入门 —— Agent 是怎么转起来的
人工智能·ai·agent·langgraph
专职11 天前
LangGraph持久化机制和可恢复执行:如何让Agent拥有“不死之身”
langgraph
Maiko Star11 天前
LangGraph 环境配置:Miniconda、PyCharm、依赖安装与环境验证
langgraph
小易老师AI实战12 天前
用中间件把任务规划嵌进智能体循环
中间件·状态管理·智能体·工具调用·langgraph·任务规划
lee_curry12 天前
第十周完整学习笔记:继续升级为“检索更准、权限安全、索引可维护、失败可恢复、长期可运行”的企业级 RAG 系统
python·ai·langchain·agent·langgraph
Mr. zhihao12 天前
Deep Agent 架构深度解析:主Agent与子Agent完整交互机制与核心参数作用
python·ai·langgraph·deepagent