> ## Documentation Index
> Fetch the complete documentation index at: https://cndoc-langchain.site/llms.txt
> Use this file to discover all available pages before exploring further.

# 启用 LangSmith 部署、Fleet、Insights 和 Polly

> 在自托管 LangSmith 实例上启用 LangSmith 部署、Fleet、Insights 和 Polly。

除了基础的 [LangSmith](/langsmith/self-hosted) 平台外，您还可以启用以下功能：

* **[LangSmith 部署](/langsmith/deployment)** 添加了一个[控制平面](/langsmith/control-plane)和[数据平面](/langsmith/data-plane)，让您可以直接通过 LangSmith UI 部署、扩展和管理代理及应用程序。

  <Note>
    如果您不需要完整的基于 UI 的设置，请参阅[独立服务器](/langsmith/self-hosted#standalone-server)以获取轻量级替代方案。
  </Note>

* **[Fleet](/langsmith/fleet/index)** 允许您直接在 LangSmith 中创建、部署和管理 AI 代理，无需编写代码。

* **[Insights](/langsmith/insights)** 在 LangSmith 中提供对您的跟踪和应用程序数据的 AI 驱动分析。

* **[Polly](/langsmith/polly)** 提供一个嵌入在您 LangSmith 工作区中的 AI 助手，帮助您分析跟踪、线程、提示和实验结果。

<Info>
  这些功能需要 [Enterprise](https://langchain.com/pricing) 计划。[获取演示](https://www.langchain.com/contact-sales)以了解更多信息。
</Info>

## 先决条件

<Steps>
  <Step title="安装基础 LangSmith 平台">
    在继续之前，请按照 [Kubernetes 安装指南](/langsmith/kubernetes)安装基础 LangSmith 平台。
  </Step>

  <Step title="安装 KEDA">
    运行以下命令在您的集群上安装 `KEDA`：

    ```bash theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
    helm repo add kedacore https://kedacore.github.io/charts
    helm upgrade --install keda kedacore/keda --namespace keda --create-namespace
    ```

    <Info>
      KEDA 根据队列大小自动扩展部署系统。
    </Info>
  </Step>

  <Step title="配置入口">
    为您的 LangSmith 实例配置入口、网关或 Istio。所有代理将作为 Kubernetes 服务部署在此入口之后。请参阅[设置入口](/langsmith/self-host-ingress)。您必须在 [`langsmith_config.yaml`](/langsmith/kubernetes#configure-your-helm-charts) 中提供一个 `hostname`。
  </Step>

  <Step title="验证集群容量">
    确保您的集群有足够的容量进行多个部署。建议使用集群自动扩缩器。
  </Step>

  <Step title="验证存储">
    确保您的集群上可用有效的动态 PV 提供程序或 PV。

    ```bash theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
    kubectl get storageclass
    ```

    至少一个 StorageClass 应具有 `PROVISIONER` 值（不是 `kubernetes.io/no-provisioner`）并标记为 `(default)`，否则您必须在继续之前配置一个。
  </Step>

  <Step title="验证出口">
    确保到 `https://beacon.langchain.com` 的出口可用。请参阅[出口文档](/langsmith/self-host-egress)。
  </Step>
</Steps>

## 启用 LangSmith 部署

### 组件

启用 LangSmith 部署会在您的集群中配置以下资源：

* `listener`：监听[控制平面](/langsmith/control-plane)对部署的更改，并创建或更新下游 CRD。
* `LangGraphPlatform CRD`：管理 LangSmith 部署的实例。
* `operator`：处理对 LangSmith CRD 的更改。
* `host-backend`：[控制平面](/langsmith/control-plane)。

### 启用该功能

要启用 LangSmith 部署，请更新您的 [`langsmith_config.yaml`](/langsmith/kubernetes#configure-your-helm-charts)：

<Steps>
  <Step title="在配置中启用部署">
    在您的 `langsmith_config.yaml` 中，启用 `deployment` 选项。您还必须配置有效的入口。

    ```yaml theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
    config:
      deployment:
        enabled: true
    ```

    <Note>
      从 v0.12.0 开始，`langgraphPlatform` 选项已弃用。对于 v0.12.0 之后的任何版本，请使用 `config.deployment`。
    </Note>
  </Step>

  <Step title="（可选）配置镜像镜像">
    如果您需要将镜像镜像到私有注册表，请在 [`langsmith_config.yaml`](/langsmith/kubernetes#configure-your-helm-charts) 中配置 `hostBackendImage` 和 `operatorImage` 选项。使用[最新 LangSmith Helm chart 版本](https://github.com/langchain-ai/helm/releases)中指定的镜像标签。

    ```yaml theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
    hostBackendImage:
      repository: "docker.io/langchain/hosted-langserve-backend"
      pullPolicy: IfNotPresent
    operatorImage:
      repository: "docker.io/langchain/langgraph-operator"
      pullPolicy: IfNotPresent
    ```
  </Step>

  <Step title="（可选）配置基础代理模板">
    如果您需要自定义操作员创建代理 Kubernetes 资源的方式，请覆盖 [`values.yaml` 中的基础代理模板](https://github.com/langchain-ai/helm/blob/main/charts/langsmith/values.yaml#L1428)。最常见的用例是添加 `imagePullSecrets` 以向私有容器注册表进行身份验证。详情请参阅[为私有注册表配置身份验证](#configure-authentication-for-private-registries)。
  </Step>

  <Step title="应用更改">
    运行以下命令以应用更改。本指南中每次要求应用更改时都会使用此命令。将 `<version>` 和 `<namespace>` 替换为您的值：

    ```bash theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
    helm upgrade -i langsmith langchain/langsmith --values langsmith_config.yaml --version <version> -n <namespace> --wait --debug
    ```

    在继续之前，验证新的 Pod 正在运行：

    ```bash theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
    kubectl get pods -n <namespace>
    ```

    您的实例现在已准备好创建部署。
  </Step>
</Steps>

## 启用 Fleet、Insights 和 Polly

<Info>
  Fleet 需要 [LangSmith Self-Hosted v0.13](https://changelog.langchain.com/announcements/langsmith-self-hosted-v0-13) 或更高版本。下面描述的独立部署模型需要 v0.15 或更高版本。
</Info>

每个功能都需要一个 Fernet 加密密钥。您可以在单个 Helm 配置中启用所有三个功能。

### 组件

启用这些功能会在您的集群中为每个功能（Fleet、Insights、Polly）配置以下组件：

* `api-server`：处理功能请求的主 API 服务器。
* `queue`：后台任务处理队列。
* `postgres`：用于功能数据的专用 PostgreSQL 实例。可以替换为外部 PostgreSQL 实例。
* `redis`：用于功能缓存和发布/订阅的专用 Redis 实例。可以替换为外部 Redis 实例。

Fleet 额外配置：

* `toolServer`：为代理提供 MCP 工具执行。
* `triggerServer`：处理 webhook 和计划触发器。

### 生成加密密钥

每个功能使用自己的 Fernet 加密密钥来加密特定于功能的机密信息，例如凭据和令牌。单独的密钥允许独立轮换，并在密钥泄露时限制暴露。使用 Python 为每个功能生成一个密钥：

```bash theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
python -c "from cryptography.fernet import Fernet; print(Fernet.generate_key().decode())"
```

我们建议将每个密钥存储在预定义的 Kubernetes Secret 中，而不是直接在配置文件中设置它们。请参阅[使用现有 Secret](/langsmith/self-host-using-an-existing-secret#parameters)以获取相关参数：`agent_builder_encryption_key`、`insights_encryption_key` 和 `polly_encryption_key`。

### 启用功能

<Steps>
  <Step title="将配置添加到您的 langsmith_config.yaml">
    <Tabs>
      <Tab title="使用 Kubernetes Secrets（推荐）">
        通过名称引用您现有的 Secret。Chart 会自动从中读取 `agent_builder_encryption_key`、`insights_encryption_key` 和 `polly_encryption_key`。

        ```yaml theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
        config:
          existingSecretName: "<your-secret-name>"

        fleet:
          enabled: true

        insights:
          enabled: true

        polly:
          enabled: true

        agentBuilderToolServer:
          enabled: true

        agentBuilderTriggerServer:
          enabled: true
        ```
      </Tab>

      <Tab title="使用内联值">
        直接在配置文件中设置加密密钥。避免将此文件提交到版本控制。

        ```yaml theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
        fleet:
          enabled: true
          encryptionKey: "<fleet-encryption-key>"

        insights:
          enabled: true
          encryptionKey: "<insights-encryption-key>"

        polly:
          enabled: true
          encryptionKey: "<polly-encryption-key>"

        agentBuilderToolServer:
          enabled: true

        agentBuilderTriggerServer:
          enabled: true
        ```
      </Tab>
    </Tabs>

    <Note>
      `agentBuilderToolServer` 和 `agentBuilderTriggerServer` 是 Fleet 所必需的。
    </Note>

    默认情况下，每个功能都会部署自己的专用 PostgreSQL 和 Redis 实例。要改用外部数据库，请在每个功能下配置 `postgres.external` 和 `redis.external` 部分。例如：

    ```yaml theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
    fleet:
      enabled: true
      encryptionKey: "<fleet-encryption-key>"
      postgres:
        external:
          enabled: true
          connectionUrl: "<fleet-postgres-connection-url>"
      redis:
        external:
          enabled: true
          connectionUrl: "<fleet-redis-connection-url>"
    ```
  </Step>

  <Step title="应用更改">
    ```bash theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
    helm upgrade -i langsmith langchain/langsmith --values langsmith_config.yaml --version <version> -n <namespace> --wait --debug
    ```

    验证 Fleet、Insights 和 Polly Pod 正在运行：

    ```bash theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
    kubectl get pods -n <namespace>
    ```
  </Step>
</Steps>

### （可选）为 Fleet 启用 OAuth 工具和触发器

要在 Fleet 中启用基于 OAuth 的工具（如 Gmail、Slack 或 Linear），请配置 `providerOrgId` 并为您要使用的每个集成添加提供程序 ID。您可以启用任何提供程序组合。

#### 可用提供程序

| 提供程序                                                            | 启用的工具                                                   | 启用的触发器  |
| --------------------------------------------------------------- | ------------------------------------------------------- | ------- |
| `googleOAuthProvider`<br />[设置指南](#google-oauth-provider)       | Gmail、Google 日历、<br />Google 表格、BigQuery                | Gmail   |
| `linearOAuthProvider`<br />[设置指南](#linear-oauth-provider)       | Linear                                                  | -       |
| `linkedinOAuthProvider`<br />[设置指南](#linkedin-oauth-provider)   | LinkedIn                                                | -       |
| `microsoftOAuthProvider`<br />[设置指南](#microsoft-oauth-provider) | Outlook、日历、Teams、SharePoint、<br />Word、Excel、PowerPoint | Outlook |
| `slackOAuthProvider`<br />[设置指南](#slack-oauth-provider)         | Slack                                                   | Slack   |

#### 通用配置

将以下内容添加到您的 [`langsmith_config.yaml`](/langsmith/kubernetes#configure-your-helm-charts)。仅包含您需要的提供程序。

```yaml theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
fleet:
  oauth:
    # 配置 OAuth 提供程序的组织 ID
    providerOrgId: "<your-org-id>"
    # 为您要启用的集成添加提供程序 ID。
    # Slack 需要额外的配置。
    slackOAuthProvider: "<provider-id>"
    slackSigningSecret: "<signing-secret>"
    slackBotId: "<bot-id>"
    googleOAuthProvider: "<provider-id>"
    linkedinOAuthProvider: "<provider-id>"
    linearOAuthProvider: "<provider-id>"
    microsoftOAuthProvider: "<provider-id>"
```

<Warning>
  提供程序 ID 必须唯一，且不能以 `-agent-builder` 或 `-oauth-provider` 结尾。
</Warning>

#### 提供程序设置指南

<AccordionGroup>
  <Accordion title="Google OAuth 提供程序" id="google-oauth-provider">
    要为 Fleet 启用 Google OAuth，请在 GCP 中创建一个 OAuth 客户端，并使用所需的 URL 和凭据进行配置。

    <Steps>
      <Step title="在 GCP 中创建 OAuth 客户端">
        在 [Google Cloud Console](https://console.cloud.google.com/apis/credentials) 中创建一个新的 OAuth 客户端应用（Web 应用程序）。
      </Step>

      <Step title="将 URL 添加到 GCP">
        将以下 URL 添加到您的 OAuth 客户端，将 `<hostname>` 替换为您的 LangSmith 主机名，将 `<provider-id>` 替换为您将使用的提供程序 ID（例如 `google`）：

        **授权的 JavaScript 来源：**

        * `https://<hostname>`

        **授权的重定向 URI：**

        * `https://<hostname>/api-host/v2/auth/callback/<provider-id>`
        * `https://<hostname>/host-oauth-callback/<provider-id>`
      </Step>

      <Step title="复制凭据">
        从 GCP OAuth 应用中复制 **Client ID** 和 **Client Secret**。
      </Step>

      <Step title="在 LangSmith 中配置 OAuth 提供程序">
        在 LangSmith 中，转到 **Settings > OAuth Providers** 并添加新的提供程序：

        * **Client ID**：来自 GCP
        * **Client Secret**：来自 GCP
        * **Authorization URL**：`https://accounts.google.com/o/oauth2/auth`
        * **Token URL**：`https://oauth2.googleapis.com/token`
        * **Provider ID**：唯一字符串，例如：`google`
      </Step>

      <Step title="应用更改">
        将 LangSmith OAuth 提供程序 ID 添加到您的 [`langsmith_config.yaml`](/langsmith/kubernetes#configure-your-helm-charts) 并部署：

        ```yaml theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
        fleet:
          oauth:
            providerOrgId: "<your-org-id>"
            googleOAuthProvider: "<provider-id>"
        ```

        ```bash theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
        helm upgrade -i langsmith langchain/langsmith --values langsmith_config.yaml --version <version> -n <namespace> --wait --debug
        ```
      </Step>
    </Steps>
  </Accordion>

  <Accordion title="Microsoft OAuth 提供程序" id="microsoft-oauth-provider">
    要为 Fleet 启用 Microsoft OAuth，请创建一个 Azure 应用程序注册，添加所需的 Microsoft Graph 委托权限，并在 LangSmith 中配置 Microsoft OAuth 提供程序。

    <Steps>
      <Step title="创建 Azure 应用程序注册">
        在 [Microsoft Entra 管理中心](https://entra.microsoft.com/)，转到 **Applications > App registrations** 并创建新的注册。
      </Step>

      <Step title="选择支持的帐户类型">
        选择与您的部署匹配的帐户类型。如果您需要来自多个 Microsoft Entra 租户的用户进行身份验证，请选择多租户选项。如果您的部署仅限于一个租户，您可以使用单租户应用程序注册。
      </Step>

      <Step title="添加重定向 URI">
        添加以下 Web 重定向 URI，将 `<hostname>` 替换为您的 LangSmith 主机名，将 `<provider-id>` 替换为您的提供程序 ID：

        ```
        https://<hostname>/host-oauth-callback/<provider-id>
        ```
      </Step>

      <Step title="创建客户端密钥">
        在 **Certificates & secrets** 中，创建新的客户端密钥。复制 **Application (client) ID** 和生成的客户端密钥值。
      </Step>

      <Step title="添加 Microsoft Graph 委托权限">
        在 **API permissions** 中，添加以下 Microsoft Graph 委托权限：

        * `Mail.ReadWrite`
        * `Mail.Send`
        * `Calendars.ReadWrite`
        * `Team.ReadBasic.All`
        * `Channel.ReadBasic.All`
        * `Channel.Create`
        * `ChannelMessage.Send`
        * `ChannelMessage.Read.All`
        * `Chat.Create`
        * `Chat.ReadWrite`
        * `User.ReadBasic.All`
        * `Files.ReadWrite.All`
        * `Sites.ReadWrite.All`

        <Note>
          LangSmith 会自动为 Microsoft 提供程序请求 `offline_access`，以便用户可以接收刷新令牌。
        </Note>
      </Step>

      <Step title="授予租户同意">
        如果您的 Microsoft 365 策略要求对这些委托权限进行管理员同意，请为租户授予管理员同意。
      </Step>

      <Step title="在 LangSmith 中配置 OAuth 提供程序">
        在 LangSmith 中，转到 **Settings > OAuth Providers** 并添加新的提供程序：

        * **Name**：例如 `Microsoft`
        * **Provider ID**：唯一字符串，例如：`microsoft-oauth-provider`
        * **Client ID**：来自 Azure 的 Application (client) ID
        * **Client Secret**：来自 Azure 的客户端密钥值
        * **Authorization URL**：`https://login.microsoftonline.com/common/oauth2/v2.0/authorize`
        * **Token URL**：`https://login.microsoftonline.com/common/oauth2/v2.0/token`
        * **Provider Type**：`microsoft`
        * **Token endpoint auth method**：`client_secret_post`

        <Note>
          如果您创建了单租户应用程序注册，请将授权和令牌 URL 中的 `common` 替换为您的租户 ID。
        </Note>
      </Step>

      <Step title="应用更改">
        将以下内容添加到您的 [`langsmith_config.yaml`](/langsmith/kubernetes#configure-your-helm-charts) 并部署：

        ```yaml theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
        fleet:
          oauth:
            providerOrgId: "<your-org-id>"
            microsoftOAuthProvider: "<provider-id>"
        ```

        ```bash theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
        helm upgrade -i langsmith langchain/langsmith --values langsmith_config.yaml --version <version> -n <namespace> --wait --debug
        ```
      </Step>
    </Steps>
  </Accordion>

  <Accordion title="Linear OAuth 提供程序" id="linear-oauth-provider">
    要为 Fleet 启用 Linear OAuth，请创建一个 Linear OAuth 应用并使用所需的凭据进行配置。

    <Steps>
      <Step title="创建 Linear OAuth 应用">
        转到 [Linear Settings > API > Applications](https://linear.app/settings/api/applications/new) 并创建新的 OAuth 应用。
      </Step>

      <Step title="添加回调 URL">
        设置回调 URL，将 `<hostname>` 替换为您的 LangSmith 主机名，将 `<provider-id>` 替换为您的提供程序 ID：

        ```
        https://<hostname>/host-oauth-callback/<provider-id>
        ```
      </Step>

      <Step title="复制凭据">
        创建应用后，复制 **Client ID** 和 **Client Secret**。
      </Step>

      <Step title="在 LangSmith 中配置 OAuth 提供程序">
        在 LangSmith 中，转到 **Settings > OAuth Providers** 并添加新的提供程序：

        * **Client ID**：来自 Linear 应用
        * **Client Secret**：来自 Linear 应用
        * **Authorization URL**：`https://linear.app/oauth/authorize`
        * **Token URL**：`https://api.linear.app/oauth/token`
        * **Provider ID**：唯一字符串，例如：`linear`
      </Step>

      <Step title="应用更改">
        将以下内容添加到您的 [`langsmith_config.yaml`](/langsmith/kubernetes#configure-your-helm-charts) 并部署：

        ```yaml theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
        fleet:
          oauth:
            providerOrgId: "<your-org-id>"
            linearOAuthProvider: "<provider-id>"
        ```

        ```bash theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
        helm upgrade -i langsmith langchain/langsmith --values langsmith_config.yaml --version <version> -n <namespace> --wait --debug
        ```
      </Step>
    </Steps>
  </Accordion>

  <Accordion title="LinkedIn OAuth 提供程序" id="linkedin-oauth-provider">
    要为 Fleet 启用 LinkedIn OAuth，请创建一个 LinkedIn OAuth 应用并使用所需的凭据进行配置。

    <Steps>
      <Step title="创建 LinkedIn OAuth 应用">
        转到 [linkedin.com/developers/apps](https://www.linkedin.com/developers/apps/) 并创建新的应用。
      </Step>

      <Step title="添加重定向 URI">
        在您的应用设置中，转到 **Auth** 选项卡。添加以下重定向 URI，将 `<hostname>` 替换为您的 LangSmith 主机名，将 `<provider-id>` 替换为您的提供程序 ID：

        ```
        https://<hostname>/host-oauth-callback/<provider-id>
        ```
      </Step>

      <Step title="复制凭据">
        从 Auth 选项卡复制 **Client ID** 和 **Client Secret**。
      </Step>

      <Step title="在 LangSmith 中配置 OAuth 提供程序">
        在 LangSmith 中，转到 **Settings > OAuth Providers** 并添加新的提供程序：

        * **Client ID**：来自 LinkedIn 应用
        * **Client Secret**：来自 LinkedIn 应用
        * **Authorization URL**：`https://www.linkedin.com/oauth/v2/authorization`
        * **Token URL**：`https://www.linkedin.com/oauth/v2/accessToken`
        * **Provider ID**：唯一字符串，例如：`linkedin`
      </Step>

      <Step title="应用更改">
        将以下内容添加到您的 [`langsmith_config.yaml`](/langsmith/kubernetes#configure-your-helm-charts) 并部署：

        ```yaml theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
        fleet:
          oauth:
            providerOrgId: "<your-org-id>"
            linkedinOAuthProvider: "<provider-id>"
        ```

        ```bash theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
        helm upgrade -i langsmith langchain/langsmith --values langsmith_config.yaml --version <version> -n <namespace> --wait --debug
        ```
      </Step>
    </Steps>
  </Accordion>

  <Accordion title="Slack OAuth 提供程序" id="slack-oauth-provider">
    要为 Fleet 启用 Slack OAuth，请创建一个 Slack 应用并使用所需的作用域、凭据和事件订阅进行配置。

    <Steps>
      <Step title="创建 Slack 应用">
        转到 [api.slack.com/apps](https://api.slack.com/apps) 并点击 **Create New App**。
      </Step>

      <Step title="添加作用域">
        在 **OAuth & Permissions** 中，添加以下作用域：

        * `channels:history`
        * `channels:read`
        * `chat:write`
        * `groups:history`
        * `groups:read`
        * `im:history`
        * `im:read`
        * `im:write`
        * `mpim:history`
        * `team:read`
        * `users:read`
        * `users:read.email`
      </Step>

      <Step title="从 Slack 复制凭据">
        从 Slack 应用设置中复制 **Client ID**、**Client Secret** 和 **Signing Secret**。
      </Step>

      <Step title="在 LangSmith 中配置 OAuth 提供程序">
        在 LangSmith 中，转到 **Settings > OAuth Providers** 并添加新的提供程序：

        * **Client ID**：来自 Slack 应用
        * **Client Secret**：来自 Slack 应用
        * **Authorization URL**：`https://slack.com/oauth/v2/authorize`
        * **Token URL**：`https://slack.com/api/oauth.v2.access`
        * **Provider ID**：唯一字符串，例如：`slack`
      </Step>

      <Step title="将重定向 URI 添加到 Slack">
        在您的 Slack 应用的 **OAuth & Permissions > Redirect URLs** 下添加以下重定向 URI，将 `<hostname>` 替换为您的 LangSmith 主机名，将 `<provider-id>` 替换为您的提供程序 ID（例如 `slack`）：

        ```
        https://<hostname>/host-oauth-callback/<provider-id>
        ```
      </Step>

      <Step title="获取机器人 ID">
        1. 从 Slack 应用的 **OAuth & Permissions** 获取机器人令牌。
        2. 运行以下命令：

        ```bash theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
        curl -X POST https://slack.com/api/auth.test \
          -H "Authorization: Bearer <bot-token>"
        ```

        3. 从响应中复制 `bot_id`。
      </Step>

      <Step title="应用更改">
        将以下内容添加到您的 [`langsmith_config.yaml`](/langsmith/kubernetes#configure-your-helm-charts) 并部署：

        ```yaml theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
        fleet:
          oauth:
            providerOrgId: "<your-org-id>"
            slackOAuthProvider: "<provider-id>"
            slackSigningSecret: "<signing-secret>"
            slackBotId: "<bot-id>"
        ```

        ```bash theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
        helm upgrade -i langsmith langchain/langsmith --values langsmith_config.yaml --version <version> -n <namespace> --wait --debug
        ```
      </Step>

      <Step title="启用事件订阅">
        1. 部署后，转到 Slack 应用中的 **Event Subscriptions** 并启用事件。

        2. 将 **Request URL** 设置为：

           ```
           https://<hostname>/v1/triggers/webhooks/d809e66e-0000-4000-8000-000000000002
           ```

           UUID 是一个固定的 LangSmith 标识符——不要替换它。

        3. 添加以下机器人事件：
           * `message.channels`
           * `message.groups`
           * `message.im`
           * `message.mpim`
      </Step>

      <Step title="设置触发器和工具">
        1. 将 Slack 机器人添加到您希望它读取的频道。
        2. 在 Fleet 中配置 Slack 工具或触发器时，提供 **channel ID** 和 **channel name**。
      </Step>
    </Steps>
  </Accordion>
</AccordionGroup>

### （可选）为 Fleet 启用 GitHub App

Fleet 通过专用的 **GitHub App**（不是 OAuth 应用）与 GitHub 集成。GitHub App 为 Fleet 的 GitHub 工具提供仓库访问权限，并支持私有仓库访问所需的用户授权流程。

设置涉及创建 GitHub App、收集其凭据、将其存储为 Kubernetes Secrets，并从您的 [`langsmith_config.yaml`](/langsmith/kubernetes#configure-your-helm-charts) 中引用它们。

<Steps>
  <Step title="创建 GitHub App">
    转到 [GitHub Settings > Developer settings > GitHub Apps](https://github.com/settings/apps) 并点击 **New GitHub App**。

    <Note>
      您可以在个人帐户或组织下创建应用。如果多人将管理集成，建议使用组织拥有的应用。
    </Note>
  </Step>

  <Step title="填写基本详细信息">
    * **GitHub App name**：任何唯一名称，例如 `acme-langsmith-fleet`。记下 GitHub 生成的 slug（名称的小写、连字符形式），因为这是您将用于 `FLEET_GITHUB_APP_SLUG` 的值。
    * **Homepage URL**：您的 LangSmith 主机名，例如 `https://langsmith.acme.com`。
    * 目前取消选择 **Webhook** 下的 **Active**。您将在生成 webhook 密钥后的后续步骤中启用它。
  </Step>

  <Step title="设置回调 URL">
    在 **Identifying and authorizing users** 下，添加以下 **Callback URL**，将 `<hostname>` 替换为您的 LangSmith 主机名：

    ```
    https://<hostname>/v1/platform/fleet/providers/github-app/auth/callback
    ```

    选择 **Redirect on update**。

    在 **Post installation** 下，添加以下 **Setup URL**：

    ```
    https://<hostname>/v1/platform/fleet/providers/github-app/callback
    ```

    选择 **Redirect on update**。
  </Step>

  <Step title="设置 webhook URL 并生成 webhook 密钥">
    生成一个随机的 webhook 密钥：

    ```bash theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
    python3 -c "import secrets; print(secrets.token_urlsafe(48))"
    ```

    在 **Webhook** 下：

    * 选择 **Active**。

    * 将 **Webhook URL** 设置为：

      ```
      https://<hostname>/v1/platform/fleet/providers/github-app/webhooks
      ```

    * 将生成的值粘贴到 **Webhook secret** 中。保存它，因为您在后续步骤中创建 Kubernetes Secret 时需要相同的值。
  </Step>

  <Step title="设置仓库权限">
    在 **Permissions > Repository permissions** 下，授予以下权限：

    * **Contents**：读写
    * **Issues**：读写
    * **Pull requests**：读写
    * **Metadata**：只读（自动选择）

    在 **Permissions > Account permissions** 下，授予 **Email addresses: 只读**。

    <Note>
      这些是 Fleet 内置 GitHub 工具（问题管理、拉取请求创建、仓库内容访问）所需的最低权限。如果您需要额外的工具功能，请进行调整。
    </Note>
  </Step>

  <Step title="选择安装可见性">
    在 **Where can this GitHub App be installed?** 下，选择与您的分发需求匹配的选项。对于大多数自托管部署，**Only on this account** 是正确的。
  </Step>

  <Step title="创建应用">
    点击 **Create GitHub App**。在应用设置页面上，记下以下值：

    | 值               | 在哪里找到它                                            | 环境变量                           |
    | --------------- | ------------------------------------------------- | ------------------------------ |
    | **App ID**      | 数字，在页面顶部                                          | `FLEET_GITHUB_APP_ID`          |
    | **Public link** | 例如 `https://github.com/apps/acme-langsmith-fleet` | `FLEET_GITHUB_APP_PUBLIC_LINK` |
    | App slug        | 公共链接的最后一个路径段                                      | `FLEET_GITHUB_APP_SLUG`        |
    | **Client ID**   | 在 **About** 下                                     | `FLEET_GITHUB_APP_CLIENT_ID`   |
  </Step>

  <Step title="生成客户端密钥">
    在 **Client secrets** 下，点击 **Generate a new client secret** 并复制值。这是 `FLEET_GITHUB_APP_CLIENT_SECRET`。GitHub 只显示一次。
  </Step>

  <Step title="生成私钥">
    滚动到 **Private keys** 并点击 **Generate a private key**。GitHub 下载一个 `.pem` 文件。请妥善保管此文件，因为它授予对 GitHub App 的完全访问权限。PEM 内容是 `FLEET_GITHUB_APP_PRIVATE_KEY`。
  </Step>

  <Step title="生成 state JWT 密钥">
    LangSmith 使用 HMAC 密钥对短期 OAuth 状态令牌进行签名。生成一个：

    ```bash theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
    python3 -c "import secrets; print(secrets.token_urlsafe(48))"
    ```

    这是 `FLEET_GITHUB_APP_STATE_JWT_SECRET`。
  </Step>

  <Step title="创建 Kubernetes Secret">
    将敏感值存储在 Kubernetes Secret 中：

    ```bash theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
    kubectl create secret generic fleet-github-app \
      --namespace <your-langsmith-namespace> \
      --from-literal=client_secret="<client-secret>" \
      --from-literal=webhook_secret="<webhook-secret>" \
      --from-literal=state_jwt_secret="<state-jwt-secret>" \
      --from-file=private_key=/path/to/fleet-app.private-key.pem
    ```

    对于生产部署，请通过您现有的 Secret 工作流管理此 Secret（例如 [Sealed Secrets](https://github.com/bitnami-labs/sealed-secrets) 或 [External Secrets Operator](https://external-secrets.io/)）。更多信息请参阅[使用现有 Secret](/langsmith/self-host-using-an-existing-secret)。
  </Step>

  <Step title="将配置添加到您的 langsmith_config.yaml">
    添加以下内容，将占位符值替换为上面收集的非敏感值：

    ```yaml theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
    commonEnv:
      - name: FLEET_GITHUB_APP_ID
        value: "<app-id>"
      - name: FLEET_GITHUB_APP_SLUG
        value: "<app-slug>"
      - name: FLEET_GITHUB_APP_PUBLIC_LINK
        value: "https://github.com/apps/<app-slug>"
      - name: FLEET_GITHUB_APP_CLIENT_ID
        value: "<client-id>"
      - name: FLEET_GITHUB_APP_CLIENT_SECRET
        valueFrom:
          secretKeyRef:
            name: fleet-github-app
            key: client_secret
      - name: FLEET_GITHUB_APP_PRIVATE_KEY
        valueFrom:
          secretKeyRef:
            name: fleet-github-app
            key: private_key
      - name: FLEET_GITHUB_APP_WEBHOOK_SECRET
        valueFrom:
          secretKeyRef:
            name: fleet-github-app
            key: webhook_secret
      - name: FLEET_GITHUB_APP_STATE_JWT_SECRET
        valueFrom:
          secretKeyRef:
            name: fleet-github-app
            key: state_jwt_secret

    agentBuilderToolServer:
      deployment:
        extraEnv:
          - name: FLEET_GITHUB_APP_ENABLED
            value: "true"
    ```

    <Note>
      `FLEET_GITHUB_APP_ENABLED` 必须在工具服务器上设置，以便注册 GitHub 工具。其余的 `FLEET_GITHUB_APP_*` 变量由平台后端使用，位于 `commonEnv` 下。
    </Note>
  </Step>

  <Step title="部署并在仓库上安装应用">
    运行以下命令以应用更改：

    ```bash theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
    helm upgrade -i langsmith langchain/langsmith --values langsmith_config.yaml --version <version> -n <namespace> --wait --debug
    ```

    Pod 健康后：

    1. 在 LangSmith 中，打开一个 Fleet 代理并转到代理编辑器中的 GitHub 集成。
    2. 点击 **Connect GitHub** 以在 Fleet 应访问的仓库上安装应用。
    3. 对于私有仓库，您必须在安装期间明确选择每个仓库。

    <Note>
      每个用户还必须使用 LangSmith 中的重新身份验证流程，针对其自己的 GitHub 帐户授权 GitHub App。这允许 Fleet 为代表用户操作的工具解析每用户令牌。
    </Note>
  </Step>
</Steps>

### 禁用功能

要禁用 Fleet、Insights 和 Polly 的任何组合，请在您的 [`langsmith_config.yaml`](/langsmith/kubernetes#configure-your-helm-charts) 中将相应的标志设置为 `false`：

```yaml theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
fleet:
  enabled: false

insights:
  enabled: false

polly:
  enabled: false
```

## 可选配置

### 配置其他数据平面

除了上面创建的数据平面外，您还可以在不同的 Kubernetes 集群中或在同一集群的不同命名空间下创建更多数据平面。有多种方法可以实现这一点，因此请实施最适合您用例的解决方案。

#### 先决条件

<Steps>
  <Step title="查看集群组织">
    阅读[混合部署文档](/langsmith/hybrid#listeners)中的集群组织指南，了解如何为您的用例组织此内容。
  </Step>

  <Step title="验证混合先决条件">
    验证新集群的[混合部分](/langsmith/deploy-hybrid#prerequisites)中的先决条件。在[先决条件](/langsmith/deploy-hybrid#prerequisites)的第 5 步中，将出口配置到您的[自托管 LangSmith 实例](/langsmith/self-host-usage#configuring-the-application-you-want-to-use-with-langsmith)，而不是 `https://api.host.langchain.com` 和 `https://api.smith.langchain.com`。
  </Step>

  <Step title="在 Postgres 中启用该功能">
    针对您的 LangSmith Postgres 实例运行以下命令以启用此功能。记下工作区 ID 以供后续步骤使用。

    ```sql theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
    update organizations set config = config || '{"enable_lgp_listeners_page": true}' where id = '<org id here>';
    update tenants set config = config || '{"langgraph_remote_reconciler_enabled": true}' where id = '<workspace id here>';
    ```
  </Step>
</Steps>

#### 部署到不同的集群

<Steps>
  <Step title="按照混合设置指南操作">
    按照[混合设置指南](/langsmith/deploy-hybrid#setup)中的步骤 2 到 6 操作。将 `config.langsmithWorkspaceId` 设置为上一步中的工作区 ID。
  </Step>

  <Step title="（可选）向同一集群添加更多数据平面">
    要向同一集群添加多个数据平面，请按照[在同一集群中配置其他数据平面](/langsmith/deploy-hybrid#configuring-additional-data-planes-in-the-same-cluster)的说明操作。
  </Step>
</Steps>

#### 部署到同一集群中的不同命名空间

<Steps>
  <Step title="更新您的配置">
    在您的 [`langsmith_config.yaml`](/langsmith/kubernetes#configure-your-helm-charts) 中，进行以下修改：

    * 将 `operator.watchNamespaces` 设置为您的自托管 LangSmith 实例当前运行的命名空间。这可以防止与新数据平面添加的操作员发生冲突。
    * 使用 [Gateway API](/langsmith/self-host-ingress#option-2%3A-gateway-api) 或 [Istio Gateway](/langsmith/self-host-ingress#option-3%3A-istio-gateway)。相应地调整您的 `langsmith_config.yaml`。
  </Step>

  <Step title="应用更改">
    ```bash theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
    helm upgrade -i langsmith langchain/langsmith --values langsmith_config.yaml --version <version> -n <namespace> --wait --debug
    ```
  </Step>

  <Step title="按照混合设置指南操作">
    按照[混合设置指南](/langsmith/deploy-hybrid#setup)中的步骤 2 到 6 操作。将 `config.langsmithWorkspaceId` 设置为上一步中的工作区 ID。将 `config.watchNamespaces` 设置为与现有数据平面使用的命名空间不同的命名空间。
  </Step>

  <Step title="（可选）配置日志访问">
    配置控制平面以从新命名空间读取 Agent Server 部署日志的访问权限。请参阅[从其他命名空间读取 Agent Server 日志](#read-agent-server-logs-from-other-namespaces)。
  </Step>
</Steps>

### 为私有注册表配置身份验证

如果您的 [Agent Server 部署](/langsmith/agent-server)将使用来自私有容器注册表（例如 AWS ECR、Azure ACR 或 GCP Artifact Registry）的镜像，请配置镜像拉取 Secret。此配置会自动应用于所有部署，允许它们向您的私有注册表进行身份验证。

<Steps>
  <Step title="创建 Kubernetes 镜像拉取 Secret">
    ```bash theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
    kubectl create secret docker-registry langsmith-registry-secret \
        --docker-server=myregistry.com \
        --docker-username=your-username \
        --docker-password=your-password \
        --docker-email=your-email@example.com \
        -n langsmith
    ```

    将值替换为您的注册表凭据：

    * `myregistry.com`：您的注册表 URL
    * `your-username`：您的注册表用户名
    * `your-password`：您的注册表密码或访问令牌
    * `langsmith`：安装 LangSmith 的 Kubernetes 命名空间
  </Step>

  <Step title="在您的 langsmith_config.yaml 中配置部署模板">
    要使代理服务器部署能够使用私有注册表 Secret，请将 `imagePullSecrets` 添加到操作员的部署模板中：

    ```yaml {21-22} theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
    operator:
      templates:
        deployment: |
          apiVersion: apps/v1
          kind: Deployment
          metadata:
            name: ${name}
            namespace: ${namespace}
          spec:
            replicas: ${replicas}
            revisionHistoryLimit: 10
            selector:
              matchLabels:
                app: ${name}
            template:
              metadata:
                labels:
                  app: ${name}
              spec:
                enableServiceLinks: false
                imagePullSecrets:
                - name: langsmith-registry-secret
                containers:
                - name: api-server
                  image: ${image}
                  ports:
                  - name: api-server
                    containerPort: 8000
                    protocol: TCP
                  livenessProbe:
                    httpGet:
                      path: /ok
                      port: 8000
                    periodSeconds: 15
                    timeoutSeconds: 5
                    failureThreshold: 6
                  readinessProbe:
                    httpGet:
                      path: /ok
                      port: 8000
                    periodSeconds: 15
                    timeoutSeconds: 5
                    failureThreshold: 6
    ```
  </Step>

  <Step title="应用更改">
    ```bash theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
    helm upgrade -i langsmith langchain/langsmith --values langsmith_config.yaml --version <version> -n <namespace> --wait --debug
    ```

    通过 LangSmith UI 创建的所有用户部署都将继承这些注册表凭据。
  </Step>
</Steps>

有关特定于注册表的身份验证方法，请参阅 [Kubernetes 关于从私有注册表拉取镜像的文档](https://kubernetes.io/docs/tasks/configure-pod-container/pull-image-private-registry/)。

### 从其他命名空间读取 Agent Server 日志

<Warning>
  对于控制平面（`host-backend`）和数据平面（`listener`）部署在不同 Kubernetes 集群中的自托管部署，不支持检索服务器日志。
</Warning>

对于控制平面和数据平面在同一集群中的部署，请确保控制平面 Kubernetes 部署（`host-backend`）具有从 Agent Server 部署所在的命名空间中 `get`、`list` 和 `watch` Kubernetes `deployments`、`pods`、`replicasets` 和 `logs` 的权限。有多种方法可以实现这一点。以下示例使用 Kubernetes RBAC，但请使用最适合您用例的方法：

<Steps>
  <Step title="创建具有所需权限的 Role">
    在 Agent Server 命名空间中创建一个 `Role`。替换 `<data_plane_namespace>`：

    ```bash theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
    kubectl apply -n <data_plane_namespace> -f - <<EOF
    apiVersion: rbac.authorization.k8s.io/v1
    kind: Role
    metadata:
      name: read-agent-server-logs-role
    rules:
    - apiGroups: [""]
      resources: ["pods"]
      verbs: ["get","list","watch"]
    - apiGroups: [""]
      resources: ["pods/log"]
      verbs: ["get","watch"]
    - apiGroups: ["apps"]
      resources: ["deployments"]
      verbs: ["get","list","watch"]
    - apiGroups: ["apps"]
      resources: ["replicasets"]
      verbs: ["get","list","watch"]
    EOF
    ```
  </Step>

  <Step title="获取控制平面 ServiceAccount">
    替换 `<control_plane_namespace>`：

    ```bash theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
    kubectl get serviceaccounts -n <control_plane_namespace> | grep host-backend
    ```
  </Step>

  <Step title="将 Role 绑定到控制平面 ServiceAccount">
    替换 `<data_plane_namespace>`、`<control_plane_namespace>` 和 `<control_plane_service_account>`：

    ```bash theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
    kubectl apply -n <data_plane_namespace> -f - <<EOF
    apiVersion: rbac.authorization.k8s.io/v1
    kind: RoleBinding
    metadata:
      name: read-agent-server-logs-role-binding
    subjects:
    - kind: ServiceAccount
      name: <control_plane_service_account>
      namespace: <control_plane_namespace>
    roleRef:
      apiGroup: rbac.authorization.k8s.io
      kind: Role
      name: read-agent-server-logs-role
    EOF
    ```
  </Step>
</Steps>

<Note>
  在此示例中，Role 和 RoleBinding 与 Agent Server 部署定义在同一个 Kubernetes 命名空间中。您可以为 Role 和 RoleBinding 分配任何名称，并根据需要进行自定义。
</Note>

## 后续步骤

基础设施设置完成后，您就可以部署代理应用程序了。请参阅[部署指南](/langsmith/deployment)以获取构建和部署代理应用程序的说明。

***

<div className="source-links">
  <Callout icon="terminal-2">
    [将这些文档](/use-these-docs)通过 MCP 连接到 Claude、VSCode 等，以获取实时答案。
  </Callout>

  <Callout icon="edit">
    [在 GitHub 上编辑此页面](https://github.com/langchain-ai/docs/edit/main/src/langsmith/deploy-self-hosted-full-platform.mdx)或[提交问题](https://github.com/langchain-ai/docs/issues/new/choose)。
  </Callout>
</div>
