Agent Server 支持特定的环境变量来配置部署。

BG_JOB_ISOLATED_LOOPS

BG_JOB_ISOLATED_LOOPS 设置为 True 以在与服务 API 事件循环分离的隔离事件循环中执行后台运行。 如果图/节点的实现包含同步代码,则应将此环境变量设置为 True。在这种情况下,同步代码将阻塞服务 API 事件循环,这可能导致 API 不可用。API 不可用的症状是由于健康检查失败而持续重启应用程序。 默认为 False

BG_JOB_SHUTDOWN_GRACE_PERIOD_SECS

指定服务器在队列收到关闭信号后等待后台作业完成的时间(以秒为单位)。此期间后,服务器将强制终止。默认为 180 秒。设置此项以确保作业在关闭期间有足够的时间干净地完成。在 langgraph-api==0.2.16 中添加。

BG_JOB_TIMEOUT_SECS

可以增加后台运行的超时时间。但是,云部署的基础架构对 API 请求强制执行 1 小时超时限制。这意味着客户端和服务器之间的连接将在 1 小时后超时。这是不可配置的。 后台运行可以执行超过 1 小时,但如果运行时间超过 1 小时,客户端必须重新连接到服务器(例如,通过 POST /threads/{thread_id}/runs/{run_id}/stream 加入流)以从运行中检索输出。 默认为 3600

DD_API_KEY

指定 DD_API_KEY(您的 Datadog API 密钥)以自动为部署启用 Datadog 跟踪。指定其他 DD_* 环境变量以配置跟踪检测。 如果指定了 DD_API_KEY,应用程序进程将包装在 ddtrace-run 命令中。通常需要其他 DD_* 环境变量(例如 DD_SITEDD_ENVDD_SERVICEDD_TRACE_ENABLED)才能正确配置跟踪检测。有关更多详细信息,请参阅 DD_* 环境变量。您可以启用 DD_TRACE_DEBUG=true 并设置 DD_LOG_LEVEL=debug 以进行故障排除。
启用 DD_API_KEY(因此 ddtrace-run)可能会覆盖或干扰您可能已在应用程序代码中检测的其他自动检测解决方案(例如 OpenTelemetry)。

LANGCHAIN_TRACING_SAMPLING_RATE

发送到 LangSmith 的跟踪的采样率。有效值:01 之间的任何浮点数。 有关更多详细信息,请参阅为跟踪设置采样率

LANGGRAPH_AUTH_TYPE

Agent Server 部署的身份验证类型。有效值:langsmithnoop 对于部署到 LangSmith,此环境变量会自动设置。对于本地开发或外部处理身份验证的部署(例如自托管),将此环境变量设置为 noop

LANGGRAPH_POSTGRES_POOL_MAX_SIZE

从 langgraph-api 版本 0.2.12 开始,可以使用 LANGGRAPH_POSTGRES_POOL_MAX_SIZE 环境变量控制 Postgres 连接池的最大大小(每个副本)。通过设置此变量,您可以确定服务器将与 Postgres 数据库建立的同时连接数的上限。 例如,如果部署扩展到 10 个副本并且 LANGGRAPH_POSTGRES_POOL_MAX_SIZE 配置为 150,则最多可以建立 1500 个到 Postgres 的连接。这对于数据库资源有限(或更多可用)或您需要出于性能或扩展原因调整连接行为的部署特别有用。 默认为 150 个连接。

LANGSMITH_API_KEY

仅适用于使用自托管 LangSmith 的部署。 要将跟踪发送到自托管 LangSmith 实例,请将 LANGSMITH_API_KEY 设置为从自托管实例创建的 API 密钥。

LANGSMITH_ENDPOINT

仅适用于使用自托管 LangSmith 的部署。 要将跟踪发送到自托管 LangSmith 实例,请将 LANGSMITH_ENDPOINT 设置为自托管实例的主机名。

LANGSMITH_TRACING

LANGSMITH_TRACING 设置为 false 以禁用跟踪到 LangSmith。 默认为 true

LOG_COLOR

这主要与通过 langgraph dev 命令使用开发服务器的上下文相关。将 LOG_COLOR 设置为 true 以在使用默认控制台渲染器时启用 ANSI 着色的控制台输出。通过将此变量设置为 false 禁用颜色输出会产生单色日志。默认为 true

LOG_LEVEL

配置日志级别。默认为 INFO

LOG_JSON

LOG_JSON 设置为 true 以使用配置的 JSONRenderer 将所有日志消息呈现为 JSON 对象。这会生成可以轻松解析或由日志管理系统摄取的结构化日志。默认为 false

MOUNT_PREFIX

仅在自托管部署中允许 MOUNT_PREFIX 环境变量仅在自托管部署模型中允许,LangSmith SaaS 不允许此环境变量。
MOUNT_PREFIX 设置为在特定路径前缀下提供 Agent Server。这对于服务器位于需要特定路径前缀的反向代理或负载均衡器后面的部署很有用。 例如,如果服务器要在 https://example.com/langgraph 下提供,请将 MOUNT_PREFIX 设置为 /langgraph

N_JOBS_PER_WORKER

Agent Server 任务队列的每个工作器的作业数。默认为 10

POSTGRES_URI_CUSTOM

Only for Hybrid and Self-Hosted Custom Postgres instances are only available for Hybrid and Self-Hosted deployments.
Specify POSTGRES_URI_CUSTOM to use a custom Postgres instance. The value of POSTGRES_URI_CUSTOM must be a valid Postgres connection URI. Postgres:
  • Version 15.8 or higher.
  • An initial database must be present and the connection URI must reference the database.
Control Plane Functionality:
  • If POSTGRES_URI_CUSTOM is specified, the control plane will not provision a database for the server.
  • If POSTGRES_URI_CUSTOM is removed, the control plane will not provision a database for the server and will not delete the externally managed Postgres instance.
  • If POSTGRES_URI_CUSTOM is removed, deployment of the revision will not succeed. Once POSTGRES_URI_CUSTOM is specified, it must always be set for the lifecycle of the deployment.
  • If the deployment is deleted, the control plane will not delete the externally managed Postgres instance.
  • The value of POSTGRES_URI_CUSTOM can be updated. For example, a password in the URI can be updated.
Database Connectivity:
  • The custom Postgres instance must be accessible by the Agent Server. The user is responsible for ensuring connectivity.

REDIS_CLUSTER

This feature is in Alpha.
Only Allowed in Self-Hosted Deployments Redis Cluster mode is only available in Self-Hosted Deployment models, LangSmith SaaS will provision a redis instance for you by default.
Set REDIS_CLUSTER to True to enable Redis Cluster mode. When enabled, the system will connect to Redis using cluster mode. This is useful when connecting to a Redis Cluster deployment. Defaults to False.

REDIS_KEY_PREFIX

Available in API Server version 0.1.9+ This environment variable is supported in API Server version 0.1.9 and above.
Specify a prefix for Redis keys. This allows multiple Agent Server instances to share the same Redis instance by using different key prefixes. Defaults to ''.

REDIS_URI_CUSTOM

Only for Hybrid and Self-Hosted Custom Redis instances are only available for Hybrid and Self-Hosted deployments.
Specify REDIS_URI_CUSTOM to use a custom Redis instance. The value of REDIS_URI_CUSTOM must be a valid Redis connection URI.

REDIS_MAX_CONNECTIONS

The maximum size of the Redis connection pool (per replica) can be controlled using the REDIS_MAX_CONNECTIONS environment variable. By setting this variable, you can determine the upper bound on the number of simultaneous connections the server will establish with the Redis instance. For example, if a deployment is scaled up to 10 replicas and REDIS_MAX_CONNECTIONS is configured to 150, then up to 1500 connections to Redis can be established. Defaults to 2000.

RESUMABLE_STREAM_TTL_SECONDS

Time-to-live in seconds for resumable stream data in Redis. When a run is created and the output is streamed, the stream can be configured to be resumable (e.g. stream_resumable=True). If a stream is resumable, output from the stream is temporarily stored in Redis. The TTL for this data can be configured by setting RESUMABLE_STREAM_TTL_SECONDS. See the Python and JS/TS SDKs for more details on how to implement resumable streams. Defaults to 120 seconds.
Connect these docs programmatically to Claude, VSCode, and more via MCP for real-time answers.