> ## Documentation Index
> Fetch the complete documentation index at: https://langchain-zh.cn/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#set-up-local-agent-server)确保你的应用兼容 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="edit">
    [Edit this page on GitHub](https://github.com/langchain-ai/docs/edit/main/src/i18n\zh-CN\oss\langchain\deploy.mdx) or [file an issue](https://github.com/langchain-ai/docs/issues/new/choose).
  </Callout>

  <Callout icon="terminal-2">
    [Connect these docs](/use-these-docs) to Claude, VSCode, and more via MCP for real-time answers.
  </Callout>
</div>
