Run autonomous iteration loops: Goal → Metric → Loop (make change → verify → keep/revert → repeat).
text
SETUP:
1. Define GOAL (what to improve)
2. Define METRIC (how to measure success)
3. Define SCOPE (what can be modified)
4. Establish BASELINE (current metric value)
LOOP (forever or N iterations):
1. Review current state + history + results log
2. Pick next change (based on what worked, what failed, what's untried)
3. Make ONE focused change
4. Commit change (for rollback)
5. Run mechanical verification (tests, benchmarks, scores)
6. If improved → keep. If worse → revert. If error → fix or skip.
7. Log the result
8. Repeat until goal reached or max iterations
text
Goal: Improve memory search Top-1 hit rate from 65% to 75%
Metric: Benchmark score (openclaw cron runs --id <job-id> --limit 1)
Scope: ~/.openclaw/workspace/MEMORY.md, ~/.openclaw/openclaw.json
Max Iterations: 5
Then run the loop manually or spawn a subagent to execute it.
For simple tasks, run the loop yourself:
text
Iteration 1:
- Change: [describe what you'll change]
- Verify: [run verification]
- Result: [keep/revert + reason]
- Log entry
For longer tasks, spawn a subagent with the loop instructions:
text
sessions_spawn with:
- task: Full autoresearch loop specification
- timeoutSeconds: 600 (10 min per iteration)
- mode: run (one-shot) or session (persistent)
For very long loops, use exec with background continuation:
text
exec with:
- command: The optimization script
- background: true
- yieldMs: 60000 (check every minute)
DomainVerify CommandMemory searchopenclaw cron runs --id <job-id> --limit 1Testsnpm test, pytest, cargo testBuildnpm run build, cargo buildLinteslint ., ruff check .Benchmarksnpm run bench, custom benchmark scriptCoveragenpm test -- --coverage
Track iterations in TSV format:
text
iteration change metric_before metric_after delta status description
0 baseline 65.0 65.0 0.0 baseline initial state
1 lowered minScore 65.0 70.0 +5.0 keep improved retrieval
2 tried larger model 70.0 68.0 -2.0 revert worse, reverted
3 added corpus entry 70.0 72.0 +2.0 keep filled gap
When spawning a subagent for autoresearch, use this template:
markdown
GOAL: [what to improve]
METRIC: [how to measure]
VERIFICATION: [command to run]
SCOPE: [files that can be modified]
MAX_ITERATIONS: [number]
CONSTRAINTS:
- [resource limits]
- [safety rules]
- [reversibility requirements]
APPROACH:
1. Establish baseline
2. For each iteration:
a. Identify next change
b. Make ONE atomic change
c. Run verification
d. Compare to baseline
e. Keep if improved, revert if worse
f. Log result
3. Report final results
text
Goal: Improve benchmark score
Metric: Benchmark output
Changes: Config tweaks, corpus improvements, model changes
Iterations: 5-10
text
Goal: All tests passing
Metric: Test count failing
Changes: Fix one test at a time
Iterations: Until zero failures
text
Goal: Bundle < 100KB
Metric: Build output size
Changes: Remove dependencies, tree-shake, minify
Iterations: Until target met
text
Goal: Coverage > 80%
Metric: Coverage percentage
Changes: Add tests for uncovered lines
Iterations: Until target met
FailureResponseSyntax errorFix immediately, don't count as iterationRuntime errorAttempt fix (max 3 tries), then move onResource exhaustionRevert, try smaller variantTimeoutRevert, simplify approachExternal dependency failedSkip, log, try different approach
/stop)For advanced patterns, see: