> ## 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 部署

当您准备好将 LangChain 代理部署到生产环境时，LangSmith 提供了一个专为代理工作负载设计的托管平台。传统的托管平台是为无状态、短生命周期的 Web 应用程序构建的，而 LangGraph 则是**专为有状态、长时间运行的代理**构建的，这些代理需要持久化状态和后台执行。LangSmith 处理基础设施、扩展和运维问题，因此您可以直接从代码仓库进行部署。

## 前提条件

在开始之前，请确保您具备以下条件：

* 一个 [GitHub 账户](https://github.com/)
* 一个 [LangSmith 账户](https://smith.langchain.com/)（免费注册）

## 部署您的代理

### 1. 在 GitHub 上创建一个代码仓库

您的应用程序代码必须位于 GitHub 代码仓库中，才能在 LangSmith 上部署。公共和私有代码仓库均受支持。对于本快速入门指南，首先请按照[本地服务器设置指南](/oss/javascript/langchain/studio)确保您的应用与 LangGraph 兼容。然后，将您的代码推送到代码仓库。

### 2. 部署到 LangSmith

<Steps>
  <Step title="导航至 LangSmith 部署">
    登录 [LangSmith](https://smith.langchain.com/)。在左侧边栏中，选择 **部署**。
  </Step>

  <Step title="创建新部署">
    点击 **+ 新建部署** 按钮。将打开一个面板，您可以在其中填写所需字段。
  </Step>

  <Step title="关联仓库">
    如果您是首次用户或添加一个尚未关联过的私有仓库，请点击 **添加新账户** 按钮，并按照说明关联您的 GitHub 账户。
  </Step>

  <Step title="部署仓库">
    选择您应用程序的仓库。点击 **提交** 进行部署。此过程可能需要约 15 分钟完成。您可以在 **部署详情** 视图中查看状态。
  </Step>
</Steps>

### 3. 在 Studio 中测试您的应用程序

您的应用程序部署完成后：

1. 选择您刚刚创建的部署以查看更多详情。
2. 点击右上角的 **Studio** 按钮。Studio 将打开并显示您的图。

### 4. 获取部署的 API URL

1. 在 LangGraph 的 **部署详情** 视图中，点击 **API URL** 将其复制到剪贴板。
2. 点击 `URL` 将其复制到剪贴板。

### 5. 测试 API

您现在可以测试 API：

<Tabs>
  <Tab title="JavaScript">
    1. 安装 LangGraph JS：

    ```shell theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
    npm install @langchain/langgraph-sdk
    ```

    2. 向代理发送消息：

    ```ts theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
    const { Client } = await import("@langchain/langgraph-sdk");

    const client = new Client({ apiUrl: "your-deployment-url", apiKey: "your-langsmith-api-key" });

    const streamResponse = client.runs.stream(
        null,    // 无线程运行
        "agent", // 代理名称。在 langgraph.json 中定义。
        {
            input: {
                "messages": [
                    { "role": "user", "content": "What is LangGraph?"}
                ]
            },
            streamMode: "messages",
        }
    );

    for await (const chunk of streamResponse) {
        console.log(`Receiving new event of type: ${chunk.event}...`);
        console.log(JSON.stringify(chunk.data));
        console.log("\n\n");
    }
    ```
  </Tab>

  <Tab title="Rest API">
    ```bash theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
    curl -s --request POST \
        --url <DEPLOYMENT_URL>/runs/stream \
        --header 'Content-Type: application/json' \
        --header "X-Api-Key: <LANGSMITH API KEY> \
        --data "{
            \"assistant_id\": \"agent\", `# 代理名称。在 langgraph.json 中定义。`
            \"input\": {
                \"messages\": [
                    {
                        \"role\": \"human\",
                        \"content\": \"What is LangGraph?\"
                    }
                ]
            },
            \"stream_mode\": \"updates\"
        }"
    ```
  </Tab>
</Tabs>

<Tip>
  LangSmith 提供额外的托管选项，包括自托管和混合托管。更多信息，请参阅 [平台设置概述](/langsmith/platform-setup)。
</Tip>

***

<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/oss/langchain/deploy.mdx) 或 [提交问题](https://github.com/langchain-ai/docs/issues/new/choose)。
  </Callout>
</div>
