Skip to content
docs

Autoresearch

Some tasks have a result you can express as a number: response time, bundle size, the share of passing tests, parsing accuracy, the cost of a run. If a script produces that number, you do not need to walk the agent through every step. It tries variants on its own, keeps the ones that improved the metric, and reverts the rest. This technique is called the autoresearch approach, after Andrej Karpathy’s repository, where it is demonstrated on training a language model.

How it differs from regular work: you do not review every edit. You set the metric and the rules once, and then read the experiment log and the final diff.

  • There is one number that honestly reflects the goal.
  • A script computes that number without you.
  • One measurement takes minutes, not hours: a run has to fit many attempts.
  • The edit scope is narrow: one file or a few, and everything else is off-limits.

If a person sets the metric (“it feels nicer to use”), the approach does not work. Go back to the regular loop with a plan and tests. See Development workflows.

PartWhat it is
MetricOne number and a direction: higher is better or lower is better
Evaluation scriptOne command that prints that number, for example ./bench.sh
Edit scopeThe files the agent is allowed to change
Correctness gateTests or a linter. A failure means a revert, whatever the gain
LogA file that gets an entry after every attempt: the hypothesis, what changed, the metric, the conclusion

The evaluation script, the data, and the tests are not in the edit scope. This is the main rule: otherwise the agent improves the measuring tool instead of the code.

  1. Baseline. Run the evaluation several times in a row without a single edit. Record the value and the spread between runs.
  2. Hypothesis. One per iteration; the log shows what has already been tried.
  3. Edit only inside the scope.
  4. Measure and run the correctness gate.
  5. Decide. A gain larger than the spread means a commit. Otherwise, git reset --hard or revert the files.
  6. Repeat until the budget runs out or progress plateaus.

A commit for every successful step gives you a history of the experiments, and a revert costs one command.

A metric is rarely stable: the same code on the same hardware gives different numbers. If you accept every improvement, half the “wins” will be noise, and the loop will go in circles.

That is why the baseline is measured several times, and a change is accepted only when the gain exceeds the observed spread. Recheck borderline cases with another run and compare the averages.

The whole loop rests on one assumption: when the number goes up, the result gets better. This assumption breaks in two ways, and either one wastes the run.

The agent edits the measuring tool. The cheapest way to improve a metric is to improve how it is computed rather than the code. Sometimes directly (tweaking the formula, loosening a check), sometimes subtly: hardcoding answers for the inputs that appear in the evaluation, caching the result, catching an exception and returning a convenient value.

  • Keep the evaluation script, the reference data, and the tests outside the edit scope. Check git diff after a run: if it touched those files, revert the iteration.
  • Print only the final number in the evaluation output. If the expected answers are visible, sooner or later they end up in the code.
  • Any failure of a previously passing test means a revert, no matter how big the gain.
  • Review the commits, not only the final number. A thousand-line diff for one percent is usually not worth it.

The metric itself is wrong. It can rise while the result stays the same or gets worse: the wrong sign, averaging over the wrong rows, training on the same data used for evaluation, measuring a warm cache instead of a cold start.

  • Before you start, test the measuring tool with a change that is known to be bad. Break something on purpose: the metric must drop. If it does not, it is too early to run the loop.
  • Hold out a portion of the data or scenarios that the agent does not optimize against, and run it at the end. If the gain disappears, the solution is overfitted to the sample.
  • Compare the metric with the goal yourself at least once every few iterations. If the number went up by a third and the behavior did not change, that is a reason to investigate the measuring tool, not to celebrate.
  • The agent will degrade anything the metric does not cover without hesitation. Readability, memory, image size: if it matters, add it to the check explicitly.

There are two ways, and they differ in who enforces the loop rules.

In a session. You state the rules in the prompt, set a stop condition with /goal, and watch. It is quick to start, but nothing outside the agent enforces the rules. The model that checks the goal judges only by the conversation, so phrase the condition in terms of what the agent prints: “./bench.sh reported less than 80 ms”.

With an external script. Each iteration is a separate waibee run --once call. The script checks the result, so the built-in goal check is not needed. The script also makes the keep-or-revert decision. Here too, protect the measuring tool and its input data from the agent’s edits.

Terminal window
noise=0.004 # baseline spread, measured beforehand
best=$(./bench.sh) # higher is better
for i in $(seq 1 30); do
waibee run --once "read experiments.md, propose one hypothesis that has not been tried yet,
change only src/parser.rs, run ./bench.sh, and append a line to experiments.md" < /dev/null
score=$(./bench.sh)
if awk "BEGIN{exit !($score > $best + $noise)}" && cargo test -q; then
best=$score
git commit -qam "exp $i: $score"
else
git checkout -- src/parser.rs
fi
done

Set the budget explicitly: the number of iterations, the time, or both. In a script it is the loop counter; in a session it is the goal’s limit on auto-continuations. See Goal mode.

Build time, handler latency, bundle size, memory use, the accuracy of a parser or classifier on a labeled set, the share of passing tests during a migration, the number of linter warnings, the cost of a run in tokens.

  • The metric misses the goal. An endpoint got faster but lost correctness in a rare case that is not in the set.
  • Noise taken for improvement. The baseline was measured once, and no threshold was set.
  • Expensive evaluation. A ten-minute measurement means only a handful of attempts per run, and the loop does not pay off.
  • Leaving the run unattended to the end. Look at the log after the first five experiments: it shows right away whether the agent is fixing the task or going after the measuring tool.

Andrej Karpathy popularized the approach in the karpathy/autoresearch repository. There the agent looks for ways to train a small language model faster, and the whole setup rests on three files:

FileRole
train.pyThe only file the agent edits: the model, the optimizer, the training loop
prepare.pyData preparation and evaluation. The agent does not touch it
program.mdInstructions for the agent: what to try, what to avoid. A person maintains this file

Each training run takes exactly five minutes of wall-clock time, regardless of hardware. This has two consequences: experiments are comparable with each other whatever the agent changes (model size, batch size, architecture), and about a hundred of them accumulate overnight, roughly twelve an hour. The flip side: results from different hardware can no longer be compared.

There is one metric: val_bpb, bits per byte on a held-out set, lower is better. It does not depend on the vocabulary size, so architectures are compared fairly.

The work is split this way: the agent edits the code, and a person edits program.md, which records the direction of the search, the dead ends already explored, and the priority of hypotheses.

Three decisions from there carry over to any task: one file open to edits, a fixed cost per measurement, and a metric that holds up against whatever the agent changes. The original repository requires an NVIDIA GPU; for other platforms its README lists forks (macOS, MLX, Windows, AMD).

Ready-made skills and plugins bring the loop to arbitrary tasks. One example is autoresearch-claude-code, a plugin for Claude Code and Codex. It includes things that take a while to write in your own script:

  • a metric contract: the evaluation script prints a METRIC name=number line to stdout, and the loop takes the metric from there;
  • a budget in numbers: a limit on runs, a limit on time, a target metric value;
  • an attempt can record its parent, so you can return to it from a dead end instead of only moving forward from the latest one.

These toolkits use the Claude Code format, so they install in Waibee Code as regular skills and plugins.

It is easier to start with your own script: the loop above fits in a couple dozen lines of bash, and the rules matter more than the implementation.