章鱼总结
00:00 / 19:44

Prompt Engineering · 19:44

说话人 0

can an ai agent write its own harness and then recursively improve the harness based on the task it is trying to solve? this is what i want to show you how to build in this video because almost every agent harness we use today, including the coding ones, suffer from the exact same problem. they are bloated and they are not task specific. now, as developers, we try to guess every tool an agent might ever need up front. we connect a whole bunch of mcp servers. now, when we ship 30 or 40 generic tools that sit in the context window on every single turn, well, yet the moment the agent actually needs... a specific tool in a specialized problem, things like inspecting a web page it just built or watching a bug report recorded as a video or reading a custom binary file format, we see that it's not able to pick the right tool or that right tool is actually missing. so instead of shipping a bloated one size fits all harness, what happens if you start with a tiny three tool harness, just bash, read and write and let the model recursively evolve its own task-specific harness while it works. this is the exact idea i tried to build and the results were really, really interesting. so when i tried to test this idea on gemini interaction api, the agent realized on its very first web app that it had no way to see the ui. it wrote an unit test on chrome screenshot tool and give itself eyes for the next turn. then without me prompting it, it rewrote its own harness loop and added condition that it would never mark a task done unless the web page clearly rendered in a real browser. now, frozen harnesses that doesn't have a specific tool that you would need can do some really absurd things in order to accomplish some tasks. i have some benchmarks which i'm going to show you in this video. but first, let's start by looking at the full architecture of how a recursive harness works compared to a normal one. and then we will walk through each piece and run different experiments. and i'll show you both the good and bad of recursive harnesses.

AI 智能体能否编写自己的运行框架,然后根据它试图解决的任务递归地改进这个框架? 这就是我想在这段视频里教你如何构建的东西,因为我们现在使用的几乎所有智能体运行框架,包括编程智能体的运行框架,都有完全相同的问题。 它们臃肿,而且不针对具体任务。 现在,作为开发者,我们总想预先猜出智能体可能需要的所有工具。 我们接入一大堆 MCP 服务器。 当我们把 30 或 40 个通用工具放进上下文窗口,让它们在每一轮都占据空间时,一旦智能体真的需要某个特定工具来解决专业问题——比如检查它刚构建的网页、查看以视频形式录制的错误报告,或读取自定义二进制文件格式——我们就会发现,它要么选不对工具,要么根本没有那个合适的工具。 所以,与其提供一个臃肿、试图满足所有需求的运行框架,不如从一个只有三个工具的小型框架开始:bash、读取和写入,然后让模型在工作过程中递归地演化出自己的任务专用框架,会怎么样? 这正是我尝试构建的想法,结果真的非常有意思。 所以,当我尝试在 Gemini Interaction API 上测试这个想法时,智能体在开发第一个网页应用时就意识到,它没有办法查看 UI。 它为 Chrome 截图工具编写了一个单元测试,让自己在下一轮有了眼睛。 然后,在我没有给出任何提示的情况下,它重写了自己的运行框架循环,并加上了一条条件:除非网页确实在真实浏览器中清晰呈现,否则绝不将任务标记为完成。 现在,缺少特定所需工具的固定运行框架,为了完成某些任务,有时会做出一些非常离谱的事情。 我有一些基准测试,会在这段视频里展示给你看。 不过首先,我们先来看看递归式运行框架与普通运行框架的完整架构。 然后我们会逐一讲解各个部分,并运行不同的实验。 我会向你展示递归式运行框架的优点和缺点。

okay, before we look at the code, let's put the whole architecture on the screen so you have a clear map of what we are building. first, what is an agent harness in general? a model by itself only takes text in and predict text out. the harness is the control loop around the model. on every turn, the harness sends the conversation and a list of tools. to the model, runs whatever tool calls the model asks for, feeds the results back and decide when the task is finished. now because the tools are the only way the model can touch the outside world, the tool lists defines what the agent can and cannot do. and in a standard harness, both the two lists and the loop rules are completely frozen. now, look at how the architecture changes when we make the harness recursive.

好,在看代码之前,我们先把整个架构展示出来,让你清楚了解我们要构建的东西。 首先,智能体运行框架到底是什么? 模型本身只会接收文本,并预测输出文本。 运行框架就是围绕模型的控制循环。 每一轮中,运行框架都会向模型发送对话内容和工具列表。 它会运行模型请求的任何工具调用,将结果反馈给模型,并决定任务何时完成。 现在,由于工具是模型接触外部世界的唯一途径,工具列表就定义了智能体能做什么、不能做什么。 而在标准运行框架中,工具列表和循环规则都完全固定。 现在,看看当我们让运行框架递归化时,架构会如何变化。

the whole system is split into three different zones that we're going to look at. at the top is zone one. in this case, it's the gemini interaction api. it keeps the conversation state on google's server and critically, it lets our harness inject an updated tool list and system prompt in every single turn without restarting the session. in the middle is zone 2, which runs inside a lockdown mac os sandbox. the agent starts with a tiny base kernel with three different tools, which are shell, read file, and write file. next to that kernel is toolbox folder with three recursive primitives that lets harness evolve. Okay, first is create tool with a mandatory unit test gate, which lets the model write new python tools, test them and hot swap them into the next turns to list. Second are a life cycle hooks specifically session start and before done. which let the model attach its own tools to the harness loop and rewrite its own definition of done. and the third is reflective memory, a note file and a short between-task reflection step where the model inspects what failed and upgrades its toolbox for the next task. finally, at the bottom is zone 3, which lives completely outside the sandbox. it holds two guardrails, a hidden grader, the agent cannot see or game even the evaluation tests, and an external model broker that holds our api keys so the agent can build model powered tools without ever touching a secret. okay, so this is the entire blueprint.

整个系统分为三个不同的区域,我们接下来会逐一查看。 最上方是区域一。 在这个案例中,它是 Gemini Interaction API。 它会在 Google 的服务器上保存对话状态。关键的是,它允许我们的运行框架在每一轮中注入更新后的工具列表和系统提示,而无需重启会话。 中间是区域二,它运行在锁定的 macOS 沙箱中。 智能体启动时只有一个小型基础内核,包含三个工具:shell、读取文件和写入文件。 内核旁边有一个工具箱文件夹,其中包含三个递归原语,让运行框架能够不断演进。 好,第一个是创建工具,并设有强制性的单元测试门槛;它让模型能够编写新的 Python 工具、测试这些工具,并在后续轮次中将其热切换到工具列表中。 第二个是生命周期钩子,具体包括会话开始和完成前钩子。 它们让模型能够将自己的工具接入运行框架循环,并重写对任务完成条件的定义。 第三个是反思式记忆:一个笔记文件,以及一个简短的任务间反思步骤,让模型检查失败之处,并升级工具箱以应对下一个任务。 最后,最下方是区域三,它完全位于沙箱之外。 这里有两道护栏:一个隐藏的评分器,智能体既看不到,也无法通过操纵评估测试来作弊;还有一个外部模型代理,它保管着我们的 API 密钥,让智能体能够构建由模型驱动的工具,却永远无法接触任何机密。 好,这就是完整的蓝图。

now let's zoom into zone one and see why the gemini interaction api makes this whole loop possible. okay, the reason i built this on the gemini interaction api instead of a standard chat endpoint comes down to two design properties. first, the conversation history lives on google's side. on each turn, the harness only sends the new tool outputs along with the previous interaction id. so it never has to resend the entire conversation history. second, and this is kind of the key mechanism for recursive harness, every request on the interaction api carries its own system instructions. its own settings and its own list of tools. which means a python tool that the model writes on turn 3 can be validated by the harness and passed as a real callable function on turn 4 of the exact same conversation without restarting anything. but there is one cost detail you should know about. in my runs, the turn immediately after the tool list. changes don't hit the context cache. so if you build this, you want to patch tool updates instead of changing the tool list on every single turn. now, being able to hot swap tools mid-conversation is powerful, but it immediately creates our first failure mode inside zone 2.

现在,让我们深入了解区域一,看看为什么 Gemini Interaction API 能让这一整套循环成为可能。 好,我之所以用 Gemini Interaction API 来构建这个,而不是用标准的聊天端点,归结为两个设计特性。 第一,对话历史保存在 Google 那边。 每一轮中,执行框架只会发送新生成的工具输出,以及之前的交互 ID。 所以它不必重新发送整个对话历史。 第二点,也是递归执行框架的关键机制:Interaction API 上的每个请求都带有自己的系统指令。 也有自己的设置和工具列表。 这意味着,模型在第 3 轮编写的 Python 工具,可以由执行框架验证,并在同一段对话的第 4 轮作为真正可调用的函数传入,无需重启任何东西。 不过有一个成本方面的细节你应该知道。 在我的测试中,紧接着工具列表发生变化的那一轮, 不会命中上下文缓存。 所以如果你要构建这个系统,就应该对工具更新做增量修改,而不是每一轮都更改工具列表。 现在,在对话进行中热插拔工具固然很强大,但这会立即在区域 2 内引出我们的第一个故障模式。

if a model writes a new tool that has subtle bug in it and the harness registers it anyways, the model will call that broken tool and trust its bad output for the rest of the task. this is why zone 2 starts with a minimal kernel in plain python with no frameworks. so the base harness only has three tools, a shell runner, a file reader, and a file writer, all blocked inside a mac os sandbox so the model can only write inside its project folder and cannot read my keys. i didn't even give it a way to view images because i wanted to see what the model builds when it notices a capability is missing. now, when the model wants to grow the harness, it calls create tool, and it has to pass five things. a name, a description, the parameter schema, the python code, and at least one unit test. now, before the harness registers that tool, it loads the code and runs the tool's unit test inside the sandbox. only if every test passes, does the tool get saved into the toolbox folder and added to the next turn's tools list? okay, the thing is that the unit test gate actually saved my very first run. so the model was building a small web app and realized that it had no way to see it and called create tools to write a screenshot tool. its first test failed because the browser binary it tried to launch was not installed on my macos. so the harness rejected the tool and sent back an error. the model located my installed chrome binary, fixed the tool, passed the test, and on its very next turn called the new tool to inspect the same web page. and because the custom tools in this harness can return images straight back to the model as a image input, the single tool allowed the text-only harness to give itself eyes. okay, so now the agent can build tools whenever it needs them, but that exposes a second problem.

如果模型编写了一个带有细微漏洞的新工具,而执行框架仍然将它注册,模型就会调用这个有问题的工具,并在任务剩余过程中相信它错误的输出。 这就是为什么区域 2 要从一个用纯 Python 编写、没有任何框架的最小内核开始。 因此,基础执行框架只有三个工具:Shell 执行器、文件读取器和文件写入器。它们都被限制在 macOS 沙盒中,因此模型只能在项目文件夹内写入,无法读取我的密钥。 我甚至没有给它查看图像的能力,因为我想看看模型发现缺少某项能力时会构建什么。 现在,当模型想要扩展执行框架时,它会调用 create tool,并且必须提供五项内容。 名称、描述、参数架构、Python 代码,以及至少一个单元测试。 现在,在执行框架注册该工具之前,它会加载代码,并在沙盒中运行该工具的单元测试。 只有所有测试都通过后,该工具才会被保存到工具箱文件夹,并添加到下一轮的工具列表中。 好吧,关键是,单元测试关卡确实救了我第一次运行。 模型当时在构建一个小型 Web 应用,意识到自己没有办法查看它,于是调用创建工具来编写一个截图工具。 它第一次测试失败了,因为它尝试启动的浏览器二进制文件并未安装在我的 macOS 上。 于是运行框架拒绝了这个工具,并返回了一条错误信息。 模型找到了我安装的 Chrome 二进制文件,修好了这个工具,通过了测试,并在下一轮立刻调用新工具来检查同一个网页。 而且,由于这个运行框架里的自定义工具可以直接把图像作为图像输入返回给模型,这一个工具就让纯文本运行框架拥有了视觉能力。 好,现在代理可以在需要时构建工具了,但这也暴露了第二个问题。

just because an agent builds a tool on task one does not mean it will remember to use it on task two. so tools gives the agent new capabilities, but they do not change how the harness loop itself behaves. this is what the second and third part of our toolbox are, hooks and memory. So a hook attaches one of the more zone tools to a specific moment in the harness loop and I give it two hook points. the first one is session start, which runs before turn one of a task and shows its output to the model right away. the second one is before done, which runs when the model says it's finished. if the tool attached to before done reports a failure, the harness blocks the finish and sends the failure back to the model. which means the model can write its own task specific definition of done and the harness will enforce it automatically on every future task. now to carry knowledge across tasks the toolbox folder also holds a short note file that the model writes for its future self. which the harness injects at the start of every task, and between tasks the model gets a short reflection session with a report of what passed, failed, so it can fix, merge, or prune tools and hooks. now, letting an agent write its own tools and its own definition of done creates two immediate ways the agent can cheat or break your system, which brings us to zone 3 for architecture.

代理在任务一中构建了某个工具,并不意味着它会记得在任务二中使用它。 所以,工具赋予代理新的能力,但不会改变运行框架循环本身的运作方式。 这就是我们工具箱的第二和第三部分:钩子和记忆。 钩子会把某个更高级的工具挂接到运行框架循环中的特定时刻,我为它设置了两个挂接点。 第一个是会话开始,它会在任务的第一轮之前运行,并立即把输出展示给模型。 第二个是完成前,它会在模型表示自己已经完成时运行。 如果挂接到完成前的工具报告失败,运行框架就会阻止任务结束,并把失败信息发回给模型。 这意味着模型可以为每项任务编写自己的具体完成标准,而运行框架会在今后的每项任务中自动执行这些标准。 为了让知识能在不同任务之间延续,工具箱文件夹还保存着一个简短的笔记文件,由模型写给未来的自己。 运行框架会在每项任务开始时注入这份笔记;而在任务之间,模型会进行一次简短的反思,并查看哪些内容通过了、哪些失败了的报告,从而修复、合并或精简工具和钩子。 现在,让代理编写自己的工具和自己的完成标准,会立刻带来两种代理可能作弊或破坏系统的方式。这就引出了架构的第 3 区。

there are two guardrails running outside the sandbox that made the biggest difference in my runs, and if you build a recursive harness, you should copy both. first, the model never sees how it is created. whenever a model can read its creator, it starts optimizing the creator instead of the app. so every task here is scored by hidden check that runs outside the sandbox. and the model only gets back the names of the check that passed or failed. second, tools inside the sandbox never hold secrets. if a custom tool needs to call a model, for example, to describe a video, it calls a small broker running outside the sandbox that holds the api key and enforces a strict budget. that way, the agent can build model-powered tools without ever seeing a key. this is all three zones of the architecture working together. now let's run the three experiments and see where this recursive harness wins and where it breaks.

有两道在沙箱之外运行的护栏,对我的运行结果影响最大。如果你要构建一个递归运行框架,就应该把这两道护栏都照搬过去。 首先,模型永远不会看到自己是如何被创建出来的。 只要模型能读到创建者的信息,它就会开始优化创建者,而不是应用。 因此,这里的每项任务都由一个在沙箱之外运行的隐藏检查来评分。 模型收到的只有通过或未通过检查的名称。 其次,沙箱内的工具绝不会持有秘密。 例如,如果自定义工具需要调用模型来描述视频,它就会调用一个在沙箱外运行的小型代理,由它保管 API 密钥并严格控制预算。 这样一来,智能体就能构建由模型驱动的工具,却永远看不到密钥。 这就是架构中的三个区域协同工作的方式。 现在,我们来运行这三项实验,看看这个递归式运行框架在哪些方面奏效,又会在哪里出问题。

说话人 1

Here we see the self-evolving agent in its natural habitat, the sandbox. It's a workspace actually. It has already built itself eyes. and now. Now it wants a voice. Hello? Is this thing on? Oh, it works.

我们在它的自然栖息地——沙箱中,看到了这个自我进化的智能体。 准确来说,这是一个工作区。 它已经给自己造好了眼睛。 而现在…… 现在它想要一个声音。 喂? 这玩意儿开着吗? 哦,能用了。

说话人 0

To give the agent a voice, the harness needs a text-to-speech model. This is where today's sponsor, Fish Audio, comes in. I have partnered with them to show you Drama 3, their new text-to-speech model. In this harness, a voice would be just one more tool that the agent builds with create tool. and the fish audio api key would stay in the broker outside the sandbox, exactly like the gemini key. now, the best part is that you direct drama 3 with plain words in square brackets, which is exactly how the narrator you just heard was written. and the crazy part is that you can give every speaker a different voice in a single request.

要让智能体拥有声音,运行框架需要一个文本转语音模型。 这正是今天的赞助商 Fish Audio 派上用场的地方。 我与他们合作,向大家介绍他们全新的文本转语音模型 Drama 3。 在这个运行框架中,语音只不过是智能体通过 create tool 构建的又一个工具。 Fish Audio API 密钥会留在沙箱外的代理程序中,就像 Gemini 密钥一样。 现在,最棒的是,你只需用方括号里的普通文字来指导 Drama 3,这正是你刚才听到的旁白的写法。 更厉害的是,你可以在一次请求中为每位说话者指定不同的声音。

说话人 1

I built a screenshot tool, a pixel diff tool, and a hook that checks every page before I finish. I wrote one Python script. And? And threw it away. We both got twelve out of twelve. Mine has unit tests. Cool. They all pass.

我做了一个截图工具、一个像素差异工具,还写了一个钩子,在我完成之前检查每个页面。 我写了一个 Python 脚本。 然后呢? 然后把它扔掉了。 我们俩都拿了十二分,满分十二分。 我的还有单元测试。 不错。 测试全都通过了。

说话人 0

For the launch, Drama 3 API is $10 per million UTF-8 bytes. And if you would rather run it yourself, the model weights are open on Hugging Face. so check it out. it's pretty amazing. link is going to be in the description. okay, back to the experiments. so for the first experiment, i built a series of real web apps, starting with a simple note app and scaling it to an offline trip planner where each app is harder than the last. i ran the evolving harness against a frozen harness on the exact same tasks, where the frozen one only ever had the three base tools and kept nothing between tasks. so on app one, the evolving agent builds its chrome screenshot tool and on app two, it built a pixel comparison tool. then in its first reflection session, it did something i didn't expect. it turned its own browser check into before done hook. so from then, it could not finish a task until the app passed that check. and it added a session start hook that surveys every new project automatically. so for example, when a task came with a bug report as a video, it built the video tool that finds where the screen changes and pulls out the exact frame. watching the log, it looked like the evolving harness was going to win by a mile. and then i looked at the final scoreboard. both harnesses passed every single hidden check on every single app and they took almost the exact same amount of time. Okay, so that result kind of surprised me.

发布时,Drama 3 API 的价格是每百万 UTF-8 字节 10 美元。 如果你更愿意自己运行,模型权重已在 Hugging Face 上开放。 所以去看看吧。 真的很厉害。 链接会放在简介里。 好了,回到实验。 第一个实验中,我构建了一系列真正的 Web 应用,从简单的笔记应用开始,逐步扩展到离线旅行规划器,每个应用都比上一个更难。 我让不断迭代的测试框架和冻结的测试框架执行完全相同的任务;冻结版始终只有三个基础工具,而且不会在任务之间保留任何内容。 在第一个应用中,不断迭代的智能体构建了自己的 Chrome 截图工具;到了第二个应用,它又构建了像素对比工具。 然后在它的第一次反思环节中,它做了一件我没想到的事。 它把自己的浏览器检查变成了一个任务完成前钩子。 于是从那以后,除非应用通过这项检查,否则它就无法完成任务。 它还添加了一个会自动调查每个新项目的会话启动钩子。 比如,当任务附带的视频 bug 报告时,它就构建了一个视频工具,用来找出屏幕变化的位置并提取准确的画面。 看着日志,我觉得不断进化的测试框架会轻松胜出。 然后我查看了最终比分。 两个测试框架在每个应用的每一项隐藏检查中都全部通过,而且耗时几乎完全相同。 好吧,这个结果确实有点出乎我的意料。

So for round two, I decided to make tests much harder. I took away the image helper and the external broker completely. So the frozen agent has no built in way to look at the screenshots or videos at all. and it still rebuilt the pricing page down to the pixel. so when i checked the logs to see how it pulled that off, i found that the frozen agent wrote a small program that called the text recognition built into mac os to read the reference screenshot and then wrote plain python to measure the exact colors and edges. even wilder, when i gave it a silent bug report video with no changes, the frozen agent wrote its own computer vision script from scratch. it matched the reference photos against the video frames to track the order, found the drop marker by filtering for its exact color, and fixed all of the bugs. now, by the way, all of this was running on Gemini 4 argon. and this is kind of the first major lesson from these runs. a frontier model with a shell will build whatever capability it needs in line, whether the harness lets it save tools or not. which is pretty incredible on its own. so this raises the real question, when does keeping those evolved tools actually pay off? and when does it backfires?

所以第二轮,我决定把测试难度提高很多。 我完全移除了图像辅助工具和外部代理。 因此,冻结的智能体完全没有内置的办法查看截图或视频。 但它仍然把定价页面像素级地重建了出来。 所以我查看日志,想弄清它是怎么做到的,结果发现冻结的智能体写了一个小程序,调用 macOS 内置的文字识别功能来读取参考截图,然后用纯 Python 精确测量颜色和边缘。 更夸张的是,当我给它一段没有任何变化的静音 bug 报告视频时,冻结的智能体从头开始编写了自己的计算机视觉脚本。 它将参考照片与视频画面进行匹配以追踪顺序,通过筛选特定颜色找到了下落标记,并修复了所有 bug。 顺便说一下,这一切都是在 Gemini 4 Argon 上运行的。 而这就是这些测试带来的第一个重要启示。 只要有 shell,前沿模型就会当场构建所需的任何能力,不管测试框架是否允许它保存工具。 光这一点就相当不可思议了。 所以,这就引出了一个真正的问题:保留这些进化出来的工具,什么时候才值得? 又什么时候会适得其反?

so to test where persistence actually matter, i ran a third round, five tasks on a custom binary file format, where every task needs a complex parser that takes real work to write. here, the recursive harness paid off immediately. on task one, it spent a few extra minutes turning its parser into a library inside its toolbox. on the next four tasks, it called that parser right away and finished significantly faster than the frozen agent, which had to write the new parser from scratch every single time. but when i ran a second evolving harness that started with this binary family with an empty toolbox, it hit the. exact ironic trap of self-improvement. remember how our whole goal was to escape bloated harness? that fresh agent built the most impressive toolbox of all my runs, but on every reflection, it kept adding more checks to its own before-done hook. by task 5, the agent had bloated its own harness and running. It's growing before then checklist eight hundred percent of the time it's saved from reusing the binary parser. now, i also got two more failure modes.

为了测试持久化究竟何时发挥作用,我进行了第三轮测试:针对一种自定义二进制文件格式的五项任务,每项任务都需要一个编写起来相当费力的复杂解析器。 在这里,递归式工具框架立刻发挥了作用。 在第一项任务中,它多花了几分钟,把解析器整理成工具箱里的一个库。 接下来的四项任务中,它直接调用这个解析器,完成速度明显快于冻结版智能体;后者每次都得从头编写新的解析器。 但当我运行第二个进化式工具框架时,它一开始面对的是这个二进制文件系列,工具箱却是空的,结果它陷入了…… 自我改进中那个恰如其分、令人哭笑不得的陷阱。 还记得我们的全部目标是摆脱臃肿的工具框架吗? 这个新智能体打造出了我所有测试中最令人印象深刻的工具箱,但每次反思时,它都会继续往自己的完成前钩子里添加更多检查。 到第 5 项任务时,智能体把自己的工具框架撑得臃肿不堪,运行…… 它不断增长的完成前检查清单,耗费的时间是复用二进制解析器所节省时间的八倍。 此外,我还发现了另外两种失败模式。

once the agent built a stricter pixel diff tool, it kept re-verifying a page that had already passed until it ran out of time. and it's growing before the check started copying the name of the hidden check directly from the task description. so across all three rounds, the takeaway is that recursive self-evolving harness does not make the model smarter. because a strong model builds through scripts inline anyway. it pays off under these specific conditions. when a capability is expensive to rebuild from scratch, when your task repeats in a domain family, and when the evolution stays lean so that the agent doesn't bloat its own loop. so if you're building a recursive harness on the interaction api, start with these four rules from our architecture. start with tiny 3.2 kernel inside a sandbox so every new tool is forced by a real task need. require unit test inside create tool before any generalized function enters the tool list. then keep your grader and your secret brokers outside the. A sandbox in zone 3, use session start and before-done hooks with the model can improve its own process but keep reflection short. And strictly cap your before-done hook so it stays fast. now, i'm going to be running more experiments on recursive self-improving harnesses with weaker models. so if you're interested in that, make sure to subscribe to the channel. i would love to know how you're handling tool boot and your own agent harnesses. so share your approaches in the comment section below. And you will find all the links in the description. Anyways, I hope you found this video useful. Thanks for watching and as always, see you in the next one.

有一次,智能体构建了一个更严格的像素差异工具,之后却不断重新验证一个已经通过检查的页面,直到时间耗尽。 而且,在不断增长的完成前检查中,它开始直接照抄任务描述里的隐藏检查名称。 因此,纵观这三轮测试,结论是:递归式自进化工具框架并不会让模型变得更聪明。 因为强大的模型本来就会在需要时直接编写内联脚本。 只有在以下特定条件下,它才有价值。 当某项能力从头重建代价高昂、任务会在同一领域系列中重复出现,并且进化过程保持精简、不让智能体把自己的循环搞得臃肿时。 所以,如果你正在基于交互 API 构建递归式工具框架,可以从我们架构中的这四条规则入手。 从沙盒里的微型 3.2 内核开始,让每个新工具都必须由实际任务需求来驱动。 要求在创建工具时先编写单元测试,之后才能将任何通用函数加入工具列表。 然后把你的评分器和秘密代理留在外面。 在 3 区的沙盒中,使用会话开始和结束前钩子,让模型改进自己的流程,同时让反思保持简短。 并且严格限制结束前钩子的执行时间,确保它足够快。 现在,我打算用较弱的模型对递归式自我改进框架进行更多实验。 如果你对此感兴趣,记得订阅频道。 我很想知道你是如何处理工具启动和自己的智能体框架的。 所以欢迎在下方评论区分享你的做法。 所有链接都在简介里。 总之,希望这个视频对你有帮助。 感谢收看,一如既往,我们下期再见。

摘要

视频探讨智能体能否根据任务需要改造自己的 harness。方案从 shell、读文件、写文件三个基础工具起步,在沙箱中允许模型通过带单元测试门槛的工具创建机制扩展能力,并用生命周期钩子和反思记忆积累经验;隐藏评分器与外部密钥代理则负责隔离评测和秘密。实验显示,强模型即使没有可持久化的自定义工具,也能临时编写脚本完成复杂任务,因此递归 harness 并非普遍更快;但面对重复出现、重建成本高的任务,复用工具能显著节省时间。工具和完成检查也可能不断膨胀,故需控制反思与钩子的规模。

章节

00:00 通用 Harness 的问题与自我演化思路

常见智能体 harness 往往预先接入大量通用工具,既占据上下文,又未必适合眼前任务;遇到网页检查、视频 bug 报告或自定义二进制格式时,可能缺少专用能力或无法选对工具。替代方案是从 shell、read、write 三个工具组成的最小 harness 起步,让模型在工作中按需创建工具和改造流程。首次网页应用实验中,模型发现自己看不到界面,便编写 Chrome 截图工具;随后还修改 harness 的完成条件,要求网页必须在真实浏览器中正确渲染才算完成。

提出智能体编写并改进自身 Harness 的问题
指出现有智能体 Harness 的共同问题
概括 Harness 臃肿且缺乏任务针对性
开发者预先猜测智能体所需工具
提到连接大量 MCP 服务器

02:22 Harness 的控制循环与标准架构

模型本身接收文本并生成文本,harness 则负责向模型发送对话和工具列表、执行工具调用、回传结果,并判断任务是否结束。工具决定智能体能与外部世界进行哪些交互;标准 harness 的工具列表和循环规则通常固定不变,因此能力边界也预先固定。递归 harness 的关键变化,是让工具和控制流程能够随任务需要演化。

整体架构图展示
Agent harness 概念引入
模型输入与输出关系
模型外围的控制循环
对话与工具列表发送给模型

03:15 递归 Harness 的三层架构

架构分为三层:第一层使用 Gemini Interactions API,允许在同一会话的每一轮更新工具列表和系统指令;第二层是在 macOS 锁定沙箱内运行的最小内核,包含 shell、读文件、写文件,以及创建工具、生命周期钩子和反思记忆等递归机制;第三层位于沙箱之外,包含模型看不到的隐藏评分器,以及持有 API 密钥并限制预算的外部模型代理。反思机制通过短备注和任务间复盘,帮助模型修复、合并或删减工具与钩子。

顶层区域的 Gemini 交互 API
沙箱中的基础内核及其三种工具
创建工具并通过单元测试门槛
反思记忆机制及任务间的复盘步骤
沙箱外部的防护机制与隐藏评估器

05:04 Interactions API 与动态工具更新

Interactions API 将对话历史保存在 Google 侧,后续请求只需发送新的工具输出和先前交互 ID;每次请求还可单独携带系统指令、设置和工具列表。因此,第三轮生成的 Python 工具可经 harness 验证后,在同一会话第四轮成为可调用函数。一个成本细节是,工具列表变更后的紧接一轮不会命中上下文缓存,因此应采用补丁式更新,避免每轮都改工具列表。

同一对话中,工具从第3轮生成到第4轮成为可调用函数

06:28 工具创建门槛与网页截图案例

为避免模型生成的工具带有隐蔽缺陷,基础内核以纯 Python 实现,shell 和文件工具被限制在 macOS 沙箱项目目录内,且模型没有读取密钥的权限。创建工具时必须提交名称、描述、参数 schema、Python 代码和至少一个单元测试;测试在沙箱中通过后,工具才能保存并加入下一轮的工具列表。网页应用案例中,模型首次编写截图工具时因找不到浏览器而测试失败,修正为使用已安装的 Chrome 后才通过门槛,并在下一轮调用工具检查网页;工具还能把图像直接返回模型,使原本没有视觉能力的 harness 获得“眼睛”。

工具存在细微缺陷时,模型会依赖错误输出
以纯 Python 最小内核作为起点
基础 harness 的三种工具
章节代表画面
模型通过 create tool 扩展 harness

08:40 生命周期钩子与跨任务记忆

单次任务中创建的工具不一定会在后续任务中被模型记起,因此架构增加钩子与记忆。session_start 钩子在任务第一轮前运行并把输出交给模型;before_done 钩子在模型宣告完成时运行,若检查失败,harness 会阻止结束并把错误反馈给模型,从而自动执行模型定义的完成条件。工具箱还保存供未来任务使用的短备注,并在任务间安排简短反思,让模型根据成败调整工具和钩子。

跨任务记忆的局限
工具能力与执行循环的区别
工具箱中的钩子与记忆
钩子连接工具与执行循环
任务开始时运行的钩子

10:24 沙箱外的评分与密钥保护

自写工具和自定完成标准会带来作弊与安全风险。模型不应看到创建者或隐藏评测细节,否则可能转而优化评测;因此任务由沙箱外的隐藏检查评分,模型只能收到哪些检查通过或失败。沙箱内工具也不保存秘密:需要调用模型的自定义工具通过外部 broker 请求服务,由 broker 持有 API 密钥并执行严格预算限制,使智能体能够构建模型驱动的工具而不直接接触密钥。

沙箱外的隐藏检查评分机制
沙箱外代理保管密钥并限制预算

11:28 网页应用基准:动态能力与冻结 Harness

第一轮实验用从便笺应用逐步扩展到离线旅行规划器的一组真实网页任务,对比可演化 harness 与只保留三个基础工具、任务间不保留经验的冻结 harness。演化智能体先后创建 Chrome 截图工具和像素比较工具,并把浏览器检查改为 before_done 钩子,还通过 session_start 自动勘察新项目;遇到视频 bug 报告时,它也创建了定位画面变化并提取对应帧的工具。然而最终两种 harness 都通过了所有应用的隐藏检查,耗时也几乎相同,说明创建并保存能力不一定带来可见优势。

展示从简单笔记应用到离线旅行规划器的一系列应用任务
展示用于比较页面像素差异的工具
展示浏览器检查被设置为任务完成前的检查钩子
展示从视频中提取屏幕变化对应画面的工具结果
展示两种 harness 的最终隐藏检查通过情况与耗时对比

14:52 没有视觉工具时,强模型仍能现场构建能力

第二轮移除了图像辅助工具和外部 broker,使冻结智能体无法直接查看截图或视频,但它仍能把定价页面还原到像素级。模型通过调用 macOS 内置文字识别读取参考截图,再用普通 Python 测量颜色和边缘;面对没有变化的静默 bug 视频,它从头编写计算机视觉脚本,将参考照片与视频帧匹配以追踪顺序,并按标记颜色定位地图上的下车点。实验据此指出,具备 shell 的前沿模型即使不能把工具保存进 harness,也可能在任务中临时编写所需能力。

重建后的定价页面及像素级效果
参考截图与读取图中文字、颜色和边缘的过程
无声错误报告视频及从零编写的视觉分析脚本
通过颜色筛选定位视频中的拖放标记

16:23 二进制格式任务:复用收益与 Harness 膨胀

第三轮连续安排五个自定义二进制格式任务,每项都需要耗时编写复杂解析器。一个递归 harness 在首项任务中把解析器整理成工具箱里的库,后四项直接复用,因此比每次从头编写解析器的冻结 harness 快得多。但另一个从空工具箱开始的演化版本,在反思中不断给 before_done 增加检查;到第五项时,完成检查的运行开销达到复用解析器所节省时间的八倍,演化因此反而造成负担。

复用已有解析器后,后续任务完成得更快
工具箱扩大的同时,完成前检查也不断增加
呈现复用解析器的收益与清单增长之间的对比

17:45 失败模式、适用条件与实施规则

演化工具可能造成重复验证:更严格的像素差异工具曾让已通过检查的页面反复被检查,直到耗尽时间;完成钩子还曾直接复制任务描述中的隐藏检查名称。综合实验,递归 harness 不会让模型本身更聪明,且强模型往往能用 shell 临时编写脚本;持久化工具主要在能力从头重建成本高、任务属于重复领域、演化过程保持精简时有收益。实施时应从沙箱内的最小内核开始,新工具必须通过单元测试,评分器和密钥代理置于沙箱外,反思保持简短,并严格限制 before_done 钩子的运行成本。

更严格的像素差异工具导致重复验证并耗尽时间
代理从任务描述复制隐藏检查名称的失败模式
递归自进化 harness 并不会让模型更聪明
强模型本身可通过内联脚本构建能力
适用条件的引入

结论

18:10 递归式 harness 的价值不在于提升模型智能,而在于为重复领域中重建成本高的能力提供可复用工具。

16:41 只有在工具复用带来的节省超过工具维护、反复检查和反思的开销时,持久化演化才值得采用。

07:20 工具创建应经过沙箱内单元测试,隐藏评分与密钥代理则应留在沙箱之外。

17:45 完成钩子和反思流程必须受到严格约束,否则自我改进会演变为重复验证与 harness 膨胀。