LangChain LangGraph
Module 1 Module 2 Module 3 Module 4 Module 5 Module 6
Module 6 · Production
1 6-1 Creating
2 6-2 Connecting
3 6-3 Double Texting
4 6-4 Assistant
HomeLangGraphModule 6 · Production6-1 Creating
📓 Notebook 📖 Explained
LANGGRAPH MODULE 6 · LESSON 1

Creating a Deployment

From native map code to production-grade LangGraph Platform deployment - in-depth explanation of 4 necessary files, LangGraph CLI build process, Docker containerization and docker-compose multi-service orchestration.

1LangGraph Platform deployment overview

LangGraph Platform is provided by LangChain for applying LangGraphDeployed as a production-grade serviceplatform. It provides REST API interface, persistent storage, streaming output support, and conversation thread management capabilities.

This section is built with Module 5task_mAIstroTake the application as an example to show how to package and deploy a local map code as a service that can be accessed externally.

LangGraph Platform deployment architecture
┌─────────────────────────────────────────────┐
│ LangGraph Server (API) │ ← Process HTTP requests and manage threads
├─────────────────────────────────────────────┤
│ task_mAIstro Graph (your business logic) │ ← Load from Python file
├─────────────────────────────────────────────┤
PostgreSQLRedis
│ Persistence checkpointer │ Message Queue/Cache │
└─────────────────────────────────────────────┘
Why you need LangGraph Platform

When running the graph locally, the state is stored in memory (InMemoryStore), the data disappears when the process is restarted and cannot be accessed by other clients. LangGraph Platform packages graphs as HTTP services, uses PostgreSQL for persistent storage, and Redis for message queues. It supportsMulti-user, multi-thread, disconnection and reconnectionproduction scene.

24 necessary documents explained in detail

To create a LangGraph Platform deployment, you need tomodule-6/deployment/Prepare the following 4 files in the directory:

langgraph.json

LangGraph API configuration file declares the graph to be deployed, path mapping and operating environment.

task_maistro.py

The core logic file of the application, including the nodes, edges, and compiled code of the graph (migrated from Module 5).

requirements.txt

A list of Python dependencies that LangGraph CLI automatically installs when building a Docker image.

.env / docker-compose.yml

Runtime environment variables (API keys, database URIs, etc.), passed into the container via file or compose.

langgraph.json configuration example

// langgraph.json — 声明图的路径和 Python 版本
{
  "graphs": {
    "task_maistro": "./task_maistro.py:graph"
  },
  "python_version": "3.11",
  "dependencies": ["."]
}

The format is"图名称": "文件路径:图变量名". After deployment, the graph name becomes part of the API endpoint path.

requirements.txt example

langgraph
langchain-deepseek
trustcall
langchain-core
python-dotenv
deployment directory structure

module-6/deployment/The directory already contains complete examples of these 4 files for direct reference. Among themdocker-compose-example.ymlYou need to copy and fill in the actual environment variables before use.

3LangGraph CLI: Building a Docker image

LangGraph CLI is a command line tool provided by LangChain for packaging graph code into a Docker image (i.e. LangGraph Server container).

Install CLI

pip install -U langgraph-cli

Build a Docker image

# 进入部署目录
cd module-6/deployment

# 构建 Docker 镜像,-t 指定镜像名称
langgraph build -t my-image

langgraph buildwill read the files in the current directorylanggraph.json, automatically:

  1. Download the base image adapted to LangGraph Server
  2. Installationrequirements.txtall dependencies in
  3. Copy the image code into the image
  4. Build the final runnable Docker image
Prerequisites

runlanggraph buildBefore doing this, make sure it is installed and started locally.Docker Desktop. The build process requires network access to pull the base image.

4Redis vs. PostgreSQL: Infrastructure Configuration

LangGraph Server relies on two external services for infrastructure:

serviceuseConfiguration parameters
PostgreSQL Persistent storage graph state (checkpointer) and Store data, data will not be lost after restarting DATABASE_URI(such aspostgresql://user:pass@host/db
Redis Message queue, supporting streaming output and asynchronous task scheduling REDIS_URI(such asredis://localhost:6379

Run the LangGraph Server container independently (already have Redis/PostgreSQL)

# 如果 Redis 和 PostgreSQL 已在别处运行,直接启动 API 容器
docker run \
    --env-file .env \
    -p 8123:8000 \
    -e REDIS_URI="redis://localhost:6379" \
    -e DATABASE_URI="postgresql://user:pass@localhost/langgraph" \
    -e LANGSMITH_API_KEY="lsv2_..." \
    my-image

After startup, LangGraph Server listens to port 8000 in the container by default.-p 8123:8000Maps to host port 8123.

5docker-compose.yml: three-service orchestration

If you do not have independent Redis/PostgreSQL, you can usedocker-compose.ymlStart all three services with one click:

# docker-compose.yml 中定义的三个服务

services:
  langgraph-redis:
    image: redis:6          # 使用官方 Redis 镜像
    ports: ["6379:6379"]

  langgraph-postgres:
    image: postgres:16      # 使用官方 PostgreSQL 镜像
    environment:
      POSTGRES_DB: langgraph
      POSTGRES_USER: langgraph
      POSTGRES_PASSWORD: langgraph
    ports: ["5433:5432"]

  langgraph-api:
    image: ${IMAGE_NAME}    # 使用 langgraph build 构建的镜像
    ports: ["8123:8000"]
    depends_on:
      langgraph-redis:    { condition: service_healthy }
      langgraph-postgres: { condition: service_healthy }
    env_file: .env          # 从 .env 文件读取 API 密钥等环境变量

Startup steps

  1. Copydocker-compose-example.ymlfordocker-compose.yml
  2. exist.envFill in the fileIMAGE_NAMELANGSMITH_API_KEYDEEPSEEK_API_KEY
  3. Run the following command to start all services:
cd module-6/deployment
docker compose up
depends_on and health checks

langgraph-apiContainer is set updepends_onThe condition isservice_healthy, which means that LangGraph Server will only start after both Redis and PostgreSQL pass the health check, avoiding startup failure caused by dependent services not being ready.

6Self-hosted vs LangGraph Cloud comparison

DimensionsSelf-hostedLangGraph Cloud
infrastructureSelf-maintain Redis, PostgreSQL, DockerLangChain management, no need to care about the underlying layer
Data controlFull control, data never leaves your own serverData is hosted on LangChain cloud
Deployment complexityDevOps capabilities requiredOne-click deployment (via LangSmith console)
cost modelBilled based on own server costBilled by API call volume
Applicable scenariosEnterprise scenarios with strict compliance requirements and sensitive dataRapid prototyping, small and medium-sized applications
LangGraph CLIlanggraph build + docker compose upClick deploy directly on the LangSmith interface
Context for this course

The URL used in subsequent Lesson 2 (Connecting)https://langchain-academy-*.langgraph.appIt is a task_mAIstro instance that has been deployed on LangGraph Cloud. Students can directly connect and experience the complete production-level API without deploying it themselves.