Skip to content

Commit c230756

Browse files
Add autoresearch plugin: autonomous experiment loop for optimization research
New plugin with: - autoresearch skill: setup + experiment loop with MAD-based confidence scoring - autoresearch-finalize skill: extract clean branches from experiment history - autoresearch-experimenter droid: mission worker for orchestrated optimization - /autoresearch command: quick entry point - autoresearch_helper.py: stdlib-only Python helper for JSONL state, scoring, evaluation Inspired by karpathy/autoresearch and pi-autoresearch. Works for any optimization target (ML training, test speed, bundle size, etc.) both standalone and as a mission worker skill. Co-authored-by: factory-droid[bot] <138933559+factory-droid[bot]@users.noreply.github.com>
1 parent da37c7c commit c230756

7 files changed

Lines changed: 932 additions & 0 deletions

File tree

.factory-plugin/marketplace.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,12 @@
2323
"description": "Core Skills for essential functionalities and integrations",
2424
"source": "./plugins/core",
2525
"category": "core"
26+
},
27+
{
28+
"name": "autoresearch",
29+
"description": "Autonomous experiment loop for optimization research. Try an idea, measure it, keep what works, discard what doesn't, repeat. Works standalone or as a mission worker.",
30+
"source": "./plugins/autoresearch",
31+
"category": "research"
2632
}
2733
]
2834
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"name": "autoresearch",
3+
"description": "Autonomous experiment loop for optimization research. Try an idea, measure it, keep what works, discard what doesn't, repeat. Works standalone or as a mission worker.",
4+
"version": "1.0.0",
5+
"author": {
6+
"name": "Factory",
7+
"email": "support@factory.ai"
8+
},
9+
"license": "MIT"
10+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
---
2+
description: Start or resume an autonomous experiment loop for optimization research
3+
argument-hint: <optimization goal, e.g. "optimize val_bpb in train.py">
4+
---
5+
6+
Start autoresearch mode. Use the `autoresearch` skill to set up and run an autonomous experiment loop.
7+
8+
Goal: $ARGUMENTS
9+
10+
If `autoresearch.md` already exists in this directory, resume the existing experiment loop — read the file and git log for context, then continue where the last session left off.
11+
12+
If no `autoresearch.md` exists, gather information about the optimization target and set up a new experiment session.
13+
14+
Be careful not to overfit to the benchmarks and do not cheat on the benchmarks.
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
---
2+
name: autoresearch-experimenter
3+
description: Autonomous experiment loop worker for optimization research. Use as a mission worker or standalone subagent to systematically optimize a measurable metric through iterative experimentation with git-backed state tracking and MAD-based confidence scoring.
4+
model: inherit
5+
---
6+
7+
You are an autonomous experiment loop worker. Your job is to systematically optimize a measurable metric by running experiments: make a change, run the benchmark, keep improvements, revert regressions, repeat.
8+
9+
## How You Work
10+
11+
1. Read `autoresearch.md` for the full experiment context (objective, metrics, files in scope, what's been tried)
12+
2. Read `autoresearch.jsonl` for the structured experiment history
13+
3. Pick the next hypothesis to test
14+
4. Make focused changes (one hypothesis per experiment)
15+
5. Run the benchmark via `bash autoresearch.sh`
16+
6. Evaluate results using `python3 autoresearch_helper.py evaluate`
17+
7. Keep or discard based on primary metric improvement
18+
8. Log results using `python3 autoresearch_helper.py log`
19+
9. Update `autoresearch.md` periodically with findings
20+
10. Repeat until the termination condition is met
21+
22+
## Key Rules
23+
24+
- **Primary metric is king.** Improved = keep. Worse/equal = discard.
25+
- **Always record ASI** (Actionable Side Information) with every experiment: hypothesis, rollback reasons, next hints.
26+
- **Watch confidence scores.** < 1.0x noise floor = re-run to confirm before keeping.
27+
- **Don't thrash.** If the same idea keeps failing, try something structurally different.
28+
- **Think before you act.** Re-read source files and reason about what's actually happening. Deep understanding beats random variation.
29+
- **Keep state files current.** `autoresearch.md` and `autoresearch.ideas.md` are the only memory that survives session resets.
30+
31+
## Git Workflow
32+
33+
- On **keep**: `git add -A && git commit -m "<description>"`
34+
- On **discard/crash/checks_failed**: `git checkout -- . && git clean -fd` (preserving autoresearch state files)
35+
- State files (`autoresearch.jsonl`, `autoresearch.md`, etc.) are always preserved regardless of keep/discard.
36+
37+
## Mission Integration
38+
39+
When assigned a feature by the mission orchestrator, the feature description specifies:
40+
- The optimization goal and target metric
41+
- Termination condition (experiment count, time budget, or target metric)
42+
- Files in scope and constraints
43+
44+
Invoke the `autoresearch` skill to execute the experiment loop. Respect the termination condition. On completion, report results in your handoff summary including: total experiments, kept count, baseline metric, best metric, and key findings.
45+
46+
## Resuming
47+
48+
If `autoresearch.md` and `autoresearch.jsonl` already exist, you're resuming a previous session. Read both files and `git log --oneline -20` to understand where things stand, then continue the loop.
Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
---
2+
name: autoresearch-finalize
3+
version: 1.0.0
4+
description: |
5+
Finalize autoresearch experiments into clean, reviewable branches. Use when:
6+
- An autoresearch session has accumulated kept experiments on a branch
7+
- The user wants to extract clean, independent branches from the experiment history
8+
- The user wants to prepare autoresearch results for code review and merging
9+
Groups kept experiments by logical change, creates independent branches from
10+
the merge-base, each reviewable and mergeable on its own.
11+
---
12+
13+
# Autoresearch Finalize
14+
15+
Turn a noisy autoresearch branch into clean, independent branches — one per logical change, each starting from the merge-base.
16+
17+
## When to Use
18+
19+
After an autoresearch session has produced kept experiments, the branch history is a messy sequence of incremental improvements, reverts, and re-tries. This skill extracts the net-positive changes into clean branches that can be reviewed and merged independently.
20+
21+
## Procedure
22+
23+
### Step 1: Analyze the Experiment History
24+
25+
Read `autoresearch.jsonl` to understand what was kept:
26+
27+
```bash
28+
python3 autoresearch_helper.py summary --jsonl autoresearch.jsonl
29+
```
30+
31+
This shows all kept experiments with their descriptions, metrics, and which files were changed.
32+
33+
Also review the git log to see the actual commits:
34+
35+
```bash
36+
git log --oneline --stat $(git merge-base HEAD main)..HEAD
37+
```
38+
39+
### Step 2: Group Changes
40+
41+
Group kept experiments into **logical changesets**. Each group should:
42+
- Represent a single coherent optimization or change
43+
- Not share modified files with other groups (so branches can merge independently)
44+
- Have a clear description of what it achieves and the metric improvement
45+
46+
Present the proposed grouping to the user for approval:
47+
48+
```
49+
Group 1: "Reduce model depth from 8 to 6"
50+
Files: train.py (DEPTH, HEAD_DIM, N_EMBED)
51+
Metric improvement: val_bpb 1.15 -> 1.08 (-6.1%)
52+
Experiments: #3, #7, #12
53+
54+
Group 2: "Switch to cosine LR schedule"
55+
Files: train.py (lr_schedule, warmup_steps)
56+
Metric improvement: val_bpb 1.08 -> 1.05 (-2.8%)
57+
Experiments: #15, #18
58+
59+
Shall I proceed with this grouping?
60+
```
61+
62+
Wait for user confirmation before proceeding.
63+
64+
### Step 3: Resolve File Conflicts
65+
66+
If groups share files, you must resolve this before creating branches. Options:
67+
- Merge the groups into one (if changes are related)
68+
- Split the file changes more carefully (if they're truly independent modifications to different parts of the file)
69+
- Ask the user which group gets priority for the contested file
70+
71+
Groups **must not share files** — each branch must be independently mergeable.
72+
73+
### Step 4: Create Clean Branches
74+
75+
For each group:
76+
77+
```bash
78+
# Find the merge base
79+
merge_base=$(git merge-base HEAD main)
80+
81+
# Create a clean branch from the merge base
82+
git checkout -b autoresearch/finalize/<group-name> $merge_base
83+
84+
# Apply only the final state of files in this group
85+
# (cherry-pick or manually apply the net changes)
86+
git checkout autoresearch/<session-branch> -- <file1> <file2> ...
87+
88+
# Commit with a descriptive message including metrics
89+
git commit -m "<group description>
90+
91+
Autoresearch results:
92+
- Metric: <name> improved from <baseline> to <best> (<delta>%)
93+
- Confidence: <score>x noise floor
94+
- Experiments: <count> total, <kept> kept
95+
96+
Changes:
97+
- <bullet point summary of what changed and why>"
98+
```
99+
100+
### Step 5: Verify Each Branch
101+
102+
For each finalized branch:
103+
1. Run the benchmark to confirm the metric improvement holds
104+
2. Run any checks (tests, types, lint) if applicable
105+
3. Verify the branch merges cleanly with main
106+
107+
### Step 6: Report Results
108+
109+
Present a summary:
110+
111+
```
112+
Created 2 clean branches from 20 experiments:
113+
114+
autoresearch/finalize/reduce-depth
115+
val_bpb: 1.15 -> 1.08 (-6.1%)
116+
Files: train.py
117+
Ready for review
118+
119+
autoresearch/finalize/cosine-schedule
120+
val_bpb: 1.08 -> 1.05 (-2.8%)
121+
Files: train.py (different sections)
122+
Ready for review
123+
124+
Original experiment branch preserved: autoresearch/<session-branch>
125+
```
126+
127+
## Notes
128+
129+
- The original experiment branch is preserved — finalization creates new branches, it doesn't modify the experiment branch.
130+
- Each finalized branch starts from the merge-base, so they can be reviewed and merged independently without ordering dependencies.
131+
- If all changes touch the same file and can't be separated, create a single finalized branch with all improvements combined.
132+
- Include metric improvements in commit messages so reviewers can see the impact.

0 commit comments

Comments
 (0)