尧图网络科技YAOTU DIGITAL 获取报价
获取报价
首页 / 资讯中心 / 文章详情

(LangGraph教程)1. Introduction——Lesson 8: Deployment(可选)(好像没啥用,还得开会员)

发布时间:2026/9/24 17:11:17

资讯中心
01
ARTICLE

(LangGraph教程)1. Introduction——Lesson 8: Deployment(可选)(好像没啥用,还得开会员)

(LangGraph教程)1. Introduction——Lesson 8: Deployment(可选)(好像没啥用,还得开会员)
https://academy.langchain.com/courses/intro-to-langgraphhttps://github.com/shangxiang0907/langchain-academy文章目录[Optional] Lesson 8: DeploymentLangSmith Deployment was formerly LangGraph Platform.Deployment 部署Review 回顾Goals 目标Concepts 概念Testing Locally 本地测试StudioTesting with Cloud 使用云服务测试Create a New Repository on GitHub 在 GitHub 上新建仓库Add Your GitHub Repository as a Remote 将您的 GitHub 仓库添加为远程仓库Connect LangSmith to your GitHub Repository 将 LangSmith 连接到您的 GitHub 仓库Work with your deployment 与你的部署交互[Optional] Lesson 8: Deployment中文[可选] 第8课部署Currently, LangSmith Deployment is available only for LangSmith Plus plan users.中文目前LangSmith Deployment 仅向 LangSmith Plus 套餐用户开放。Lesson 8 in this course is optional.中文本课程的第8课为可选内容。LangSmith Deployment was formerly LangGraph Platform.中文LangSmith Deployment 原名为 LangGraph Platform。Notebook Reference: deployment.ipynb中文笔记本参考文件deployment.ipynbDownload Notebook onGitHub中文在GitHub上下载笔记本。View Notebook onGoogle Colab中文在Google Colab上查看笔记本。Deployment 部署Review 回顾We built up to an agent with memory:我们已构建出一个具备记忆能力的智能体act- let the model call specific toolsact— 允许模型调用特定工具observe- pass the tool output back to the modelobserve— 将工具输出传回模型reason- let the model reason about the tool output to decide what to do next (e.g., call another tool or just respond directly)reason— 让模型基于工具输出进行推理以决定下一步操作例如调用另一工具或直接响应persist state- use an in memory checkpointer to support long-running conversations with interruptionspersist state— 使用内存中的检查点器checkpointer支持带中断的长时间运行对话Goals 目标Now, we’ll cover how to actually deploy our agent locally to Studio and toLangGraph Cloud.接下来我们将介绍如何将智能体实际部署到本地 Studio 和LangGraph Cloud。%%capture--no-stderr%pip install--quiet-U langgraph_sdk langchain_coreConcepts 概念There are a few central concepts to understand -需理解若干核心概念 —LangGraph—LangGraph—Python and JavaScript libraryPython 与 JavaScript 库Allows creation of agent workflows支持创建智能体工作流LangGraph API—LangGraph API—Bundles the graph code封装图graph代码Provides a task queue for managing asynchronous operations提供任务队列用于管理异步操作Offers persistence for maintaining state across interactions提供持久化能力以在多次交互间维持状态LangSmith Deployment(formerlyLangGraph Cloud) –LangSmith Deployment原LangGraph Cloud——Hosted service for the LangGraph API托管式 LangGraph API 服务Allows deployment of graphs from GitHub repositories支持从 GitHub 仓库部署图Also provides monitoring and tracing for deployed graphs还为已部署的图提供监控与追踪功能Accessible via a unique URL for each deployment每个部署均通过唯一 URL 访问LangSmith Studio(formerlyLangGraph Studio) –LangSmith Studio原LangGraph Studio——Integrated Development Environment (IDE) for LangGraph applications面向 LangGraph 应用的集成开发环境IDEUses the API as its back-end, allowing real-time testing and exploration of graphs以后端 API 为基础支持对图进行实时测试与探索Can be run locally or with cloud-deployment. See below.可本地运行亦支持云部署。详见下文。LangGraph SDK–LangGraph SDK——Python library for programmatically interacting with LangGraph graphs用于以编程方式与 LangGraph 图交互的 Python 库Provides a consistent interface for working with graphs, whether served locally or in the cloud无论图是本地托管还是云端托管均提供统一接口Allows creation of clients, access to assistants, thread management, and execution of runs支持创建客户端、访问助手、线程管理及执行运行runTesting Locally 本地测试Studio⚠️ Notice⚠️ 注意Since filming these videos, we’ve updated Studio so that it can now be run locally and accessed through your browser.自录制本系列视频以来我们已更新 Studio使其现在可本地运行并可通过浏览器访问。This is the preferred way to run Studio instead of using the Desktop App shown in the video.这是运行 Studio 的首选方式而非视频中演示的桌面应用。It is now calledLangSmith Studioinstead ofLangGraph Studio.它现称为LangSmith Studio而非LangGraph Studio。Detailed setup instructions are available in the “Getting Setup” guide at the start of the course.详细安装说明请参阅本课程开头的“开始设置”指南。You can find a description of Studio here, and specific details for local deployment here.您可在此处查看 Studio 的说明文档 此处本地部署的具体细节请参见 此处。To start the local development server, run the following command in your terminal in the/studiodirectory in this module:要在本地启动开发服务器请在本模块的/studio目录下于终端中运行以下命令langgraph devYou should see the following output:您应看到如下输出- API: http://127.0.0.1:2024 - Studio UI: https://smith.langchain.com/studio/?baseUrlhttp://127.0.0.1:2024 - API Docs: http://127.0.0.1:2024/docsOpen your browser and navigate to theStudio UIURL shown above.打开浏览器并导航至上方显示的Studio UIURL。ifgoogle.colabinstr(get_ipython()):raiseException(Unfortunately LangGraph Studio is currently not supported on Google Colab)fromlanggraph_sdkimportget_client# This is the URL of the local development serverURLhttp://127.0.0.1:2024clientget_client(urlURL)# Search all hosted graphsassistantsawaitclient.assistants.search()assistants[-3]{assistant_id: fe096781-5601-53d2-b2f6-0d3403f7e9ca, graph_id: agent, config: {}, metadata: {created_by: system}, name: agent, created_at: 2025-03-04T22:57:28.42456500:00, updated_at: 2025-03-04T22:57:28.42456500:00, version: 1}# We create a thread for tracking the state of our runthreadawaitclient.threads.create()Now, we can run our agent withclient.runs.streamwith:现在我们可以使用client.runs.stream运行我们的智能体Thethread_idThegraph_idTheinputThestream_modeWe’ll discuss streaming in depth in a future module.我们将在后续模块中深入探讨流式处理streaming。For now, just recognize that we are streaming the full value of the state after each step of the graph withstream_modevalues.目前只需了解我们正以stream_modevalues方式 流式传输即在图每一步执行后输出完整状态值。The state is captured in thechunk.data.状态值保存在chunk.data中。fromlangchain_core.messagesimportHumanMessage# Inputinput{messages:[HumanMessage(contentMultiply 3 by 2.)]}# Streamasyncforchunkinclient.runs.stream(thread[thread_id],agent,inputinput,stream_modevalues,):ifchunk.dataandchunk.event!metadata:print(chunk.data[messages][-1]){content: Multiply 3 by 2., additional_kwargs: {example: False, additional_kwargs: {}, response_metadata: {}}, response_metadata: {}, type: human, name: None, id: cdbd7bd8-c476-4ad4-8ab7-4ad9e3654267, example: False} {content: , additional_kwargs: {tool_calls: [{index: 0, id: call_iIPryzZZxRtXozwwhVtFObNO, function: {arguments: {a:3,b:2}, name: multiply}, type: function}]}, response_metadata: {finish_reason: tool_calls, model_name: gpt-4o-2024-05-13, system_fingerprint: fp_157b3831f5}, type: ai, name: None, id: run-06c7243c-426d-4c81-a113-f1335dda5fb2, example: False, tool_calls: [{name: multiply, args: {a: 3, b: 2}, id: call_iIPryzZZxRtXozwwhVtFObNO, type: tool_call}], invalid_tool_calls: [], usage_metadata: None} {content: 6, additional_kwargs: {}, response_metadata: {}, type: tool, name: multiply, id: 988cb170-f6e6-43c1-82fd-309f519abe6d, tool_call_id: call_iIPryzZZxRtXozwwhVtFObNO, artifact: None, status: success} {content: The result of multiplying 3 by 2 is 6., additional_kwargs: {}, response_metadata: {finish_reason: stop, model_name: gpt-4o-2024-05-13, system_fingerprint: fp_157b3831f5}, type: ai, name: None, id: run-7bda0aa0-6895-4250-9625-18419c5dc171, example: False, tool_calls: [], invalid_tool_calls: [], usage_metadata: None}Testing with Cloud 使用云服务测试We can deploy to Cloud via LangSmith, as outlined here.我们可通过 LangSmith 部署至云服务具体步骤详见 此处。Create a New Repository on GitHub 在 GitHub 上新建仓库Go to your GitHub account前往您的 GitHub 账户Click on the “” icon in the upper-right corner and selectNew repository点击右上角的 “” 图标选择“New repository”Name your repository (e.g.,langchain-academy)为您的仓库命名例如langchain-academyAdd Your GitHub Repository as a Remote 将您的 GitHub 仓库添加为远程仓库Go back to your terminal where you clonedlangchain-academyat the start of this course返回本课程初始时克隆langchain-academy的终端Add your newly created GitHub repository as a remote将新创建的 GitHub 仓库添加为远程仓库git remote add origin https://github.com/your-username/your-repo-name.gitPush to it推送至该仓库git push -u origin mainConnect LangSmith to your GitHub Repository 将 LangSmith 连接到您的 GitHub 仓库Go to LangSmith访问 LangSmithClick ondeploymentstab on the left LangSmith panel点击 LangSmith 左侧面板中的deployments标签页Add New Deployment添加 新建部署Then, select the Github repository (e.g.,langchain-academy) that you just created for the course然后选择你为本课程刚刚创建的 GitHub 仓库例如langchain-academyPoint theLangGraph API config fileat one of thestudiodirectories将LangGraph API 配置文件指向某个studio目录For example, for module-1 use:module-1/studio/langgraph.json例如对于 module-1请使用module-1/studio/langgraph.jsonSet your API keys (e.g., you can just copy from yourmodule-1/studio/.envfile)设置你的 API 密钥例如可直接从module-1/studio/.env文件中复制Work with your deployment 与你的部署交互We can then interact with our deployment a few different ways:随后我们可通过几种不同方式与部署进行交互With the SDK, as before.使用 SDK方式与之前相同。With LangGraph Studio.使用 LangGraph Studio。To use the SDK here in the notebook, simply ensure thatLANGSMITH_API_KEYis set!若要在本笔记本中使用 SDK请确保已设置LANGSMITH_API_KEYimportos,getpassdef_set_env(var:str):ifnotos.environ.get(var):os.environ[var]getpass.getpass(f{var}: )_set_env(LANGSMITH_API_KEY)# Replace this with the URL of your deployed graphURLhttps://langchain-academy-8011c561878d50b1883f7ed11b32d720.default.us.langgraph.appclientget_client(urlURL)# Search all hosted graphsassistantsawaitclient.assistants.search()# Select the agentagentassistants[0]agent{assistant_id: fe096781-5601-53d2-b2f6-0d3403f7e9ca, graph_id: agent, created_at: 2024-08-23T17:58:02.72292000:00, updated_at: 2024-08-23T17:58:02.72292000:00, config: {}, metadata: {created_by: system}}fromlangchain_core.messagesimportHumanMessage# We create a thread for tracking the state of our runthreadawaitclient.threads.create()# Inputinput{messages:[HumanMessage(contentMultiply 3 by 2.)]}# Streamasyncforchunkinclient.runs.stream(thread[thread_id],agent,inputinput,stream_modevalues,):ifchunk.dataandchunk.event!metadata:print(chunk.data[messages][-1]){content: Multiply 3 by 2., additional_kwargs: {example: False, additional_kwargs: {}, response_metadata: {}}, response_metadata: {}, type: human, name: None, id: 8ea04559-f7d4-4c82-89d9-c60fb0502f21, example: False} {content: , additional_kwargs: {tool_calls: [{index: 0, id: call_EQoolxFaaSVU8HrTnCmffLk7, function: {arguments: {a:3,b:2}, name: multiply}, type: function}]}, response_metadata: {finish_reason: tool_calls, model_name: gpt-4o-2024-05-13, system_fingerprint: fp_3aa7262c27}, type: ai, name: None, id: run-b0ea5ddd-e9ba-4242-bb8c-80eb52466c76, example: False, tool_calls: [{name: multiply, args: {a: 3, b: 2}, id: call_EQoolxFaaSVU8HrTnCmffLk7, type: tool_call}], invalid_tool_calls: [], usage_metadata: None} {content: 6, additional_kwargs: {}, response_metadata: {}, type: tool, name: multiply, id: 1bf558e7-79ef-4f21-bb66-acafbd04677a, tool_call_id: call_EQoolxFaaSVU8HrTnCmffLk7, artifact: None, status: success} {content: 3 multiplied by 2 equals 6., additional_kwargs: {}, response_metadata: {finish_reason: stop, model_name: gpt-4o-2024-05-13, system_fingerprint: fp_3aa7262c27}, type: ai, name: None, id: run-ecc4b6ad-af15-4a85-a76c-de2ed0ed8ed9, example: False, tool_calls: [], invalid_tool_calls: [], usage_metadata: None}
02
RELATED NEWS

相关资讯

更多网站建设与数字化升级内容

03
WHY YAOTU

想打造同款高转化官网?

懂行业、懂生意,从建站到增长一站式陪跑

场景化定制

不做模板站,围绕你的业务场景量身设计,小众不撞款。

营销型架构

以转化目标组织内容与路径,让官网真正带来询盘。

全周期服务

设计、开发、运营、运维一体,上线只是开始。

免费获取你的建站方案

留下需求,专属顾问 24 小时内为你输出方案建议。