X← X · 精读长文
文章X · 精读长文· 06-22 · 12:40

如何为你的 Skills 搭建自我改进循环

How to build a self-improvement loop for your Skills

打开原文约 9 分钟读

cover

There’s been a lot of chatter about using “loops” lately to drive agents, and I think this has been accompanied by a bit of “what actually is a loop”?

I can’t speak for everyone else using the term, but I wanted to show a practical approach using Skills and cloud agents for a particularly powerful kind of loop: a self-improvement loop.

This is the idea that an agent can improve the quality of its own Skills over time from external feedback. My example is a loop that involves a human feedback step, but if you have a clear goal that doesn’t require a human, you can use the same method with an automated grader.

To make matters concrete, say this Skill does issue triage, separating incoming issues into a few buckets: ready-to-implement, duplicate, needs-info. This would also work for a code review Skill, a bug fixing Skill, an incident response Skill, and so on.

Here’s what a first draft of the Skill might look like:

Full triage-issue Skill

What you need to do is set up the following loops:

  1. An inner agent loop: this is where you actually apply the Skill. For issue triage, you could be running it manually, or, more likely, you have an integration with your task tracker that runs the Skill whenever a new issue is filed. Interactions with the Skill are recorded somewhere: in a file, an agent trace, or an interaction in an external system like Slack or Github.
  1. An outer agent loop: this is an agent that runs on a schedule and observes the inner loop use of the Skill. For the issue triager, this will likely be a cloud agent that pulls records of every time the Triage agent ran. Its job is to look at all the runs of the inner agent and adjust its Skill based on the performance of those runs. Since Skills are just files, this means it should make a diff to improve Skill based on user feedback from past runs.

I’ll show you how to do this in practice using Warp and Oz, our cloud agent platform, but there are lots of ways you can accomplish it. We will use Github Issues as the issue tracker.

Here is a sample repo with the Skills and GitHub workflows to follow along.

Step 1: set up the inner agent loop

The inner agent loop uses a Github action that runs on every new issue created.

Full GitHub Action

The Github action invokes a cloud agent through Oz, Warp’s cloud agent platform. This cloud agent syncs the repo, pulls in the issue contents from github, and tries to classify it. The code on how to set this up is in the repo linked below.

Now when a new issue comes in, a cloud agent runs the inner loop triaging skill, and applies a label indicating that a new feature request is ready to implement.

Step 2: set up the outer loop for self-improvement

Let’s say though that a human reviewer doesn’t agree with the agent assignment. As a person looking at the agent’s assigned labels, I switch the issue from “ready to implement” to “needs info” and add a comment on the thread as to why it was mis-categorized, e.g. because there is ambiguity on whether we should add a setting for the new feature.

Here’s where the outer loop becomes interesting. The outer loop agent runs once a day and looks at all issues that have been triaged, and when it runs, it will find that I manually adjusted the label and gave a reason why.

Full improve-triage-issue Skill

Since the outer loop agent Skill is run through a coding agent, it will take the feedback I provided and make a diff to update the triage Skill.

Once that diff merges, it feeds back into Skill that drives the inner loop agent, and the next time the agent runs the Skill should work better.

Would love to know if this is useful for folks. We use self improvement loops to manage the Warp open-source repository, and we extracted the framework behind it for others to adopt. Early version here.

cover

最近大家没少聊用「循环(loop)」来驱动智能体(agent),但这股讨论里也夹着一点疑问:循环到底是个啥?

我不能替别的用这个词的人说话,但我想拿技能(skill)和云端智能体(cloud agent)演示一个实操方法,搭出一种特别有用的循环:自我改进循环(self-improvement loop)。

它的核心想法是:智能体能靠外部反馈,让自己的技能质量随时间越变越好。我这个例子里的循环带了一个人工反馈环节,但只要你有一个不需要人介入的明确目标,同样的方法换上自动评分器(grader)也照样能跑。

举个具体的:假设这个技能负责 issue 分诊(issue triage),把新进来的 issue 分到几个桶里——可直接开发(ready-to-implement)、重复(duplicate)、信息不足(needs-info)。换成代码评审技能、修 bug 技能、事故响应技能等等,思路也都一样。

这个技能的初稿大概长这样:

完整的 triage-issue 技能

你要做的,是搭起下面这两层循环:

  1. 内层智能体循环:这一层才是真正调用技能的地方。对 issue 分诊来说,你可以手动跑,但更常见的做法是把它接进你的任务管理系统——每提一个新 issue 就自动跑一遍这个技能。技能的每次交互都要记录在某个地方:一个文件、一段智能体轨迹(agent trace),或是 Slack、GitHub 这类外部系统里的一次互动。
  1. 外层智能体循环:这是一个按计划定时运行的智能体,专门观察内层循环对技能的使用情况。对 issue 分诊器来说,这一层通常是个云端智能体,它会把分诊智能体每次运行的记录都拉过来。它的活儿,就是审视内层智能体的所有运行结果,并据此调整自己的技能。既然技能不过是一堆文件,那这就意味着:它会根据过往运行中的用户反馈,生成一份 diff 来改进技能。

下面我用 Warp 和我们的云端智能体平台 Oz 演示具体怎么做,但能实现这件事的方式有很多。这里我们拿 GitHub Issues 当 issue 跟踪系统。

这是一个示例仓库,里面有可供照着做的技能和 GitHub workflow。

第 1 步:搭起内层智能体循环

内层智能体循环用一个 GitHub action,每创建一个新 issue 就跑一次。

完整的 GitHub Action

这个 GitHub action 通过 Warp 的云端智能体平台 Oz 调起一个云端智能体。这个云端智能体会同步仓库、从 GitHub 拉取 issue 内容,再尝试给它分类。怎么把这套搭起来,代码都在下面链接的仓库里。

现在,每进来一个新 issue,就会有一个云端智能体跑内层循环的分诊技能,并打上一个标签,标明这是一条可直接开发(ready-to-implement)的新功能请求。

第 2 步:搭起用于自我改进的外层循环

不过假设有个人工审核员不认同智能体的判定。作为审看智能体所打标签的人,我把这个 issue 从「可直接开发」改成了「信息不足」(needs-info),并在讨论串里留了条评论,说明它为什么被分错了——比如,我们到底该不该为这个新功能加一个设置项,这一点还有歧义。

外层循环有意思的地方就在这里。外层循环智能体每天跑一次,会审视所有已被分诊过的 issue;它一跑起来,就会发现我手动改了标签,还给出了理由。

完整的 improve-triage-issue 技能

由于外层循环智能体的技能是通过一个编码智能体来运行的,它会接住我给出的反馈,生成一份 diff 来更新分诊技能。

这份 diff 一旦合并,就会回流进驱动内层循环智能体的那个技能;下次智能体再跑时,技能就应该表现得更好了。

很想知道这对大家有没有用。我们就是用自我改进循环来管理 Warp 的开源仓库的,并把背后这套框架抽了出来,供他人采用。早期版本在这里