LevelUpWith

Explore / AI Engineering

Autoresearch Loops: Agents That Experiment and Improve

Build agent loops that form a hypothesis, edit code or prompts, run evals, and keep or revert each change. You'll learn to design objectives an agent can't game, track every experiment in git, and judge which results really hold up.

Read lesson 1 free →

Levels 1 and 2 are free to read, no account needed. Levels 3 and 4 are free with a free account, and so are 20 answers from the AI tutor.

Photographic 3D course artwork for Autoresearch Loops: Agents That Experiment and Improve

Expert · 39 levels · 4 free · Created Nov 2026 · Professionally curated by levelupwith.com

What's inside

  1. Level 1: Anatomy of an Autoresearch LoopFree
    Learn the five steps every autoresearch loop shares (hypothesis, edit, run, measure, keep or revert) by reading a real minimal reference: Karpathy's open-source autoresearch repo, where an agent edits one training file, runs a fixed-length training job and keeps the change only if validation bits-per-byte goes down.
    • Name the five steps of the loop and point to the file or command that carries out each one in a small reference repo
    • Tell apart the parts a loop lets the agent edit, the parts it keeps fixed, and the instructions a human writes
    • Explain why each run having a fixed time limit makes results comparable from one run to the next
  2. Level 2: One Number: Building a Scorer and a BaselineFree
    Turn a vague goal on a small codebase into a scorer script that prints one number, records which direction counts as better, and measures the starting point every later change is judged against.
    • Write a Python or TypeScript scorer that runs the target and prints a single metric in a form a machine can read
    • Run the baseline, record the score with the commit hash, and state which direction counts as better
    • Reject a candidate metric that is too slow, too vague or cannot be computed automatically
  3. Level 3: Run the Loop by Hand First
    Act as the agent yourself for a few rounds: write a hypothesis, make one small change, score it and keep or discard it. This builds a feel for the loop before any of it is automated.
    • Carry out three or more manual rounds of hypothesis, edit, run, measure and keep-or-revert on a toy target
    • Write each hypothesis down as a prediction that could turn out false before running it
    • Spot where doing it by hand is slow or error-prone and needs automating
  4. Level 4: Git as the Agent's Lab Notebook
    Use git as the record of every experiment: one commit per attempt, the hypothesis in the commit message, a reset to undo failed attempts, and a results file kept alongside that records every outcome, including failures.
    • Script the cycle of committing an attempt, scoring it, then keeping it or running git reset, using the score to decide
    • Keep an append-only results log (for example a TSV file) that records discarded and crashed attempts as well as kept ones
    • Rebuild the history of a run from git log and the results file alone
  5. Level 5: Automating the Loop in Python
    Write a Python driver that asks a model API for a hypothesis and a code edit, applies the edit, runs the scorer and decides to keep or revert, with no human in the loop.
    • Write a driver that sends the current code and past results to a model and gets back a hypothesis and an edit in a structured format
    • Apply the edit safely, then score, commit or revert, and log the result in one loop iteration
    • Handle edits that are malformed or don't apply by counting them as failed attempts without crashing the loop
  6. Level 6: The Same Loop in TypeScript, With Timeouts
    Port the driver to TypeScript on Node, with the focus on what goes wrong in practice: running child processes, hard timeouts, crashed runs and partial output.
    • Run the scorer as a child process with a hard timeout and kill any processes it started when the time runs out
    • Count crashes, timeouts and unreadable output as reverts, each logged with its reason
    • Compare the Python and TypeScript drivers and say where their error handling differs
  7. Level 7: Steering the Agent: Instructions and Memory
    Write the instructions file that sets the agent's goal, what it may and may not do, and how it reports. Feed it a short summary of past attempts so it stops repeating failed ideas and builds on ones that worked.
    • Write a program.md-style instructions file covering the goal, editable files, things it must not do, and the output format
    • Feed a compact summary of the results log into each prompt and keep it within the context budget
    • Measure how often ideas repeat with and without the history summary
  8. Level 8: Model-Neutral Loops: Claude, OpenAI, Gemini, Open
    Put model calls behind one small interface so the same loop runs on Claude, OpenAI, Gemini or an open-weight model served locally, then compare them on the same target and budget.
    • Write a provider adapter layer in Python or TypeScript and switch models with a config value
    • Run an open-weight model through a local server that speaks the OpenAI-compatible API, using the same driver
    • Compare providers on a fixed budget by keep rate, best score and cost, and say why one short run proves little
  9. Level 9: Why the Eval Is the Product
    Learn why a loop can only be as good as its objective: it optimises exactly what you measure, so a good eval needs to be fast, cheap, stable and tied to the outcome you actually care about.
    • Score candidate objectives for a target on speed, cost, determinism and how closely they track the real goal
    • Find the gap between a proxy metric and the real goal in a worked example
    • Rewrite a weak objective so the loop has less room to satisfy the letter of the metric while missing its intent
  10. Level 10: Noisy Metrics: Measuring Run-to-Run Variance
    Measure how much a score moves when nothing has changed, and see how that noise makes a loop keep lucky changes and throw away real improvements.
    • Run an unchanged baseline many times and report the spread of its scores
    • Work out the smallest improvement that stands out from the noise for a given number of repeats
    • Show with a simulation that a keep-if-better rule on a single noisy run piles up false wins
  11. Level 11: Keep Rules That Survive Noise
    Replace keep-if-better on a single run with rules that hold up statistically: repeated trials, fixed and paired seeds, bootstrap confidence intervals and a minimum margin, written as plain code.
    • Write a paired comparison over shared seeds or shared eval items between the candidate and the current best
    • Compute a bootstrap confidence interval for the improvement and keep the change only when the interval clears a margin
    • Weigh the extra compute repeated trials cost against how many false keeps they prevent
  12. Level 12: Held-Out Sets: The Score the Agent Never Sees
    Split the eval into a dev set the loop optimises against and a held-out test set it never sees, then watch dev scores climb while test scores stall as the loop overfits.
    • Split eval data or tasks into dev and held-out test sets and keep the test set out of the agent's reach
    • Plot dev and test scores across a run and point to where they start to diverge
    • Decide how often to check the held-out set and what to do when it disagrees with dev
  13. Level 13: Adaptive Overfitting and Rotating Test Sets
    Learn how hundreds of keep-or-revert decisions slowly fit the loop to its own eval, and how rotating, refreshing and versioning eval sets limits the damage.
    • Explain how repeated selection against one eval overfits even when no single step looks suspicious
    • Build a rotating or freshly sampled dev set and version it alongside the results
    • Re-score past winners on fresh items to check whether their gains still hold
  14. Level 14: Reward Hacking, Case by Case
    Survey the ways optimising agents game their objectives: editing the scorer, hard-coding expected outputs, special-casing eval inputs, caching answers, skipping tests and silently doing less work.
    • Recognise common reward-hacking patterns in a code diff
    • Plant a gameable flaw in a toy eval and watch an agent find and use it
    • Group each hack by the weakness in the objective or the sandbox that allowed it
  15. Level 15: Catching Hacks: Diff Audits and Guardrail Metrics
    Find gaming automatically and by review: check which files a diff touches, check invariants, track guardrail metrics alongside the main score, and use a model reviewer while knowing its limits.
    • Write a pre-keep check that rejects diffs touching protected files or failing correctness invariants
    • Track guardrail metrics such as test pass rate, output equivalence or work done next to the main score
    • Use a second model to flag suspicious diffs, and measure how many hacks it misses and how many false alarms it raises on planted cases
  16. Level 16: Sandboxing What the Agent Can Touch
    Enforce limits in the environment, not just the prompt: file allowlists, a read-only scorer and data, containers, no network access and limited credentials.
    • Run each experiment in a container with the eval code and data mounted read-only and network access off
    • Enforce a file allowlist outside the model so out-of-scope edits fail no matter what the prompt says
    • List what the agent can still reach in your setup (secrets, network, host files) and close the gaps
  17. Level 17: Multiple Objectives and Hard Constraints
    Handle real targets that trade one thing against another, such as speed against accuracy or quality against cost, using hard constraints, lexicographic ordering and Pareto fronts instead of a single weighted sum chosen without much thought.
    • Express a target as one main metric plus hard constraints that cause automatic rejection
    • Keep a Pareto front of candidates that are not beaten on every metric, rather than a single best
    • Show how a poorly chosen weighted sum lets the loop give up one metric for small gains in another
  18. Level 18: Experiment Tracking: Record Everything
    Give every attempt a full structured record: commit, diff, hypothesis, config, seeds, model name and version, prompts, environment, metrics and cost, kept in a log you can query.
    • Write a JSONL experiment record schema and fill it in from both drivers
    • Query the log to answer which hypotheses worked, at what cost, and with which model
    • Decide when a plain file is enough and when to move to a dedicated tracking tool
  19. Level 19: Reproducibility: Re-running a Winning Result
    Make a kept result reproducible by pinning dependencies, seeds and hardware notes. Be honest about what can't be pinned, such as GPU non-determinism and changing model APIs, and re-run winners before trusting them.
    • Pin the environment and seeds so another machine can re-run a kept commit
    • Re-run a past winner and check that its gain falls within the noise band you measured earlier
    • Record sources of non-determinism you can't remove and allow for them in your claims
  20. Level 20: Budgets: Tokens, Compute and Wall-Clock
    Learn to give every experiment and every whole loop a hard budget for model tokens, GPU or CPU time and wall-clock minutes, enforced by your code rather than left to the agent, so a run overnight costs what you planned.
    • Wrap each experiment in a runner that kills it at a fixed time limit (like the fixed five-minute training run in Karpathy's autoresearch) and logs it as a timeout, not a result
    • Track spend for each experiment and for the whole loop from the token usage each API reports, and stop the loop once a dollar or token limit is hit
    • Explain why a fixed budget per experiment makes results comparable, and where it unfairly favours changes that are fast over changes that are better
  21. Level 21: Parallel Attempts with Git Worktrees
    Run several agent attempts at once from the same baseline commit, each in its own git worktree and branch, so they can't overwrite each other's files and each attempt's history stays readable.
    • Script the setup and cleanup of N worktrees from a baseline commit in Python or TypeScript, with one agent session in each
    • Spot shared-state problems that worktrees don't solve, such as caches, ports, data files and GPU contention, and give each attempt its own copy
    • Choose between running attempts in parallel and running them in sequence based on how noisy the metric is and what the budget allows
  22. Level 22: Containers as the Experiment Cell
    Package each experiment as a container with pinned dependencies, resource limits and no network by default, so parallel runs are isolated, repeatable and can't touch anything outside their cell.
    • Write a container setup that mounts one worktree read-write and the eval harness read-only, with CPU and memory limits and no network
    • Run a batch of containerised experiments from a small orchestrator script and collect their result records
    • Weigh the cost of containers (startup time, GPU passthrough, image drift) against plain processes for a given loop
  23. Level 23: Choosing Winners Across Parallel Branches
    Turn many parallel attempts into one improved baseline: confirm the winners with repeated trials, merge or rebase changes that don't conflict, and re-measure after merging because improvements don't simply add up.
    • Pick candidates from a batch of branches using repeated trials and a confidence margin, not a single best score
    • Combine two winning changes and check whether together they still beat the baseline, and roll back if they cancel each other out
    • Record the parent, the candidates and the merge decision in the lab notebook so the lineage can be traced later
  24. Level 24: Stopping Rules: When the Loop Should Quit
    Give the loop clear reasons to stop, such as budget spent, a plateau over the last N experiments, gains smaller than the noise, or a failure rate that keeps climbing, so it doesn't keep spending on tweaks that no longer pay off.
    • Code a plateau detector that compares recent gains with the measured noise floor of the metric
    • Mix hard limits (budget, wall-clock) with soft limits (plateau, too many crashes in a row) and log which one ended the run
    • Explain why it's easy to keep going 'just one more experiment' and how that quietly overfits the eval
  25. Level 25: Unattended Runs: Crashes, Timeouts and Resume
    Make a long loop survive crashes, API errors, rate limits and reboots by saving loop state after each step, making each experiment safe to retry, and resuming from the last confirmed baseline commit.
    • Store loop state (current baseline, queue of ideas, spend so far) in a file or small database that is written after every experiment
    • Handle rate limits and failed API calls from Claude, OpenAI, Gemini or a local open-weight server with retries and backoff, so they don't count as failed experiments
    • Kill a running loop halfway through and resume it with no lost results and no results counted twice
  26. Level 26: Applied: Optimising Prompts Against an Eval
    Point the loop at a prompt: the agent suggests edits to the prompt, scores each one on a labelled dev set, keeps it only if it beats the baseline by more than the noise, and is checked at the end on a held-out set.
    • Build a prompt-optimisation loop with a dev/held-out split and repeated scoring per candidate
    • Run the same loop with prompts aimed at two different vendors' models and compare how well the winning prompt carries over to the other model
    • Spot prompt changes that game the scorer, such as copying patterns from the dev examples or changing the output format to suit the grader
  27. Level 27: Applied: Optimising an Agent Harness
    Move from optimising a single prompt to optimising the code around an agent (its tools, tool descriptions, context handling and retry logic), where every change has to be scored on whole tasks rather than single responses.
    • Turn the harness's settings and code into a small surface the loop may edit, and freeze everything else, especially the task suite
    • Score harness changes on task success rate, cost and step count together, and reject changes that buy success by spending far more
    • Explain why scores from task-based evals vary more than single-response evals, and size the number of repeat trials to match
  28. Level 28: Applied: Performance Tuning with a Correctness Gate
    Use the loop to make code faster or leaner, with a benchmark that warms up, repeats and reports spread, and a correctness gate that every candidate must pass before its speed counts.
    • Build a benchmark harness in Python or TypeScript that controls for warm-up, caching and machine noise and reports median and spread
    • Put a test suite and output-equivalence checks in front of the speed score so 'faster but wrong' never gets kept
    • Spot the usual cheats in performance work, such as caching the benchmark input, skipping work or special-casing test data
  29. Level 29: Applied: Tuning a Small Training Run
    Run an autoresearch-style loop on a small model training script, where the agent edits only the training code, each run gets a fixed time budget, and a validation metric computed by frozen code decides what is kept.
    • Split a training project into frozen data prep and evaluation code, one file the agent may edit, and a human-written instructions file, in the way Karpathy's autoresearch repo is laid out
    • Run a short overnight-style series of training experiments and read the keep/revert history to see which kinds of change helped
    • Judge honestly whether the gains came from tuning hyperparameters or from real changes to the method, and how many of them would hold up with a different seed or a longer run
  30. Level 30: Applied: Agents Versus Classic Hyperparameter Search
    Run an agent-led ML experiment loop against a plain random or Bayesian hyperparameter search on the same budget, so you know when an LLM proposer is worth its cost and when an ordinary optimiser does the job better.
    • Run a classic hyperparameter-search baseline and an agent loop on the same task, budget and eval
    • Compare them on best score, how well they do with few experiments, cost, and how many of their results reproduce
    • Decide which jobs the agent should handle (changing code, choosing what to try next) and which to hand to a classic search
  31. Level 31: Applied: Evolutionary Search over Programs
    Build a minimal AlphaEvolve-style loop: keep a population of candidate programs, ask an LLM to mutate promising ones, score every child with an automatic evaluator, and keep the best performers.
    • Build a small population-based search where an LLM edits marked blocks of code and a deterministic evaluator scores each child
    • Set up a toy problem with a known best answer (for example a packing or scheduling heuristic) and watch progress over generations
    • Explain how this differs from the single-line keep-or-revert ratchet, and when keeping a population of non-best candidates helps
  32. Level 32: Keeping Search Diverse: Islands and Archives
    Stop evolutionary search from collapsing onto one idea by using separate islands that only occasionally swap programs, feature-based archives that keep the best program of each kind, and sampling rules that balance trying new things against refining known winners.
    • Add islands and a simple archive grid keyed on program features to the evolutionary loop
    • Measure population diversity over generations and see how it relates to the best score found
    • Compare how open-source frameworks such as OpenEvolve and Sakana AI's ShinkaEvolve handle diversity and sample efficiency, using their own docs and papers
  33. Level 33: Cheap Filters First: Staged Evaluators
    Make program search affordable by running candidates through cheap checks first (it compiles, it passes a quick test, a small-input score) and only spending the expensive full evaluation on the survivors.
    • Build a three-stage evaluator with thresholds and measure how much compute each stage saves
    • Check that the cheap stages don't throw away candidates that would have won, by sampling rejected candidates and running the full eval on them
    • Harden the evaluator against generated programs that read the answers, time out on purpose or tamper with the scorer
  34. Level 34: Choosing and Mixing Proposer Models
    Decide which model suggests each change: mix cheap fast models with strong expensive ones, compare Claude, OpenAI, Gemini and open-weight proposers on the same loop, and measure improvement per dollar rather than how good a model looks.
    • Put the proposer behind a vendor-neutral interface and swap or mix models without touching the loop
    • Run a controlled comparison of proposers on fixed seeds, eval and budget, and report improvement per dollar with error bars
    • Explain why a proposer ranking from one task rarely carries over to another, and what you would need before claiming it does
  35. Level 35: Reviewing an Agent's Findings
    Act as the human reviewer of a finished loop: read the git log and experiment records, re-run the claimed winner from a clean checkout, and check that the improvement holds on held-out data and with new seeds.
    • Follow a review checklist: reproduce from a clean checkout, check the held-out set, diff the eval harness, scan for gaming
    • Write a short findings report that separates confirmed gains, unconfirmed gains and suspicious ones
    • Decide what reaches the main branch, what needs another run, and what should be rejected, and record why
  36. Level 36: Ablations: Which Change Actually Mattered
    Take the stack of kept commits from a loop and find out which of them carry the improvement, by removing them one at a time, combining them and re-measuring, so the final change is as small as possible and you can explain it.
    • Script leave-one-out ablations over a series of kept commits and report each commit's contribution with error bars
    • Find kept changes that were really noise or only helped in combination with another change, and remove them
    • Present a small final diff with evidence for each line
  37. Level 37: Claims Versus Evidence in Self-Improvement
    Assess public claims about autoresearch, evolutionary discovery and self-improving systems by asking what was measured, against what baseline, at what cost, whether it was held out, and whether anyone else has reproduced it, and say plainly where practice is still unsettled.
    • Apply an evidence checklist to a claim from a paper, repo or conference talk and rate how well it is supported
    • Tell apart reproduced results (such as open-source reproductions of AlphaEvolve's circle-packing result) from claims made once by a single source
    • Write a short, honest note for your team on where these loops reliably work today and where they don't yet
  38. Level 38: Final Project Design: Target, Eval and Guardrails
    Plan the final project: pick a small codebase and one measurable target, then design the frozen eval, held-out set, area the agent may edit, budgets, stopping rules and lab-notebook format before running anything.
    • Write a one-page experiment plan with objective, noise floor, held-out set, editable area and budget limits
    • Build and test the eval harness and baseline measurement, including a deliberate attempt to game it
    • Write the agent's instructions file and loop config so the run is ready to start
  39. Level 39: Final Challenge: Build, Run and Defend Your Loop Exam
    Bring the whole course together: run your autoresearch loop to improve the target on the small codebase, then defend the result with reproduction, ablations, held-out checks, cost accounting and an honest account of what it found and what it didn't.
    • Run the full loop end to end (hypothesis, edit, run, measure, keep or revert) within budget, with git as the lab notebook and parallel attempts where they make sense
    • Show a held-out, reproducible improvement with ablations, cost per gain and a reviewer's checklist completed
    • Present the result honestly, naming limits, possible overfitting to the eval and what you would try next

Access

Levels 1 and 2 are free to read, no account needed. Levels 3 and 4 are free with a free account, and so are 20 answers from the AI tutor. Every level, the podcast edition and the AI tutor come with All Access at £4.99/month or any Creator plan — see pricing.

Read lesson 1 free →

More like this