快速入门:在LangGraph Cloud上部署¶
在 GitHub 上创建代码库¶
要将 LangGraph 应用程序部署到 LangGraph Cloud,您的应用程序代码必须位于 GitHub 代码库中。支持公共和私有代码库。
您可以将任何 LangGraph 应用程序部署到 LangGraph Cloud。
本指南中,我们将使用预构建的 Python ReAct Agent 模板。
获取 ReAct Agent 模板所需的 API 密钥
此 ReAct Agent 应用程序需要从 Anthropic 和 Tavily 获取 API 密钥。您可以在各自的网站上注册以获取这些 API 密钥。
替代方案:如果您更喜欢一个不需要 API 密钥的框架应用,请使用 New LangGraph Project 模板,而不是 ReAct Agent 模板。
- 访问 ReAct Agent 代码库。
- 点击右上角的
Fork
按钮,将代码库 fork 到您的 GitHub 账户中。
部署到LangGraph云¶
5. 选择仓库,配置环境变量等
LangGraph Studio Web UI¶
一旦您的应用程序部署完成,您就可以在**LangGraph Studio**中进行测试。
测试API¶
Note
下面的API调用是针对**ReAct Agent**模板的。如果你部署的是不同的应用,可能需要相应地调整API调用。
在使用之前,你需要获取你的LangGraph部署的URL
。你可以在“部署”视图中找到这个URL。点击“URL”将其复制到剪贴板。
你还需要确保你的API密钥设置正确,以便能够使用LangGraph Cloud进行身份验证。
安装LangGraph Python SDK
向助手发送消息(无线程运行)
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")
安装LangGraph Python SDK
向助手发送消息(无线程运行)
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")
安装LangGraph JS SDK
向助手发送消息(无线程运行)
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");
}
下一步¶
恭喜!如果您完成了本教程,那么您已经走在成为LangGraph Cloud专家的路上了。这里有一些其他资源,可以帮助您进一步提升技能:
LangGraph 框架¶
- LangGraph 教程:开始学习LangGraph框架。
- LangGraph 概念:了解LangGraph的基础概念。
- LangGraph 操作指南:常见任务的操作指南。
📚 更多关于LangGraph 平台的知识¶
利用这些资源扩展您的知识:
- LangGraph 平台概念:理解LangGraph平台的基础概念。
- LangGraph 平台操作指南:发现构建和部署应用程序的分步指南。
- 启动本地LangGraph服务器:本快速入门指南展示了如何启动本地LangGraph服务器,用于**ReAct Agent**模板。其他模板的步骤类似。