Autoresearch Skill
Run autonomous iteration loops: Goal → Metric → Loop (make change → verify → keep/revert → repeat).
Core Protocol
CODEBLOCK0
Principles
- 1. One change per iteration — Atomic changes. If it breaks, you know why.
- Mechanical verification only — No subjective "looks good." Use metrics.
- Automatic rollback — Failed changes revert instantly.
- Git is memory — Each experiment is committed. Git revert preserves history.
- Simplicity wins — Equal results + less code = KEEP
Quick Start
CODEBLOCK1
Then run the loop manually or spawn a subagent to execute it.
Usage Patterns
Pattern 1: Manual Loop (Interactive)
For simple tasks, run the loop yourself:
CODEBLOCK2
Pattern 2: Spawn Subagent (Autonomous)
For longer tasks, spawn a subagent with the loop instructions:
CODEBLOCK3
Pattern 3: Background Process
For very long loops, use exec with background continuation:
CODEBLOCK4
Verification Commands
| Domain | Verify Command |
|---|
| Memory search | INLINECODE0 |
| Tests |
npm test,
pytest,
cargo test |
| Build |
npm run build,
cargo build |
| Lint |
eslint .,
ruff check . |
| Benchmarks |
npm run bench, custom benchmark script |
| Coverage |
npm test -- --coverage |
Logging Format
Track iterations in TSV format:
CODEBLOCK5
Subagent Template
When spawning a subagent for autoresearch, use this template:
CODEBLOCK6
Common Patterns
Improving Benchmark Scores
CODEBLOCK7
Fixing Tests
CODEBLOCK8
Reducing Bundle Size
CODEBLOCK9
Increasing Coverage
CODEBLOCK10
Failure Handling
| Failure | Response |
|---|
| Syntax error | Fix immediately, don't count as iteration |
| Runtime error |
Attempt fix (max 3 tries), then move on |
| Resource exhaustion | Revert, try smaller variant |
| Timeout | Revert, simplify approach |
| External dependency failed | Skip, log, try different approach |
Stopping Conditions
- - Goal metric reached
- Max iterations hit
- No improvement for 3 consecutive iterations
- User interrupt (Ctrl+C or
/stop)
References
For advanced patterns, see:
自动研究技能
运行自主迭代循环:目标 → 指标 → 循环(做出变更 → 验证 → 保留/回滚 → 重复)。
核心协议
设置:
- 1. 定义目标(要改进什么)
- 定义指标(如何衡量成功)
- 定义范围(可以修改什么)
- 建立基线(当前指标值)
循环(无限次或N次迭代):
- 1. 审查当前状态 + 历史记录 + 结果日志
- 选择下一个变更(基于哪些有效、哪些失败、哪些未尝试)
- 做一个聚焦的变更
- 提交变更(用于回滚)
- 运行机械验证(测试、基准测试、评分)
- 如果改进 → 保留。如果更差 → 回滚。如果出错 → 修复或跳过。
- 记录结果
- 重复直到达成目标或达到最大迭代次数
原则
- 1. 每次迭代一个变更 — 原子性变更。如果出错,你知道原因。
- 仅机械验证 — 没有主观的看起来不错。使用指标。
- 自动回滚 — 失败的变更立即回滚。
- Git是记忆 — 每个实验都被提交。Git回滚保留历史。
- 简洁胜出 — 相同结果 + 更少代码 = 保留
快速开始
目标:将内存搜索Top-1命中率从65%提升到75%
指标:基准测试分数(openclaw cron runs --id --limit 1)
范围:~/.openclaw/workspace/MEMORY.md, ~/.openclaw/openclaw.json
最大迭代次数:5
然后手动运行循环或生成子代理来执行。
使用模式
模式1:手动循环(交互式)
对于简单任务,自行运行循环:
迭代1:
- 变更:[描述你将更改的内容]
- 验证:[运行验证]
- 结果:[保留/回滚 + 原因]
- 日志条目
模式2:生成子代理(自主式)
对于较长的任务,使用循环指令生成子代理:
sessions_spawn 使用:
- 任务:完整的自动研究循环规范
- timeoutSeconds:600(每次迭代10分钟)
- 模式:run(一次性)或 session(持久化)
模式3:后台进程
对于非常长的循环,使用带后台延续的exec:
exec 使用:
- 命令:优化脚本
- 后台:true
- yieldMs:60000(每分钟检查一次)
验证命令
| 领域 | 验证命令 |
|---|
| 内存搜索 | openclaw cron runs --id <job-id> --limit 1 |
| 测试 |
npm test, pytest, cargo test |
| 构建 | npm run build, cargo build |
| 代码检查 | eslint ., ruff check . |
| 基准测试 | npm run bench, 自定义基准测试脚本 |
| 覆盖率 | npm test -- --coverage |
日志格式
以TSV格式跟踪迭代:
迭代 变更 指标之前 指标之后 增量 状态 描述
0 基线 65.0 65.0 0.0 基线 初始状态
1 降低minScore 65.0 70.0 +5.0 保留 检索改进
2 尝试更大模型 70.0 68.0 -2.0 回滚 更差,已回滚
3 添加语料条目 70.0 72.0 +2.0 保留 填补空白
子代理模板
在生成用于自动研究的子代理时,使用此模板:
markdown
目标:[要改进什么]
指标:[如何衡量]
验证:[要运行的命令]
范围:[可以修改的文件]
最大迭代次数:[数字]
约束:
方法:
- 1. 建立基线
- 对于每次迭代:
a. 确定下一个变更
b. 做一个原子性变更
c. 运行验证
d. 与基线比较
e. 如果改进则保留,如果更差则回滚
f. 记录结果
- 3. 报告最终结果
常见模式
改进基准测试分数
目标:改进基准测试分数
指标:基准测试输出
变更:配置调整、语料改进、模型变更
迭代次数:5-10
修复测试
目标:所有测试通过
指标:失败的测试数量
变更:一次修复一个测试
迭代次数:直到零失败
减少打包大小
目标:打包小于100KB
指标:构建输出大小
变更:移除依赖、摇树优化、压缩
迭代次数:直到达成目标
提高覆盖率
目标:覆盖率大于80%
指标:覆盖率百分比
变更:为未覆盖的代码行添加测试
迭代次数:直到达成目标
失败处理
| 失败类型 | 响应 |
|---|
| 语法错误 | 立即修复,不计入迭代次数 |
| 运行时错误 |
尝试修复(最多3次),然后继续 |
| 资源耗尽 | 回滚,尝试更小的变体 |
| 超时 | 回滚,简化方法 |
| 外部依赖失败 | 跳过,记录,尝试不同方法 |
停止条件
- - 达成目标指标
- 达到最大迭代次数
- 连续3次迭代无改进
- 用户中断(Ctrl+C或/stop)
参考
关于高级模式,请参见: