Skip to content

Commit e1b6061

Browse files
mrjfclaude
andcommitted
Support multiple independent loops per repository
- Programs now live in .github/autoloop/programs/ (one .md file per loop) - Each program gets its own namespace: metrics, memory, branches, PRs, experiment log - Programs can specify per-program schedule and timeout via YAML frontmatter - Slash command supports program targeting: /autoloop training: try X - Template moved to programs/example.md with instructions to rename Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 6e8df2a commit e1b6061

3 files changed

Lines changed: 136 additions & 53 deletions

File tree

docs/autoloop.md

Lines changed: 49 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
55
**Iterative optimization agent inspired by [Autoresearch](https://github.com/karpathy/autoresearch) and Claude Code's `/loop`**
66

7-
The [Autoloop workflow](../workflows/autoloop.md?plain=1) runs on a schedule to autonomously improve a target artifact toward a measurable goal. Each iteration proposes a change, evaluates it against a metric, and keeps only improvements.
7+
The [Autoloop workflow](../workflows/autoloop.md?plain=1) runs on a schedule to autonomously improve target artifacts toward measurable goals. Each iteration proposes a change, evaluates it against a metric, and keeps only improvements. Supports **multiple independent loops** in the same repository.
88

99
## Installation
1010

@@ -22,43 +22,58 @@ This walks you through adding the workflow to your repository.
2222

2323
```mermaid
2424
graph LR
25-
A[Scheduled Run] --> B[Read program.md]
26-
B --> C[Review History]
27-
C --> D[Propose Change]
28-
D --> E[Implement on Branch]
29-
E --> F[Run Evaluation]
30-
F --> G{Metric Improved?}
31-
G -->|Yes| H[Create Draft PR]
32-
G -->|No| I[Record & Reject]
33-
H --> J[Update Experiment Log]
34-
I --> J
25+
A[Scheduled Run] --> B[Discover Programs]
26+
B --> C[For Each Program]
27+
C --> D[Review History]
28+
D --> E[Propose Change]
29+
E --> F[Implement on Branch]
30+
F --> G[Run Evaluation]
31+
G --> H{Metric Improved?}
32+
H -->|Yes| I[Create Draft PR]
33+
H -->|No| J[Record & Reject]
34+
I --> K[Update Experiment Log]
35+
J --> K
3536
```
3637

3738
## Getting Started
3839

39-
When you install Autoloop, a **template `program.md`** is added to your repo at `.github/autoloop/program.md`. This template has placeholder sections you must fill in — the workflow **will not run** until you do.
40+
When you install Autoloop, a **template program file** is added at `.github/autoloop/programs/example.md`. This template has placeholder sections you must fill in — the workflow **will not run** until you do.
4041

4142
### Setup flow
4243

4344
```mermaid
4445
graph LR
45-
A[Install Workflow] --> B[Edit program.md]
46+
A[Install Workflow] --> B[Rename & Edit Program]
4647
B --> C[Define Goal, Targets, Evaluation]
4748
C --> D[Remove UNCONFIGURED sentinel]
4849
D --> E[Commit & Push]
4950
E --> F[Loop Begins]
5051
```
5152

5253
1. **Install**`gh aw add-wizard githubnext/agentics/autoloop`
53-
2. **Edit** — Open `.github/autoloop/program.md` and replace the placeholders with your project's goal, target files, and evaluation command. The template includes three complete examples (ML training, test coverage, build performance) for inspiration.
54-
3. **Activate** — Remove the `<!-- AUTOLOOP:UNCONFIGURED -->` line at the top of the file.
55-
4. **Compile & push**`gh aw compile && git add . && git commit -m "Configure autoloop" && git push`
54+
2. **Rename** — Rename `.github/autoloop/programs/example.md` to something meaningful (e.g., `training.md`, `coverage.md`). The filename becomes the program name.
55+
3. **Edit** — Replace the placeholders with your project's goal, target files, and evaluation command. The template includes three complete examples for inspiration.
56+
4. **Activate** — Remove the `<!-- AUTOLOOP:UNCONFIGURED -->` line at the top.
57+
5. **Compile & push**`gh aw compile && git add . && git commit -m "Configure autoloop" && git push`
5658

5759
If you forget to edit the template, the first scheduled run will create a GitHub issue reminding you, with a direct link to edit the file.
5860

61+
### Adding more loops
62+
63+
To run multiple optimization loops in parallel, just add more `.md` files to `.github/autoloop/programs/`:
64+
65+
```
66+
.github/autoloop/programs/
67+
├── training.md ← optimize model training loss
68+
├── coverage.md ← maximize test coverage
69+
└── build-perf.md ← minimize build time
70+
```
71+
72+
Each program runs independently with its own metric tracking, experiment log issue, and PR namespace. Copy the template, fill it in, and push — the next scheduled run picks it up automatically.
73+
5974
## Configuration
6075

61-
The `program.md` file (at `.github/autoloop/program.md` or repo root) has three sections:
76+
Each program file in `.github/autoloop/programs/` has three sections:
6277

6378
### 1. Goal — What to optimize
6479

@@ -72,7 +87,7 @@ List the files the agent is allowed to modify. Everything else is off-limits.
7287

7388
Provide a command to run and a metric to extract. Specify whether higher or lower is better.
7489

75-
### Example program.md
90+
### Example program file
7691

7792
````markdown
7893
# Autoloop Program
@@ -107,11 +122,13 @@ Edit the workflow's `schedule` field. Examples:
107122

108123
After editing, run `gh aw compile` to update the workflow.
109124

125+
Note: The schedule applies to the workflow as a whole — all programs iterate on the same schedule. To run programs at different frequencies, you can install the workflow multiple times with different schedules, each pointing to a subset of programs.
126+
110127
## Usage
111128

112129
### Automatic mode
113130

114-
Once `program.md` exists and the workflow is installed, iterations run automatically on schedule. Each run:
131+
Once at least one configured program exists, iterations run automatically on schedule. Each run processes every configured program:
115132

116133
1. Reads the program definition and past history
117134
2. Proposes a single targeted change
@@ -121,23 +138,26 @@ Once `program.md` exists and the workflow is installed, iterations run automatic
121138
### Manual trigger
122139

123140
```bash
124-
# Run an iteration now
141+
# Run all programs now
125142
gh aw run autoloop
126143

127-
# Give specific instructions
128-
gh aw run autoloop -- "try using cosine annealing for the learning rate schedule"
144+
# Target a specific program
145+
gh aw run autoloop -- "training: try using cosine annealing"
146+
147+
# If only one program exists, no prefix needed
148+
gh aw run autoloop -- "try batch size 64 instead of 32"
129149
```
130150

131151
### Slash command
132152

133153
Comment on any issue or PR:
134154
```
135-
/autoloop try batch size 64 instead of 32
155+
/autoloop training: try batch size 64 instead of 32
136156
```
137157

138158
## Experiment Tracking
139159

140-
All iterations are logged in a monthly GitHub issue titled `[Autoloop] Experiment Log {YYYY-MM}`. The issue tracks:
160+
Each program gets its own monthly experiment log issue titled `[Autoloop: {program-name}] Experiment Log {YYYY-MM}`. The issue tracks:
141161

142162
- Current best metric value
143163
- Full iteration history with accept/reject status
@@ -148,14 +168,15 @@ All iterations are logged in a monthly GitHub issue titled `[Autoloop] Experimen
148168

149169
- **Review draft PRs** — accepted improvements appear as draft PRs for human review
150170
- **Merge or close** — you decide which optimizations to keep
151-
- **Adjust the program** — update `program.md` to change the goal, targets, or evaluation
152-
- **Steer via slash command** — use `/autoloop <instructions>` to direct specific experiments
153-
- **Pause** — disable the workflow schedule to stop iterations
171+
- **Adjust programs** — edit any program file to change the goal, targets, or evaluation
172+
- **Add/remove loops** — add or delete files in `.github/autoloop/programs/`
173+
- **Steer via slash command** — use `/autoloop {program}: {instructions}` to direct experiments
174+
- **Pause** — disable the workflow schedule to stop all loops, or add the sentinel back to a single program file to pause just that loop
154175

155176
## Security
156177

157178
- Runs with read-only GitHub permissions
158-
- Only modifies files listed in `program.md`'s Target section
179+
- Only modifies files listed in each program's Target section
159180
- Never modifies evaluation scripts
160181
- All changes go through draft PRs requiring human approval
161182
- Uses "safe outputs" to constrain what the agent can create

workflows/autoloop.md

Lines changed: 70 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -74,58 +74,102 @@ An iterative optimization agent that proposes changes, evaluates them against a
7474
Take heed of **instructions**: "${{ steps.sanitized.outputs.text }}"
7575

7676
If these are non-empty (not ""), then you have been triggered via `/autoloop <instructions>`. The instructions may be:
77-
- **A one-off directive**: e.g., `/autoloop try a different approach to the loss function`. Execute it as a single iteration using the program.md context, then report results.
78-
- **A configuration change**: e.g., `/autoloop set metric to accuracy instead of loss`. Update the relevant program.md section and confirm.
77+
- **A one-off directive targeting a specific program**: e.g., `/autoloop training: try a different approach to the loss function`. The text before the colon is the program name (matching a file in `.github/autoloop/programs/`). Execute it as a single iteration for that program, then report results.
78+
- **A general directive**: e.g., `/autoloop try cosine annealing`. If no program name prefix is given and only one program exists, use that one. If multiple exist, ask which program to target.
79+
- **A configuration change**: e.g., `/autoloop training: set metric to accuracy instead of loss`. Update the relevant program file and confirm.
7980

8081
Then exit — do not run the normal loop after completing the instructions.
8182

83+
## Multiple Programs
84+
85+
Autoloop supports **multiple independent optimization loops** in the same repository. Each loop is defined by a separate markdown file in `.github/autoloop/programs/`. For example:
86+
87+
```
88+
.github/autoloop/programs/
89+
├── training.md ← optimize model training
90+
├── coverage.md ← maximize test coverage
91+
└── build-perf.md ← minimize build time
92+
```
93+
94+
Each program runs independently with its own:
95+
- Goal, target files, and evaluation command
96+
- Metric tracking and best-metric history
97+
- Experiment log issue: `[Autoloop: {program-name}] Experiment Log {YYYY-MM}`
98+
- Branch namespace: `autoloop/{program-name}/iteration-<N>-<desc>`
99+
- PR title prefix: `[Autoloop: {program-name}]`
100+
- Repo memory namespace: keyed by program name
101+
102+
On each scheduled run, the workflow iterates through **all configured programs** and runs one iteration per program. Programs with the `<!-- AUTOLOOP:UNCONFIGURED -->` sentinel are skipped.
103+
104+
### Per-Program Schedule and Timeout
105+
106+
Programs can optionally specify their own schedule and timeout in a YAML frontmatter block at the top of the file (after the sentinel, if present):
107+
108+
```markdown
109+
---
110+
schedule: every 1h
111+
timeout-minutes: 30
112+
---
113+
114+
# Autoloop Program
115+
...
116+
```
117+
118+
- **`schedule`**: Controls how often this program runs. On each workflow trigger, check if the program is due based on its schedule and the `last_run` timestamp in memory. If the program's schedule hasn't elapsed since its last run, skip it. If omitted, the program runs on every workflow trigger.
119+
- **`timeout-minutes`**: Maximum time for this program's iteration. If omitted, the program shares the workflow's overall timeout.
120+
121+
This lets you run a fast coverage check every hour while running a slow training loop once a day — all from the same workflow.
122+
82123
## Program Definition
83124

84-
The user configures the optimization loop by editing **`.github/autoloop/program.md`** — a template file installed alongside this workflow. This file defines three things:
125+
Each program file in `.github/autoloop/programs/` defines three things:
85126

86127
1. **Goal**: What the agent is trying to optimize (natural language description)
87128
2. **Target**: Which files the agent is allowed to modify
88129
3. **Evaluation**: How to measure whether a change is an improvement
89130

131+
The **program name** is the filename without the `.md` extension (e.g., `training.md` → program name is `training`).
132+
90133
### Setup Guard
91134

92-
**The workflow will not run until the user has edited the template.** The installed template contains a sentinel line:
135+
A template program file is installed at `.github/autoloop/programs/example.md`. **Programs will not run until the user has edited them.** Each template contains a sentinel line:
93136

94137
```
95138
<!-- AUTOLOOP:UNCONFIGURED -->
96139
```
97140

98-
At the start of every run, check for this sentinel. If it is present:
141+
At the start of every run, check each program file for this sentinel. For any program where it is present:
99142

100-
1. **Do not run any iterations.**
101-
2. Create a single GitHub issue (if one doesn't already exist) titled `[Autoloop] Action required: configure your program.md` with:
102-
- A clear explanation that the workflow is installed but paused until `program.md` is configured.
103-
- A direct link to the file: `${{ github.server_url }}/${{ github.repository }}/edit/${{ github.ref_name }}/.github/autoloop/program.md`
143+
1. **Skip that program — do not run any iterations for it.**
144+
2. If no setup issue exists for that program, create one titled `[Autoloop: {program-name}] Action required: configure your program` with:
145+
- A clear explanation that this program is installed but paused until configured.
146+
- A direct link to the file: `${{ github.server_url }}/${{ github.repository }}/edit/${{ github.ref_name }}/.github/autoloop/programs/{program-name}.md`
104147
- A brief guide: "Open the file, replace the placeholder sections with your project's goal, target files, and evaluation command, then remove the `<!-- AUTOLOOP:UNCONFIGURED -->` line."
105148
- Two or three example programs for inspiration (ML training, test coverage, build performance).
106-
3. Exit.
107149

108-
If the sentinel is absent, proceed with the iteration loop.
150+
If **all** programs are unconfigured, exit after creating the setup issues. Otherwise, proceed with the configured programs.
109151

110-
### Reading the Program
152+
### Reading Programs
111153

112154
At the start of every run:
113155

114-
1. Read `.github/autoloop/program.md` (or `program.md` in the repo root as a fallback).
115-
2. Check for the `<!-- AUTOLOOP:UNCONFIGURED -->` sentinel — if present, run the **Setup Guard** flow above.
116-
3. Parse the three sections: Goal, Target, Evaluation.
117-
4. Validate that all three sections have non-placeholder content. If any section still contains `TODO` or `REPLACE` markers, treat it as unconfigured — create/update the setup issue and exit.
118-
5. Read the current state of all target files.
119-
6. Read repo memory for the current best metric value and iteration history.
156+
1. List all `.md` files in `.github/autoloop/programs/`.
157+
2. If the directory is empty or doesn't exist, also check for a single `.github/autoloop/program.md` or `program.md` in the repo root as a fallback (for single-program setups).
158+
3. For each program file:
159+
a. Check for the `<!-- AUTOLOOP:UNCONFIGURED -->` sentinel — if present, run the **Setup Guard** for that program and skip it.
160+
b. Parse the three sections: Goal, Target, Evaluation.
161+
c. Validate that all three sections have non-placeholder content. If any section still contains `TODO` or `REPLACE` markers, treat it as unconfigured — create/update the setup issue for that program and skip it.
162+
d. Read the current state of all target files.
163+
e. Read repo memory for that program's metric history (keyed by program name).
120164

121165
## Iteration Loop
122166

123-
Each run executes **one iteration** of the optimization loop:
167+
Each run executes **one iteration per configured program**. For each program:
124168

125169
### Step 1: Read State
126170

127-
1. Read `program.md` to understand the goal, targets, and evaluation method.
128-
2. Read repo memory to get:
171+
1. Read the program file to understand the goal, targets, and evaluation method.
172+
2. Read repo memory (keyed by program name) to get:
129173
- `best_metric`: The current best metric value (null if first run).
130174
- `iteration_count`: How many iterations have been completed.
131175
- `history`: Summary of recent iterations (last 20).
@@ -145,7 +189,7 @@ Each run executes **one iteration** of the optimization loop:
145189

146190
### Step 3: Implement
147191

148-
1. Create a fresh branch: `autoloop/iteration-<N>-<short-desc>` from the default branch.
192+
1. Create a fresh branch: `autoloop/{program-name}/iteration-<N>-<short-desc>` from the default branch.
149193
2. Make the proposed changes to the target files only.
150194
3. **Respect the program constraints**: do not modify files outside the target list.
151195

@@ -160,7 +204,7 @@ Each run executes **one iteration** of the optimization loop:
160204
**If the metric improved** (or this is the first run establishing a baseline):
161205
1. Record the new `best_metric` in repo memory.
162206
2. Create a draft PR with:
163-
- Title: `[Autoloop] Iteration <N>: <short description of change>`
207+
- Title: `[Autoloop: {program-name}] Iteration <N>: <short description of change>`
164208
- Body includes: what was changed, why, the old metric, the new metric, and the improvement delta.
165209
- AI disclosure: `🤖 *This change was proposed and validated by Autoloop.*`
166210
3. Add an entry to the experiment log issue.
@@ -180,7 +224,7 @@ Each run executes **one iteration** of the optimization loop:
180224

181225
## Experiment Log Issue
182226

183-
Maintain a single open issue titled `[Autoloop] Experiment Log {YYYY}-{MM}` as a rolling record of all iterations.
227+
Maintain a single open issue **per program** titled `[Autoloop: {program-name}] Experiment Log {YYYY}-{MM}` as a rolling record of that program's iterations.
184228

185229
### Issue Body Format
186230

@@ -219,10 +263,11 @@ Maintain a single open issue titled `[Autoloop] Experiment Log {YYYY}-{MM}` as a
219263

220264
## Memory Schema
221265

222-
Store the following in repo memory:
266+
Store state in repo memory **keyed by program name**. Each program gets its own memory namespace (e.g., `autoloop/training`, `autoloop/coverage`):
223267

224268
```json
225269
{
270+
"program_name": "training",
226271
"best_metric": 0.0234,
227272
"metric_name": "validation_loss",
228273
"metric_direction": "lower",
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,18 @@
22
<!-- ⚠️ REMOVE the line above once you've filled in your program. -->
33
<!-- Autoloop will NOT run until you do. -->
44

5+
<!--
6+
Optional: control how often THIS program runs and its timeout.
7+
Remove the comment markers to activate. If omitted, the program
8+
runs on every workflow trigger with no per-program timeout.
9+
10+
---
11+
schedule: every 6h
12+
timeout-minutes: 30
13+
---
14+
15+
-->
16+
517
# Autoloop Program
618

719
<!--
@@ -10,6 +22,11 @@
1022
sentinel at the top. Commit and push — the loop will start on the next
1123
scheduled run.
1224
25+
Rename this file to something meaningful — the filename (minus .md) becomes
26+
the program name used in issues, PRs, and slash commands.
27+
28+
Want multiple loops? Just add more .md files to this directory.
29+
1330
Need inspiration? See the examples at the bottom of this file.
1431
-->
1532

0 commit comments

Comments
 (0)