安装
-
确保已安装 Docker(例如,
docker --version)。 -
安装 CLI:
-
验证安装
快速命令
| 命令 | 作用 |
|---|---|
langgraph dev | 启动轻量级本地开发服务器(无需 Docker),非常适合快速测试。 |
langgraph build | 构建 LangGraph API 服务器的 Docker 镜像以进行部署。 |
langgraph dockerfile | 根据您的配置生成 Dockerfile 以进行自定义构建。 |
langgraph up | 在 Docker 中本地启动 LangGraph API 服务器。需要运行 Docker;本地开发需要 LangSmith API 密钥;生产环境需要许可证。 |
npx @langchain/langgraph-cli <command>(如果全局安装,则使用 langgraphjs)。
配置文件
要构建和运行有效的应用程序,LangGraph CLI 需要一个遵循此架构的 JSON 配置文件。它包含以下属性:LangGraph CLI 默认使用当前目录中名为 langgraph.json 的配置文件。
- Python
- JS
| Key | Description |
|---|---|
dependencies | Required. Array of dependencies for LangSmith API server. Dependencies can be one of the following:
|
graphs | Required. Mapping from graph ID to path where the compiled graph or a function that makes a graph is defined. Example:
|
auth | (Added in v0.0.11) Auth configuration containing the path to your authentication handler. Example: ./your_package/auth.py:auth, where auth is an instance of langgraph_sdk.Auth. See authentication guide for details. |
base_image | Optional. Base image to use for the LangGraph API server. Defaults to langchain/langgraph-api or langchain/langgraphjs-api. Use this to pin your builds to a particular version of the langgraph API, such as "langchain/langgraph-server:0.2". See https://hub.docker.com/r/langchain/langgraph-server/tags for more details. (added in langgraph-cli==0.2.8) |
image_distro | Optional. Linux distribution for the base image. Must be one of "debian", "wolfi", "bookworm", or "bullseye". If omitted, defaults to "debian". Available in langgraph-cli>=0.2.11. |
env | Path to .env file or a mapping from environment variable to its value. |
store | Configuration for adding semantic search and/or time-to-live (TTL) to the BaseStore. Contains the following fields:
|
ui | Optional. Named definitions of UI components emitted by the agent, each pointing to a JS/TS file. (added in langgraph-cli==0.1.84) |
python_version | 3.11, 3.12, or 3.13. Defaults to 3.11. |
node_version | Specify node_version: 20 to use LangGraph.js. |
pip_config_file | Path to pip config file. |
pip_installer | (Added in v0.3) Optional. Python package installer selector. It can be set to "auto", "pip", or "uv". From version 0.3 onward the default strategy is to run uv pip, which typically delivers faster builds while remaining a drop-in replacement. In the uncommon situation where uv cannot handle your dependency graph or the structure of your pyproject.toml, specify "pip" here to revert to the earlier behaviour. |
keep_pkg_tools | (Added in v0.3.4) Optional. Control whether to retain Python packaging tools (pip, setuptools, wheel) in the final image. Accepted values:
|
dockerfile_lines | Array of additional lines to add to Dockerfile following the import from parent image. |
checkpointer | Configuration for the checkpointer. Supports:
|
http | HTTP server configuration with the following fields:
|
api_version | (Added in v0.3.7) Which semantic version of the LangGraph API server to use (e.g., "0.3"). Defaults to latest. Check the server changelog for details on each release. |
Examples
- Python
- JS
Basic configuration
Using Wolfi base images
You can specify the Linux distribution for your base image using theimage_distro field. Valid options are debian, wolfi, bookworm, or bullseye. Wolfi is the recommended option as it provides smaller and more secure images. This is available in langgraph-cli>=0.2.11.Adding semantic search to the store
All deployments come with a DB-backed BaseStore. Adding an “index” configuration to yourlanggraph.json will enable semantic search within the BaseStore of your deployment.The index.fields configuration determines which parts of your documents to embed:- If omitted or set to
["$"], the entire document will be embedded - To embed specific fields, use JSON path notation:
["metadata.title", "content.text"] - Documents missing specified fields will still be stored but won’t have embeddings for those fields
- You can still override which fields to embed on a specific item at
puttime using theindexparameter
Common model dimensions
openai:text-embedding-3-large: 3072openai:text-embedding-3-small: 1536openai:text-embedding-ada-002: 1536cohere:embed-english-v3.0: 1024cohere:embed-english-light-v3.0: 384cohere:embed-multilingual-v3.0: 1024cohere:embed-multilingual-light-v3.0: 384
Semantic search with a custom embedding function
If you want to use semantic search with a custom embedding function, you can pass a path to a custom embedding function:embed field in store configuration can reference a custom function that takes a list of strings and returns a list of embeddings. Example implementation:Adding custom authentication
配置存储项的存活时间(TTL)
您可以使用store.ttl 键为 BaseStore 中的项/记忆配置默认的数据过期时间。这将决定项目在最后一次访问后保留多长时间(读取操作可能会基于 refresh_on_read 刷新计时器)。请注意,这些默认值可以在每次调用时通过修改 get、search 等方法中的相应参数来覆盖。ttl 配置是一个包含可选字段的对象:refresh_on_read:如果为true(默认值),通过get或search访问项目会重置其过期计时器。设置为false时,仅在写入(put)时刷新 TTL。default_ttl:项目的默认寿命(单位:分钟)。仅适用于新创建的项目;现有项目不会被修改。如果未设置,项目默认不会过期。sweep_interval_minutes:系统运行后台进程以删除过期项目的频率(单位:分钟)。如果未设置,则不会自动进行清理。
配置检查点存活时间(TTL)
您可以使用checkpointer 键为检查点配置存活时间。这决定了检查点数据保留多长时间(例如,删除)。支持两个可选子对象:ttl:包含strategy、sweep_interval_minutes和default_ttl,共同设置检查点过期。serde(Agent server 0.5+) :让您控制检查点负载的反序列化行为。
配置检查点 serde
checkpointer.serde 对象形状反序列化:allowed_json_modules定义了您希望服务器能够从 “json” 模式下保存的负载中反序列化的自定义 Python 对象的允许列表。这是一个[path, to, module, file, symbol]序列的列表。如果省略,则只允许 LangChain 安全默认值。您可以不安全地设置为true以允许任何模块被反序列化。pickle_fallback:JSON 解码失败时是否回退到 pickle 反序列化。
自定义 HTTP 中间件和头
http 块让您可以微调请求处理:-
middleware_order:选择"auth_first"在您的中间件之前运行身份验证,或"middleware_first"(默认)反转顺序。 -
enable_custom_route_auth:扩展身份验证以通过http.app挂载的路由。 -
configurable_headers/logging_headers:每个都接受一个包含可选includes和excludes数组的对象;通配符受支持,排除项先于包含项。 -
cors:除了allow_origins、allow_methods和allow_headers外,您还可以设置allow_credentials、allow_origin_regex、expose_headers和max_age进行更详细的浏览器控制。
固定 API 版本
(Added in v0.3.7)您可以通过使用api_version 键来固定 Agent Server 的 API 版本。这很有用,如果您希望服务器使用特定版本的 API。
默认情况下,Cloud 部署使用服务器最新稳定版本。这可以通过将 api_version 键设置为特定版本来进行固定。Commands
Usage- Python
- JS
The base command for the LangGraph CLI is
langgraph.dev
- Python
- JS
Run LangGraph API server in development mode with hot reloading and debugging capabilities. This lightweight server requires no Docker installation and is suitable for development and testing. State is persisted to a local directory.InstallationThis command requires the “inmem” extra to be installed:UsageOptions
Currently, the CLI only supports Python >= 3.11.
| Option | Default | Description |
|---|---|---|
-c, --config FILE | langgraph.json | Path to configuration file declaring dependencies, graphs and environment variables |
--host TEXT | 127.0.0.1 | Host to bind the server to |
--port INTEGER | 2024 | Port to bind the server to |
--no-reload | Disable auto-reload | |
--n-jobs-per-worker INTEGER | Number of jobs per worker. Default is 10 | |
--debug-port INTEGER | Port for debugger to listen on | |
--wait-for-client | False | Wait for a debugger client to connect to the debug port before starting the server |
--no-browser | Skip automatically opening the browser when the server starts | |
--studio-url TEXT | URL of the Studio instance to connect to. Defaults to https://smith.langchain.com | |
--allow-blocking | False | Do not raise errors for synchronous I/O blocking operations in your code (added in 0.2.6) |
--tunnel | False | Expose the local server via a public tunnel (Cloudflare) for remote frontend access. This avoids issues with browsers like Safari or networks blocking localhost connections |
--help | Display command documentation |
build
- Python
- JS
Build LangSmith API server Docker image.UsageOptions
*Only supported for JS deployments, will have no impact on Python deployments.
| Option | Default | Description |
|---|---|---|
--platform TEXT | Target platform(s) to build the Docker image for. Example: langgraph build --platform linux/amd64,linux/arm64 | |
-t, --tag TEXT | Required. Tag for the Docker image. Example: langgraph build -t my-image | |
--pull / --no-pull | --pull | Build with latest remote Docker image. Use --no-pull for running the LangSmith API server with locally built images. |
-c, --config FILE | langgraph.json | Path to configuration file declaring dependencies, graphs and environment variables. |
--build-command TEXT* | Build command to run. Runs from the directory where your langgraph.json file lives. Example: langgraph build --build-command "yarn run turbo build" | |
--install-command TEXT* | Install command to run. Runs from the directory where you call langgraph build from. Example: langgraph build --install-command "yarn install" | |
--help | Display command documentation. |
up
- Python
- JS
Start LangGraph API server. For local testing, requires a LangSmith API key with access to LangSmith. Requires a license key for production use.UsageOptions
| Option | Default | Description |
|---|---|---|
--wait | Wait for services to start before returning. Implies —detach | |
--base-image TEXT | langchain/langgraph-api | Base image to use for the LangGraph API server. Pin to specific versions using version tags. |
--image TEXT | Docker image to use for the langgraph-api service. If specified, skips building and uses this image directly. | |
--postgres-uri TEXT | Local database | Postgres URI to use for the database. |
--watch | Restart on file changes | |
--debugger-base-url TEXT | http://127.0.0.1:[PORT] | URL used by the debugger to access LangGraph API. |
--debugger-port INTEGER | Pull the debugger image locally and serve the UI on specified port | |
--verbose | Show more output from the server logs. | |
-c, --config FILE | langgraph.json | Path to configuration file declaring dependencies, graphs and environment variables. |
-d, --docker-compose FILE | Path to docker-compose.yml file with additional services to launch. | |
-p, --port INTEGER | 8123 | Port to expose. Example: langgraph up --port 8000 |
--pull / --no-pull | pull | Pull latest images. Use --no-pull for running the server with locally-built images. Example: langgraph up --no-pull |
--recreate / --no-recreate | no-recreate | Recreate containers even if their configuration and image haven’t changed |
--help | Display command documentation. |
dockerfile
- Python
- JS
Generate a Dockerfile for building a LangSmith API server Docker image.UsageOptions
Example:This generates a Dockerfile that looks similar to:
| Option | Default | Description |
|---|---|---|
-c, --config FILE | langgraph.json | Path to the configuration file declaring dependencies, graphs and environment variables. |
--help | Show this message and exit. |
The
langgraph dockerfile command translates all the configuration in your langgraph.json file into Dockerfile commands. When using this command, you will have to re-run it whenever you update your langgraph.json file. Otherwise, your changes will not be reflected when you build or run the dockerfile.