推出托管式深度代理 | Interrupt 26
TL;DR · AI 摘要
LangChain 推出 Managed Deep Agents,其核心是可定制的代理“harness”架构,通过执行环境、上下文管理、任务委派与人机协同四大能力支持复杂现实任务。
核心要点
- Deep Agents 的 harness 包含四大能力:执行环境(文件系统+沙箱/代码解释器)、上下文管理(短/长期记忆+摘要+缓存)、任务委派(子代理协作)
- 代理依赖文件系统读写临时文件、加载持久化记忆、调用技能,且因训练数据含大量代码,天然适配代码执行环境
- 上下文管理模块提供 context offloading 与 prompt caching,可缓解长周期运行中的上下文溢出问题
结构提纲
按章节快速跳转。
代理是模型与工具调用的循环过程,而 harness 是连接模型与现实世界的全部组件,包括技能、记忆、提示词、工具与上下文。
Deep Agents 是专为复杂现实任务设计的可定制 harness,包含执行环境、上下文管理、任务委派与人机协同四大能力。
执行环境以文件系统为基石,可选配沙箱或轻量级代码解释器,使代理能安全读写文件、执行代码并调用技能。
上下文管理模块支持短/长期记忆、自动摘要、上下文卸载与提示缓存,有效应对长周期任务中的上下文溢出问题。
Deep Agents 支持通过子代理进行任务分解与并行处理,并内置一级支持的人机协同机制,适用于敏感工作流。
思维导图
用一张图看清主题之间的关系。
查看大纲文本(无障碍 / 无 JS 友好)
- Managed Deep Agents (LangChain)
- 核心概念
- Agent = Model + Harness
- Harness = 连接模型与现实世界的全部组件
- 四大能力
- 执行环境
- 上下文管理
- 任务委派
- 人机协同
- 执行环境细节
- 文件系统(基础)
- 沙箱 / 代码解释器(可选增强)
- 支持读写、记忆存储、技能调用
- 上下文管理组件
- 短/长期记忆
- 自动摘要
- 上下文卸载
- Prompt 缓存
金句 / Highlights
值得收藏与分享的关键句。
harness 是连接模型与现实世界的一切——技能、记忆、系统提示、工具、子代理及附加上下文。
代理极擅长使用文件系统:它们在训练中接触大量文件操作与代码,因此沙箱/代码解释器极具价值。
上下文管理包含开箱即用的短/长期记忆、摘要、上下文卸载与提示缓存,可避免长周期运行中的上下文溢出。
视频笔记
translation:
YouTube Transcript
language: English ( automatically generated) (en)
[0:07] Hi folks. I'm Sydney and I am an open
[0:10] source engineer at Lang Chain.
[0:12] Hi, I'm Victor. I'm a product manager.
[0:14] And today we're going to be walking
[0:15] through managed deep agents. But before
[0:18] we talk about that, Sydney's going to
[0:19] walk us through deep agents as a
[0:21] harness.
[0:24] So, first off, what is an agent?
[0:28] An agent is a simple model and tool
[0:30] calling loop. A model calling tools in a
[0:33] loop until it completes a task and
[0:35] returns a final result.
[0:39] What is a harness?
[0:41] We can define a harness as
[0:44] or we can define an agent as a model
[0:46] plus a harness.
[0:48] So, the harness is everything that
[0:49] connects the model to the real world.
[0:52] Everything around the model that helps
[0:54] it complete tasks.
[0:56] So, this is made up of skills,
[0:58] memory,
[1:00] the base system prompt,
[1:02] tools, sub agents, and any additional
[1:04] context.
[1:07] What's the job of a harness?
[1:10] So, the job of a harness is to get the
[1:12] model the right context at the right
[1:14] time for the given task.
[1:17] A model is only as powerful as the
[1:19] context that it's given. And so, the
[1:21] harness exists to bridge this gap.
[1:26] Why do you need a harness? well, agents
[1:29] have a lot of jobs.
[1:30] agents need to work in an environment
[1:33] where they can take actions.
[1:35] This action taking is what gives them
[1:38] agency. That's what makes agents useful.
[1:41] They need to connect to your data so
[1:44] that their actions are relevant for your
[1:46] use case.
[1:48] They need to manage growing context over
[1:50] long runs so that they can avoid context
[1:53] overflow.
[1:56] They need to be able to parallelize
[1:57] tasks to complete complex tasks
[2:00] efficiently.
[2:02] They need to connect with a human in the
[2:04] loop for sensitive workbooks.
[2:07] And finally, ideal, they improve over
[2:09] time so that they remain relevant and
[2:11] useful.
[2:14] So,
[2:15] what is Deep agents?
[2:17] Deep agents is a customizable agent
[2:19] harness
[2:21] that's purpose built for complex
[2:23] real-world tasks.
[2:26] First, I'm going to cover the four main
[2:29] capabilities that are part of the Deep
[2:31] agents harness, and then we'll do kind
[2:33] of a deep dive into each one.
[2:35] So, first up, we have the execution
[2:37] environment. This is the back ground of a
[2:40] Deep Agent, and it all starts with the
[2:42] file system.
[2:45]Optionally, you can also augmented this
[2:47] with a sandbox or, similarly, a code
[2:50]_interpreter.
[2:53] Next, we have, I think, the most
[2:55] important capability, which is the context
[2:57] management. So, there are lots of
[3:00] utilities built into Deep Agent that
[3:02] help with this natural order.
[3:04] That includes skill support,
[3:07] out-of-the box support for short- and
[3:09] long-term memory,(summarization capabilities,
[3:10] context offloading, andFP])** caching.
[3:18] The third capability is delegation.
[3:20] As agents run for longer amounts of time
[3:23] and take on complex workbooks, they need
[3:26] to be able to plan and organize tasks,
[3:29] and then also use sub agents to get
[3:31] delegate work.
[3:34] Finally, we build steering into the Deep
[3:36] agents harness with first class
[3:39] human-in-the loop support.
[3:43] So, now for our deep dive.
[3:45] Starting with the execution environment,
[3:46] which I mentioned is the back ground of a
[3:48] Deep Agent, this capability powers all
[3:51] of the rest.
[3:53] So, we start with the file system.
[3:56] An agent uses a file system to read and
[3:58] write scratch files as it tuna work,
[4:02] load and store persistent memories in
[4:05] the hot path, invoke skills when relevant for a given
[4:09] task, and many more things.
[4:12] agents are excellent at using file systems.
[4:14] They are trained in an environment to use file systems, and also train on
[4:18] code.
[4:21] And that's why giving an agent a
[4:25] sandbox, or lighter weight cousin, the code_interpreter,
[4:28] is very power.
[4:32] When you give an agent these code
[4:33] execution tools, you give it a safe environment to write and run code, which makes an agent capable of much, much more create problem-solving, and kind of dynamic run-time behavior.
[4:48] The second capability is context management.
[4:51] Deep Agent ships with built-in(summarization and context offloading.
[4:54] You can see on the graph here,(period, Deep Agent will evict large messages, so that can be human messages, tool results, tool calls to the file system so that we don't build up context in the window too quickly.
[4:57] Additionally,(summarization is triggered less frequently, but every so often when the history starts to approach the model's context limit.
[4:59] Both of these are in an effort to avoid context overflow, which is a problem that plugging agents, or high context agents, or both.
[5:02] Deep Agent also ships with built-in])** memory support.
[5:05] translation:
translation:
translation:
translation:
translation:
translation:
translation:
translation:
translation:
translation:
translation:
translation:
translation:
translation:
translation:
translation:
translation:
translation:
translation:
translation:
translation:
translation:
translation:
translation:
translation:
translation:
translation:
translation:
translation:
translation:
translation:
translation:
translation:
translation:
translation:
translation:
translation:
translation:
translation:
translation:
translation:
translation:
translation:
translation:
translation:
translation:
translation:
translation:
translation:
translation:
translation:
translation:
translation:
translation:
translation:
translation:
translation:
translation:
translation:
translation:
translation:
translation:
translation:
translation:
translation:
translation:
translation:
translation:
translation:
translation:
translation:
translation:
translation:
translation:
translation:
translation:
translation:
translation:
translation:
translation:
translation:
translation:
translation:
translation:
translation:
translation:
translation:
translation:
translation:
translation:
translation
[5:36] 我认为,记忆可能是最重要的上下文类型,因为它会随每次运行而变化,从而使你的智能体能够持续改进。
[5:38] 它还内置了与提供商无关的提示词缓存功能。
[5:41] 这对需要高效运行、且具备高上下文能力的长期运行型智能体而言至关重要。
[5:43] 最后,Deep Agent 从一开始就支持技能(skill)功能。
[5:45] 技能是上下文管理系统的一部分——这是由一种名为“渐进式披露”(progressive disclosure)的机制所实现的。
[5:48] 因此,Deep Agent 会将关于智能体可用技能的最精简信息提前加载到系统提示中;随后,我们赋予智能体动态加载完整技能资源并根据具体任务在脚本中调用这些技能的能力。
[5:50] 所有这一切
[5:52] 都属于一个统称的上下文管理范畴,
[5:54] 再次服务于这样一个核心需求:为模型在恰当的时间、以恰当的方式获取所需的上下文信息。
[5:57] Deep Agent 框架的第三项能力是委托(delegation)。
[6:00] 即,Deep Agent 框架内嵌了一个规划工具,使模型能够为复杂任务组织工作流程。
[6:03] 同时,它也开箱即用地支持子智能体(sub-agent)功能。
[6:05] 子智能体可以是通用型的,也可以是专业型的。
[6:08] 例如,如果你正在构建一个编程类智能体,你可能希望为其附加一些专门的子智能体,用于架构设计、代码审查、安全审查,以及测试编写与执行等环节。
[6:11] 为什么子智能体如此重要?
[6:13] 首先,它们拥有独立的上下文空间,并实际有助于整体上下文管理。
[6:15] 当主智能体调用子智能体时,后者仅从与当前任务直接相关的全新上下文中开始工作;之后,它再将经过精简的最终结果返回给主智能体,从而避免污染主上下文窗口。
[6:18] 其次,它们可用于并行化处理任务。
[6:20] 这样,你的智能体就能更高效地完成端到端的任务。
[6:22] 最后,子智能体可使用任意模型和任意服务提供商。
[6:24] 因此,你可以根据任务复杂度灵活匹配模型能力。
[6:27] Deep Agent 框架的第四项也是最后一项能力,是通过原生的人工介入(human-in-the-loop)机制提供引导支持。
[6:30] 人工介入对于以下两方面尤其关键:
[6:32] 第一,是在执行敏感操作或工具调用时,实时获取用户反馈——正如我们之前提到的那样;
[6:35] 第二,是在模型卡住、需要用户即时反馈以继续推进时,及时获得用户响应。
[6:38] 那么,这种机制具体是什么样子?我们在 Deep Agents 中集成了四种常见的决策模式:
[6:40] 第一种是审批流(approval flow)。例如,在邮件发送前进行审批;
[6:42] 第二种是编辑(edit)模式。比如在发布推文前进行修改;
[6:44] 第三种是拒绝(reject)决策。例如,拒绝一笔拟议中的金融交易;
[6:46] 第四种是响应(respond)模式。即当智能体中断并主动向用户提问,以解除其后续进展的阻碍。
[6:49] 我们已经深入探讨了 Deep Agent 框架的各项能力。
[6:51] 接下来,我们来谈谈为何要选择 Deep Agents。
[6:55] Deep Agents 是与提供商无关的。你可以自由选用任何提供商及模型,随时切换,甚至混合搭配。你的主智能体可以使用不同于子智能体的模型。
[6:58] 你可以使用主流提供商如 Anthropic、OpenAI、Google 等;
[7:01] 也可借助 Ollama 等本地部署模型;
[7:04] 或者选用日益强大且成本更低的开源模型,例如来自 Fireworks、Nvidia、Open Router、Base Ten 等平台提供的模型。
[7:07] Deep Agents 极具可定制性。
[7:09] 下面是一个快速回顾:核心智能体循环的基本结构如下;
[7:11] 而 Deep Agents 的循环结构则如下所示。
[7:13] Deep Agents 在核心智能体循环周围提供了一套钩子(hooks),我们称之为“系统中间件”(system middleware)。
[7:16] 中间件使得你几乎可以轻松添加任何自定义逻辑至你的智能体中。
[7:18] 这些逻辑可能包括:定制化的业务逻辑、任意位置的确定性代码、策略执行(如个人身份信息 PII 去除)、或动态智能体控制等。例如,根据当前任务动态调整运行时所使用的模型与工具。
[7:21] 即便拥有强大的框架,将智能体投入生产环境仍极具挑战性。
[7:23] 智能体需长时间稳定运行,并能在意外故障发生时自动恢复;
[7:26] 需支持人工介入与不可预测行为;
[7:28] 还需应对突发流量高峰;
[7:30] 同时始终保持安全合规的姿态。
[10:44] 并持续跟进不断变化的 [10:46] 互操作性标准。 [10:48] 现在,我将把话筒交给 [10:49] 维克(Vic),他将为大家介绍我们如何让这一过程变得简单易行。 [10:51] 太棒了!谢谢,悉尼。 [10:52] 好的。 [10:54] 刚才我们已经了解了什么是深度代理(Deep Agent)。 [10:56] 接下来,我们将讨论如何真正将一个深度代理投入生产环境。我看到台下有不少熟悉的面孔——这些人确实已将这些代理部署到生产环境中,并向客户提供了服务。嗯,因此我们对这一过程已有亲身经验。 [11:10] 今天,我们将介绍我们如何通过私有测试版推出托管式深度代理(managed Deep Agents),以尽可能简化这一流程。 [11:13] 托管式深度代理大致由四大核心支柱构成:首先是“工具链”(harness),这正是悉尼刚刚介绍过的部分;其次是运行时(runtime),即我们如何在生产环境中实际使用该代理;第三是与上下文中心(context hub)的集成;最后则是我们在沙箱中安全执行代码的方式。
[11:39] 首先,我们来谈谈这个运行时。 [11:41] 托管式深度代理实际上是基于 LangSmith 部署构建的,这意味着我们能获得大量原生能力,以应对代理在生产环境中所需的实时交互与可扩展性需求。 [11:47] 这意味着我们将在任意位置提供用于创建、更新甚至调用代理的端点接口。 [11:52] 我们还将获得专为任务设计的任务队列以及水平扩展能力,从而有效处理代理可能面临的突发性请求负载。 [12:01] 您可以想象这样一个场景:支持类代理在系统故障后被大量用户同时访问——您需要具备良好的流量承载能力。 [12:11] 最后,我们还提供了 SDK,以便在任何所需位置轻松调用这些代理;并支持与 Copilot Kit、Assistant UI 及 Gen UI 等各类界面的集成,不胜枚举。
[12:23] 第二个核心支柱是持久化执行(durable execution)。 [12:27] 这一点或许听起来有些枯燥,但在生产环境中却至关重要。由于我们是在 LangGraph 运行时之上运行深度代理,因此能够对每个步骤进行检查点(checkpoint)保存。 [12:36] 这意味着所有中间状态都存储于持久化存储中,我们可在任意检查点处恢复或重启整个流程。例如,若代理在第 49 步(共 50 步)失败,您无需重新开始整轮执行,只需从第 49 步继续重试即可。 [12:53] 此外,我们还支持从任意时间点及对应状态出发,回放并分叉(fork)代理的执行流程。 [12:58] 这为一些高级用例打开了大门,比如“我想从当前对话节点处分叉出一条新路径”,同时也支持人工介入审批(human in the loop)机制。 [13:06] 由于所有状态均被持久化存储于数据库中,我们可以无限期等待人工输入。这正是实现“环境感知型代理”(ambient agent)用例的基础,例如 LangSmith 引擎——您将在接下来的环节中听到更多相关内容。
[13:20] 安全与身份认证对于生产级代理而言极为关键。您需要多层认证机制,才能满足各类生产场景的需求。第一层是来自您自身应用的入站认证:如何验证用户身份的真实性及其是否被授权调用该代理? [13:30] 第二层则涉及代理内部对外部服务的出站认证:您可能需要调用某些工具(如 MCP 工具),必须确保其在运行时能可靠地完成身份验证并获取正确的权限。 [13:46] 第三层则是关于谁具备创建、更新和管理这些代理的权限——无论是您的 AI 工程师团队,还是您的 CTO 希望快速修改配置,都需要明确的权限控制体系,以保障变更的安全性与可控性。
[14:02] >> [轻笑] [14:02] >> 代理互操作性正变得愈发重要,尤其当您希望在多种不同场景中复用这些代理时。 [14:04] 其中一项核心功能是 LangSmith 部署所支持的远程图调用(remote graph)能力——这意味着您仅需一行代码,即可在其他部署于 LangSmith 的自定义 LangGraph 应用中调用由托管式深度代理构建的代理。 [14:13] 第二项能力是支持 A-to-A 协议(A to A protocol)。目前许多代理已采用 A-to-A 方式作为其主要通信机制,以实现……
[14:30] 这一层是代理与代理之间的通信层。
[14:32] 我们在标准的 LangSmith 部署中开箱即用地支持这一功能,
[14:33] 同时也支持托管式深度代理。
[14:37] 第三,是能够将这个代理带到你实际工作的环境中。我们
[14:41] 内部构建并部署在 LangSmith 上的许多代理,
[14:42] 我们希望能在实际工作场景中使用它们。无论是
[14:46] 深度代理代码还是云桌面,
[14:49] 你都希望能够将这个代理带到你需要的地方并加以使用。
[14:53] 我们已经考虑了所有这些不同的生产用例,这样你就无需再操心了。像重复发送消息、
[14:58] 中途取消运行等操作,实际上都需要投入大量工程开发工作,若自行构建可能需要数周甚至数月时间。而这些功能我们都已为你准备就绪,开箱即用。
[15:07] 这里的第三大核心支柱是上下文集成。
[15:13] 哦。
[15:13] 所以,Context Hub 已内置于托管式深度代理中,
[15:15] 它用于版本化并保存你的代理实际运行所依赖的所有文件。例如,
[15:19] 代理的 Markdown 文件以及 Harrison 在主题演讲中提到的技能,
[15:23] 正变得越来越流行。
[15:27] 代理关于用户所记录的记忆,都会被保存在 Context Hub 中,并带有版本控制,
[15:30] 以便你的团队可以管理不同层级的发布流程——比如我们可以先从预发环境开始,再逐步推送到生产环境,适用于不同的技能模块。
[15:38] 你可以真正地将这些技能在不同代理之间普及共享。
[15:46] 接下来作为 Context Hub 的一部分、属于托管式深度代理的核心功能,是我们与 LangSmith 引擎的集成。你将在下一环节听到更多关于 LangSmith 引擎的内容,但本质上它能够:
[15:57] 利用这些深度代理在真实生产环境中的使用数据,进行质量优化,对提示词、系统或技能等做出调整,
[16:03] 并随着引擎持续迭代,逐步提升代理的行为表现。
[16:12] 托管式深度代理的第四个关键组件是沙盒。
[16:17] 正如 Sydney 之前提到的,如今几乎每个代理都在逐渐演变为编码代理。即使是研究型代理,
[16:20] 也可能希望快速计算一些统计数据并将其加入报告。你希望让代理能够在生产环境中执行这些任务,
[16:26] 因为这能带来更具创造性的结果。因此,我们推出了 LangSmith 沙盒,并将其直接集成到托管式深度代理中。
[16:36] 这种 LangSmith 沙盒原语具备几个核心特性:第一,提供运行时凭证注入的代理机制,
[16:40] 以安全方式注入沙盒所需的凭据,确保你的敏感环境变量不会暴露给代理本身或沙盒实例。
[16:53] 第二,支持快照与恢复功能,确保代理始终拥有正确的执行环境。
[16:59] 明天我们将与 Mikhail 一起举办一场专题会议,深入探讨此功能,
[17:03] 但对于大多数代理应用场景而言,这些功能都非常出色。
[17:07] 因此,以上就是你将一个想法或正在运行的深度代理推向生产环境所需的一切要素。
[17:15] 这正是我们推出托管式深度代理的原因,且从今天起启动私测计划。我们鼓励大家立即加入等候名单,感谢各位的时间!
[17:25] >> [掌声]