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

前置条件

在开始之前,请确保您具备以下条件:

部署您的代理

1. 在 GitHub 上创建代码仓库

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

2. Deploy to LangSmith

1

Navigate to LangSmith Deployment

Log in to LangSmith. In the left sidebar, select Deployments.
2

Create new deployment

Click the + New Deployment button. A pane will open where you can fill in the required fields.
3

Link repository

If you are a first time user or adding a private repository that has not been previously connected, click the Add new account button and follow the instructions to connect your GitHub account.
4

Deploy repository

Select your application’s repository. Click Submit to deploy. This may take about 15 minutes to complete. You can check the status in the Deployment details view.

3. Test your application in Studio

Once your application is deployed:
  1. Select the deployment you just created to view more details.
  2. Click the Studio button in the top right corner. Studio will open to display your graph.

4. Get the API URL for your deployment

  1. In the Deployment details view in LangGraph, click the API URL to copy it to your clipboard.
  2. Click the URL to copy it to the clipboard.

5. Test the API

You can now test the API:
  1. Install LangGraph Python:
pip install langgraph-sdk
  1. Send a message to the agent:
from langgraph_sdk import get_sync_client # or get_client for async

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

for chunk in client.runs.stream(
    None,    # Threadless run
    "agent", # Name of agent. Defined in 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")
LangSmith offers additional hosting options, including self-hosted and hybrid. For more information, please see the Platform setup overview.