Autonomous experimentation

From elophanto/EloPhanto · View interactive version

Autonomous experimentation is an AI agent skill from the GitHub repository elophanto/EloPhanto. A structured loop for autonomous, metric-driven experimentation. The agent modifies code, measures a metric, keeps improvements, discards regressions, logs everything, and repeats indefinitely. Inspir

How to use this skill

Skill file

Autonomous Experimentation

Description

A structured loop for autonomous, metric-driven experimentation. The agent modifies code, measures a metric, keeps improvements, discards regressions, logs everything, and repeats indefinitely. Inspired by karpathy/autoresearch, which uses this pattern to let an AI agent run ML training experiments overnight — modifying a training script, running 5-minute experiments, keeping what improves val_bpb, discarding what doesn't.

This skill generalizes that pattern beyond ML: any measurable optimization target works — code performance, binary size, test coverage, response latency, memory usage, benchmark scores, or any custom metric the user defines.

Triggers

Instructions

Setup Phase

Before starting the experiment loop, establish these with the user:

  1. Metric — What number are you optimizing? Must be machine-readable from command output.
  1. Target file(s) — What can the agent modify?
  1. Run command — How to measure the metric after each change.
  1. Constraints — What must NOT break?
  1. Run tag — A label for this experiment session (e.g., mar7-perf).
  1. Experiment journal — Create experiments.tsv with header:

```

commit metric status description

```

Record the baseline as the first entry.

The Experiment Loop

LOOP FOREVER:

  1. Baseline check — Read the current best metric from the journal.
  1. Hypothesis — Formulate ONE specific change to try. Write it down before coding.
  1. Implement — Modify only the in-scope file(s). Keep changes minimal and focused.
  1. Commit — git commit the change with a descriptive message.
  1. Run — Execute the run command, redirecting output to run.log:

```

<run_command> > run.log 2>&1

```

Do NOT let output flood the context window.

  1. Extract metric — Parse the metric from run.log.
  1. Decide — Compare to baseline:
  1. Log — Append to experiments.tsv:

```

<commit> <metric> <keep|discard|crash> <what was tried>

```

  1. Repeat — Go to step 2. Never stop. Never ask "should I continue?"

Simplicity Criterion

Borrowed from autoresearch: all else being equal, simpler is better.

When Stuck

If the last 5+ experiments all got discarded:

  1. Re-read the in-scope files for new angles
  2. Review the journal for patterns (what kinds of changes worked?)
  3. Try more radical changes (architectural, not just parameter tweaks)
  4. Try combining two previous near-misses
  5. Try the opposite of what you've been doing

Timeout and Crash Handling

Integration with EloPhanto

Examples

Good: Performance Optimization

User: "Optimize the response time of the LLM router. Run experiments overnight."

Agent:
1. Establishes metric: average latency from `pytest tests/test_core/test_router.py -v --tb=no`
2. Target file: core/router.py
3. Creates branch: experiment/mar7-router-perf
4. Records baseline: 145ms average
5. Experiment 1: cache provider configs → 138ms → keep
6. Experiment 2: async DNS resolution → 135ms → keep
7. Experiment 3: connection pooling → 131ms → keep
8. Experiment 4: remove fallback retries → 130ms but tests fail → discard
9. ... continues overnight

Good: ML Training (autoresearch-style)

User: "Run autoresearch on train.py. Optimize val_bpb."

Agent:
1. Metric: val_bpb (lower is better), extracted via `grep "^val_bpb:" run.log`
2. Target: train.py
3. Run command: `uv run train.py > run.log 2>&1` (5-min budget)
4. Experiments: architecture changes, hyperparameter sweeps, optimizer tweaks
5. Each experiment is a 5-minute training run
6. ~12 experiments/hour, ~100 overnight

Bad: No Clear Metric

User: "Make the code better"

Agent should ask:
- Better how? Faster? Smaller? More readable? More test coverage?
- What specific metric can we measure?
- What file(s) should I modify?

Bad: Too Many Changes at Once

Experiment: "Change the optimizer, double the learning rate, and switch to a different architecture"

This combines 3 hypotheses. If it improves, you don't know which change helped.
If it regresses, you don't know which change hurt. One change at a time.

Verify

Notes

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.