(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}

相关新闻

【爆款全新升级】性能再突破!正点原子全新升级T300 Pro智能焊台来了!温控更强、功能更全,工程师、维修爱好者的专业焊接利器!

【爆款全新升级】性能再突破!正点原子全新升级T300 Pro智能焊台来了!温控更强、功能更全,工程师、维修爱好者的专业焊接利器!

玩嵌入式、修板、做硬件的工程师与电子爱好者看过来! 不少电子爱好者、维修工程师一直偏爱正点原子 T300 智能焊台。凭借稳定温控、易用交互、扎实做工,T300 成为工作室、实验室、DIY 桌面的热门焊接工具。 今天,万众期待的升级款正式登场…

2026/9/24 17:11:19 阅读更多 →
bilingual_book_maker 提示词定制指南:从 PromptDown 到 --prompt 的完整实战解析

bilingual_book_maker 提示词定制指南:从 PromptDown 到 --prompt 的完整实战解析

AI 应用NLPCLI 【免费下载链接】bilingual_book_maker Make bilingual epub books Using AI translate 项目地址: https://gitcode.com/gh_mirrors/bi/bilingual_book_maker 点击查看 免费下载 本篇技术指南围绕本仓库根目录下的 prompt_md.prompt.md 展开&#xf…

2026/9/24 17:10:18 阅读更多 →
SwiftPM 演进路线图解读:从 EvolutionIdeas 到已落地的 Package Manager 能力

SwiftPM 演进路线图解读:从 EvolutionIdeas 到已落地的 Package Manager 能力

开发工具构建工具 【免费下载链接】swift-package-manager The Package Manager for the Swift Programming Language 项目地址: https://gitcode.com/gh_mirrors/sw/swift-package-manager 点击查看 免费下载 Swift Package Manager(SwiftPM&#xff0…

2026/9/24 17:10:18 阅读更多 →

最新新闻

OpenFOAM二次开发教程(12):函数对象开发——coded 与编译型 functionObject

OpenFOAM二次开发教程(12):函数对象开发——coded 与编译型 functionObject

OpenFOAM二次开发教程(12):函数对象开发——coded 与编译型 functionObject版本与事实声明 functions 条目的结构与继承项(region、enabled、log、timeStart、timeEnd、executeControl、executeInterval、writeControl、writeInte…

2026/9/24 17:55:46 阅读更多 →
RL-赵-(五)-不基于模型1:MC算法05【MC ε-Greedy】【把只能从(s,a)对开始的条件去掉】【软策略:每个动作都有可能;通过ε平衡exploitation与exploration】

RL-赵-(五)-不基于模型1:MC算法05【MC ε-Greedy】【把只能从(s,a)对开始的条件去掉】【软策略:每个动作都有可能;通过ε平衡exploitation与exploration】

四、MC ε-Greedy(MC without exploring starts ) 1、Soft Policies(软策略) 什么是Soft policies?如果一个策略采取的每一个action的概率是positive,也就是这些action都有可能被采取,那么这个策略就称为soft policy。 为什么要引入软策略? 使用软策略,一些足够长的…

2026/9/24 17:55:46 阅读更多 →
Terminal.Gui 滚动机制详解:Content Area、Viewport 与 ScrollBar 术语体系实战指南

Terminal.Gui 滚动机制详解:Content Area、Viewport 与 ScrollBar 术语体系实战指南

UI组件跨平台桌面应用 【免费下载链接】Terminal.Gui Cross Platform Terminal UI toolkit for .NET 项目地址: https://gitcode.com/gh_mirrors/te/Terminal.Gui 点击查看 免费下载 滚动是终端 UI(TUI)开发中最基础也最容易出错的能力之一&…

2026/9/24 17:55:46 阅读更多 →
计算机毕业转AI应用开发,拿到字节25K Offer,我想说

计算机毕业转AI应用开发,拿到字节25K Offer,我想说

毕业拿到字节AI应用开发25K Offer以后,很多同学问我: 是不是因为我算法特别强? 是不是提前刷了很多大模型源码? 其实都不是。 回头看整个过程,我觉得自己真正做对的一件事,是没有把目标定成“成为算法工程师…

2026/9/24 17:55:46 阅读更多 →
光催化第一性原理结构优化计算方案设计的三个关键步骤

光催化第一性原理结构优化计算方案设计的三个关键步骤

第一步:明确优化目标与初始构型搭建在进行光催化材料的第一性原理结构优化前,需要先明确研究的核心目标,这决定了后续计算策略。光催化过程通常涉及光吸收、载流子分离、表面反应三个环节。因此,结构优化方案的设计需围绕这三个方…

2026/9/24 17:55:46 阅读更多 →
博客系统接口测试用例设计

博客系统接口测试用例设计

2026/9/24 17:54:46 阅读更多 →

日新闻

基于YOLOv8的渔船作业监控系统:从环境搭建到边缘部署全流程

基于YOLOv8的渔船作业监控系统:从环境搭建到边缘部署全流程

简介:这是一套面向计算机、人工智能、自动化等专业学生与教师的毕业设计级项目资源,围绕YOLOv8实现渔船作业监控系统,可用于毕设、课程设计、大作业或项目立项演示。压缩包共97个文件,约24.21MB,以70个Python源码文件为…

2026/9/24 0:00:19 阅读更多 →
单细胞注释实战:基于Scanpy的标记基因与参考映射流程解析

单细胞注释实战:基于Scanpy的标记基因与参考映射流程解析

简介:一份基于单细胞RNA测序数据的细胞类型注释算法研究Python毕业设计源码,针对计算机相关专业正在做毕设或需要项目实战的学习者,可用于课程设计与期末大作业。项目代码完整、经导师指导评审通过,可直接运行,覆盖数据…

2026/9/24 0:00:19 阅读更多 →
C#源生成器实战:用增量生成器替代反射,告别AOT崩溃

C#源生成器实战:用增量生成器替代反射,告别AOT崩溃

第一次在项目里被反射卡住,是在一个老旧的WinForms模块里:几十个类依赖PropertyChanged通知,运行时反射读属性、发通知,每次启动慢半拍不说,一上.NET Native/AOT裁剪模式几乎全面崩盘。后来我把这段逻辑全部改成C#源生…

2026/9/24 0:00:19 阅读更多 →

周新闻

Flutter for OpenHarmony游戏卡片渐变背景实战:从原理到性能优化

Flutter for OpenHarmony游戏卡片渐变背景实战:从原理到性能优化

直接铺开项目本身吧。这几个月我一直在折腾一件事:用Flutter给OpenHarmony做一款游戏集合类的App,说白了就是把若干小游戏塞进一个壳里,用统一入口分发。这个方向本身不算新鲜,真正让我花了不少心思的,是首页那堆游戏卡…

2026/9/24 14:34:13 阅读更多 →
Word表格编号全攻略:从列表编号到题注交叉引用

Word表格编号全攻略:从列表编号到题注交叉引用

写Word文档,最让人头疼的往往是那些“看起来不起眼”的小问题。比如表格编号这事:今天在表后面多加了两个空白行,明天给客户交稿前发现整个章节的编号全部错位,光是挨个改序号就能耗掉大半个下午。我前阵子帮人整理一份上百页的技…

2026/9/24 9:10:42 阅读更多 →
从第一个站到第二个站:独立开发者的静态网站选型与落地实践

从第一个站到第二个站:独立开发者的静态网站选型与落地实践

1. 项目概述1.1 核心需求解析做独立开发者这几年,说实话,第一个网站上线的那天晚上我兴奋得没睡着。但等它跑了半年,流量惨淡、功能臃肿、代码自己都懒得看第二遍之后,我才慢慢琢磨明白一个道理:第一个网站是练手&…

2026/9/24 14:33:56 阅读更多 →

月新闻

持续集成 流水线自动化与 声明式交付 实践:原型怎样变成可用功能

持续集成 流水线自动化与 声明式交付 实践:原型怎样变成可用功能

持续集成 流水线自动化与 声明式交付 实践:原型怎样变成可用功能分类:[AI/大模型]细分主题:AI 增强型 CI/CD 流水线自动化与 GitOps 实践:Agent 工作流、工具调用与任务拆解:从原型到生产的验收清单很多团队在尝试用大…

2026/9/24 12:50:34 阅读更多 →
容器编排 生产环境运维与排障实战:复盘记录怎样真正派上用场

容器编排 生产环境运维与排障实战:复盘记录怎样真正派上用场

容器编排 生产环境运维与排障实战:复盘记录怎样真正派上用场分类:[工程技术]细分主题:Kubernetes 生产环境运维与排障实战:可复制的项目复盘模板与决策记录大部分团队的事故复盘报告,最后都变成了躺在 Confluence 或钉…

2026/9/24 14:33:48 阅读更多 →
容器 容器化技术与镜像安全管理:核心链路应该先拆哪一步

容器 容器化技术与镜像安全管理:核心链路应该先拆哪一步

容器 容器化技术与镜像安全管理:核心链路应该先拆哪一步分类:[工程技术]细分主题:Docker 容器化技术与镜像安全管理:核心链路的逐步实现与关键代码取舍面对一个积累了五六年历史包袱的单体架构应用(包含 Web 接口、后台…

2026/9/24 12:49:17 阅读更多 →