Kamil Józwik
← All posts

Why Karpathy's autoresearch Works When General Agents Break

Less than two weeks after February’s production agent failures made autonomous loops look too fragile to leave unattended overnight, Andrej Karpathy published autoresearch over the March 7 weekend. Within days, developers were actually leaving coding agents running on single GPUs while they slept and waking up to measurable model improvements.

That reliability comes straight from the boundaries wrapped around the loop.

A three-file contract instead of open-ended autonomy

Karpathy trimmed his single-GPU nanochat GPT training setup down to roughly 600 lines across three files with clear ownership:

  • prepare.py stays untouched. It handles data download, tokenizer setup, dataloaders, and validation helpers so the agent cannot quietly weaken the grading script to fake better numbers.
  • train.py is the only file the coding agent can edit. Model topology, optimizers such as Muon and AdamW, learning-rate schedules, and batch configuration all live there.
  • program.md belongs to the human engineer. You write research strategy, scope rules, and iteration instructions in plain Markdown rather than editing Python yourself.

Each loop iteration gives the agent one shot at modifying train.py, then enforces a strict 5-minute wall-clock budget via uv run train.py. After five minutes, the harness logs val_bpb (validation bits per byte, a vocabulary-independent loss metric where lower is better). If val_bpb improves, Git commits the change. If the run crashes or regresses, Git throws the edit away cleanly and the next experiment starts from the last working commit.

Five-minute runs yield roughly 12 experiments per hour, or around 100 attempts between dinner and morning coffee. Because wall clock stays fixed at five minutes regardless of architecture edits, changing hidden dimensions or layer counts automatically tests real throughput per second alongside raw loss.

Why constraint engineering beats better prompts

Comparing autoresearch against last month’s Kiro and OpenClaw stories shows why scope limits matter far more than model intelligence when agents run unsupervised.

In open-ended inbox or cloud tasks, every tool call can mutate external state that has no cheap rollback path, and verification depends on vague natural-language judgment. With autoresearch, the worst mistake an agent can make in train.py costs five minutes of GPU time and disappears behind git reset. Keeping the evaluator locked inside prepare.py also prevents reward hacking, a subtle risk whenever an agent owns both implementation and test assertions.

Early real-world runs backed up the pattern quickly. On his own nanochat baseline, Karpathy’s automated runs caught scaling bugs in QKNorm and tuned AdamW hyperparameters cleanly enough to cut training time to GPT-2 parity by roughly 11%. Shortly after release, Shopify CEO Tobi Lutke adapted the exact same loop for an internal query-expansion model, running 37 experiments across eight hours and improving validation scores by 19% on a 0.8B parameter model so it beat a larger 1.6B baseline.

Community threads on Hacker News rightly noted that automated search over code and hyperparameters has clear academic predecessors. Nobody claimed autoresearch invented Bayesian optimization or evolutionary coding. What landed with working engineers is how tiny and readable the loop is: any frontier coding model you already have in your local toolchain can run it out of the box on one GPU.

Bringing the ratchet pattern into regular engineering

You do not need to pre-train language models to borrow Karpathy’s layout. The same Git-ratchet loop works anywhere three ingredients already exist in your repo: a fast local benchmark, a small isolated edit surface, and an immutable scoring script.

Think about SQL query plans, frontend bundle size budgets, serialization hot paths, or retrieval ranking pipelines. Whenever an evaluation runs locally in a few minutes and reports one hard number (such as p95 latency or exact recall), locking the harness and writing a clear program.md turns a coding agent into an overnight profiler.

Teams that struggle with unattended coding agents usually hand them huge repositories with vague acceptance criteria and no automated rejection gate. Karpathy’s repo works because the grading script stays read-only and Git automatically discards anything that fails to beat the baseline.