> ## 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.

# 将您的应用部署到云端

> 使用 LangGraph CLI 将您的第一个应用部署到 LangSmith Cloud。

本快速入门指南将向您展示如何使用 [`langgraph deploy`](/langsmith/cli#deploy) 命令将应用部署到 LangSmith Cloud。

<Tip>
  如需全面的云端部署指南（包括基于 GitHub 的部署和所有配置选项），请参阅[云端部署设置指南](/langsmith/deploy-to-cloud)。
</Tip>

<Note>
  `langgraph deploy` 命令目前处于 **Beta** 阶段。
</Note>

## 前提条件

开始之前，请确保您已具备：

* 一个 [LangSmith 账户](https://smith.langchain.com/)，且订阅了 [Plus 或更高套餐](https://www.langchain.com/pricing)，并拥有一个 [API 密钥](/langsmith/create-account-api-key)。
* 已安装并运行 [Docker](https://docs.docker.com/get-docker/)。可通过 `docker ps` 命令验证。
* 在 Apple Silicon (M1/M2/M3) 上：需要安装 [Docker Buildx](https://docs.docker.com/build/install-buildx/) 以交叉编译到 `linux/amd64`。
* 已安装 [LangGraph CLI](/langsmith/cli)：

  ```shell theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
  uv tool install langgraph-cli
  ```

## 1. 创建 LangGraph 应用

从 [`new-langgraph-project-python` 模板](https://github.com/langchain-ai/new-langgraph-project) 创建一个新应用：

```shell theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
langgraph new path/to/your/app --template new-langgraph-project-python
cd path/to/your/app
```

<Tip>
  运行 `langgraph new` 而不带 `--template` 参数，将显示一个交互式菜单，列出所有可用模板。
</Tip>

## 2. 设置您的 API 密钥

将您的 LangSmith API 密钥添加到项目根目录下的 `.env` 文件中：

```shell theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
LANGSMITH_API_KEY=lsv2_...
```

`langgraph deploy` 命令会自动读取此文件。或者，您也可以在命令行中直接传递：

```shell theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
LANGSMITH_API_KEY=lsv2_... langgraph deploy
```

## 3. 部署

在项目目录下运行部署命令：

```shell theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
langgraph deploy
```

这将默认创建一个名为 `dev` 的部署，其名称取自您的项目目录。您可以使用 `--name` 或 `--deployment-type prod` 来覆盖此设置。

<Tip>
  在代码更改后，要更新现有部署，请重新运行 `langgraph deploy`。它会按名称查找现有部署并就地更新。
</Tip>

您还可以使用 `langgraph deploy list` 查看所有部署，使用 `langgraph deploy logs` 跟踪运行时日志，以及使用 `langgraph deploy delete <ID>` 删除部署。详情请参阅 [CLI 参考文档](/langsmith/cli#deploy)。

## 4. 在 Studio 中测试

[Studio](/langsmith/studio) 是一个交互式智能体 IDE，可直接连接到您的部署。使用它来发送消息、检查每个节点的中间状态、在运行中编辑状态，以及从任何先前的检查点重放，无需编写代码。

部署就绪后：

1. 前往 [LangSmith](https://smith.langchain.com/) 并在左侧边栏中选择 **Deployments**。
2. 选择您的部署以查看其详细信息。
3. 点击右上角的 **Studio** 以打开 [Studio](/langsmith/studio)。

## 5. 测试 API

从部署详细信息视图中复制 **API URL**，然后使用它来调用您的应用：

<Tabs>
  <Tab title="Python SDK (异步)">
    1. 安装 LangGraph Python SDK：
       ```shell theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
       pip install langgraph-sdk
       ```
    2. 向助手发送消息（无状态运行）：
       ```python theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
       from langgraph_sdk import get_client

       client = get_client(url="your-deployment-url", api_key="your-langsmith-api-key")

       async for chunk in client.runs.stream(
           None,  # 无线程运行
           "agent", # 助手名称。在 langgraph.json 中定义。
           input={
               "messages": [{
                   "role": "human",
                   "content": "What is LangGraph?",
               }],
           },
           stream_mode="updates",
       ):
           print(f"Receiving new event of type: {chunk.event}...")
           print(chunk.data)
           print("\n\n")
       ```
  </Tab>

  <Tab title="Python SDK (同步)">
    1. 安装 LangGraph Python SDK：
       ```shell theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
       pip install langgraph-sdk
       ```
    2. 向助手发送消息（无线程运行）：
       ```python theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
       from langgraph_sdk import get_sync_client

       client = get_sync_client(url="your-deployment-url", api_key="your-langsmith-api-key")

       for chunk in client.runs.stream(
           None,  # 无线程运行
           "agent", # 助手名称。在 langgraph.json 中定义。
           input={
               "messages": [{
                   "role": "human",
                   "content": "What is LangGraph?",
               }],
           },
           stream_mode="updates",
       ):
           print(f"Receiving new event of type: {chunk.event}...")
           print(chunk.data)
           print("\n\n")
       ```
  </Tab>

  <Tab title="JavaScript SDK">
    1. 安装 LangGraph JS SDK：
       ```shell theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
       npm install @langchain/langgraph-sdk
       ```
    2. 向助手发送消息（无线程运行）：
       ```js 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", // 助手 ID
           {
               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\",
            \"input\": {
                \"messages\": [
                    {
                        \"role\": \"human\",
                        \"content\": \"What is LangGraph?\"
                    }
                ]
            },
            \"stream_mode\": \"updates\"
        }"
    ```
  </Tab>
</Tabs>

## 后续步骤

<CardGroup cols={3}>
  <Card title="助手" icon="robot" href="/langsmith/assistants">
    为每个助手部署相同的图，但使用不同的模型、提示词或工具。
  </Card>

  <Card title="线程" icon="messages" href="/langsmith/use-threads">
    跨多次运行持久化状态，使您的智能体能够记住交互之间的上下文。
  </Card>

  <Card title="运行" icon="player-play" href="/langsmith/background-run">
    为长时间运行的任务启动后台运行，并将结果流式传输回您的客户端。
  </Card>
</CardGroup>

***

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