Infinite Loop

I saw Karpathy released autoresearch. An agent gets a training script and a markdown file with instructions. It modifies the training code, runs 5 minutes of training, checks the score, keeps or reverts, and loops. He wrote “LOOP FOREVER” and “NEVER STOP” in the instructions. He goes to sleep, wakes up, 100 experiments done.

The results actually get better the more the agent iterates. When I use Claude Code on hard problems, the agent tries something, backtracks, tries another way, and the result after 10 attempts is quite different from the first one.

Karpathy did this for training, but I think the same approach would work for other things too, like making a query faster or improving a prompt’s eval score, anything where the agent can tell if the result got better.

The problem is most agent tools use a finite loop, autoresearch runs inside one session, Claude Code sessions end after a while, and OpenClaw has task queues but nothing that says “keep going forever.” So you get maybe 30 runs and then the session dies.

Scheduled tasks can get around that though. Claude Code has a /loop command that runs a prompt on a cron schedule. OpenClaw has a heartbeat mechanism that keeps the agent running. The pieces are already there.

I think making this loop actually work comes down to three things. First, a reliable measurement that the agent can’t inflate, something like a test score or a benchmark number. Second, a strict keep-or-revert rule on every iteration so the agent doesn’t drift sideways. Third, a mechanism to keep running forever, since no agent tool does that natively yet, you need something like cron or heartbeat outside the agent restarting it.

I actually tested this while writing this post. I asked Claude Code to set up a cron job that rewrites this article every minute, trying to make it match my writing style better. Each iteration the agent reads my old posts, scores the current draft, edits or skips, and logs what it changed.

It has run 28 iterations so far. The first version was pretty bad, full of AI writing patterns like parallelism, vague pronouns, Silicon Valley thought-leader tone. Around iteration 8 the agent scored itself at 8/10 but I’d say it was more like 6, which is interesting on its own because the agent’s self-scoring was too generous and it stopped trying too early. After I told it the real score it recalibrated and kept going.

Each round caught different things. Early rounds fixed the obvious AI tells. Later rounds started catching subtler stuff, like the agent was using “But X is just one case” to dismiss things and pivot to a bigger claim, or it kept producing short choppy sentences when my actual writing uses longer flowing ones. None of that would show up in a single pass.

I think the hardest part is the measurement. For code and training you can run a test and check a number, Karpathy has val_bpb. My experiment only had self-scoring which turned out too generous. After iteration 16 the agent started skipping every single round, 8 skips in a row, because without a hard number to optimize against it couldn’t tell what to improve anymore. With val_bpb the loop would keep finding things to try. Without it the agent just goes “looks fine to me” and does nothing. For anything subjective like writing you’d need a separate model as a critic or a human checking in once in a while.

The agent also needs to either keep or revert on every iteration, otherwise it drifts sideways instead of improving. And since no agent tool runs forever natively right now, you still need something outside the agent like a cron job restarting it and passing in where it left off.

After 12 consecutive skips I stopped the loop. 28 iterations total. The agent improved the article on its own from about 4/10 to 7/10 in the first 16 rounds, then hit a wall and couldn’t get past it without me telling it what was wrong. This is the article you’re reading.

Like
Comment
Share

Leave a comment

Your email address will not be published. Required fields are marked *