外观
当你准备将 LangChain 智能体部署到生产环境时,请选择适合你技术栈的托管模式。LangSmith Cloud 为有状态、长期运行的智能体提供完全托管的、具有持久状态和后台执行能力的基础设施。
你也可以使用相同的智能体流式协议,部署到 JavaScript 框架和平台上,例如 Next.js、SvelteKit、Nuxt、Cloudflare Workers 和 Deno Deploy。
Frameworks and platforms
View all guides
LangSmith
Next.js
SvelteKit
Nuxt
Cloudflare
Deno
TIP
除了 Cloud 之外,LangSmith 还提供多种部署选项,包括混合部署、独立服务器和带控制面的自托管。更多信息请参见 LangSmith 部署概述。
LangSmith Cloud
本节将引导你从 GitHub 仓库将智能体部署到 LangSmith Cloud。LangSmith 负责处理基础设施、扩展和运维方面的问题。
前提条件
开始之前,请确保你具备以下条件:
- 一个 GitHub 账户
- 一个 LangSmith 账户(免费注册)
部署你的智能体
1. 在 GitHub 上创建仓库
要部署到 LangSmith,你的应用代码必须存放在 GitHub 仓库中。公有和私有仓库均受支持。在本快速入门中,首先按照本地服务器设置指南确保你的应用与 LangGraph 兼容。然后,将你的代码推送到仓库。
2. Deploy to LangSmith
Navigate to LangSmith Deployment
Log in to [LangSmith](https://smith.langchain.com). In the left sidebar, select **Deployments**.
Create new deployment
Click the **+ New Deployment** button. A pane will open where you can fill in the required fields.
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.
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:
- Select the deployment you just created to view more details.
- Click the Studio button in the top right corner. Studio will open to display your graph.
4. Get the API URL for your deployment
- In the Deployment details view in LangGraph, click the API URL to copy it to your clipboard.
- Click the
URLto copy it to the clipboard.
5. Test the API
You can now test the API:
Python
- Install LangGraph Python:
bash
pip install langgraph-sdk- Send a message to the agent:
python
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")Rest API
bash
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\", `# Name of agent. Defined in langgraph.json.`
\"input\": {
\"messages\": [
{
\"role\": \"human\",
\"content\": \"What is LangGraph?\"
}
]
},
\"stream_mode\": \"updates\"
}"TIP
LangSmith offers additional hosting options, including self-hosted and hybrid. For more information, please see the Platform setup overview.
2. Deploy to LangSmith
Navigate to LangSmith Deployment
Log in to [LangSmith](https://smith.langchain.com). In the left sidebar, select **Deployments**.
Create new deployment
Click the **+ New Deployment** button. A pane will open where you can fill in the required fields.
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.
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:
- Select the deployment you just created to view more details.
- Click the Studio button in the top right corner. Studio will open to display your graph.
4. Get the API URL for your deployment
- In the Deployment details view in LangGraph, click the API URL to copy it to your clipboard.
- Click the
URLto copy it to the clipboard.
5. Test the API
You can now test the API:
JavaScript
- Install LangGraph JS:
bash
npm install @langchain/langgraph-sdk- Send a message to the agent:
ts
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, // Threadless run
"agent", // Name of agent. Defined in 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");
}Rest API
bash
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\", `# Name of agent. Defined in langgraph.json.`
\"input\": {
\"messages\": [
{
\"role\": \"human\",
\"content\": \"What is LangGraph?\"
}
]
},
\"stream_mode\": \"updates\"
}"TIP
LangSmith offers additional hosting options, including self-hosted and hybrid. For more information, please see the Platform setup overview.