Course›Module 2: Working with one agent›Lesson 10

When the agent goes off the rails

Every agent goes off the rails sometimes. The skill isn't avoiding it; it's noticing early and recovering cheaply. Learn the warning signs, the recovery ladder from a quick interrupt to throwing the work away, and the habits that make recovery cheap.

Key takeaways

  • Interrupt early. Escape is always safe, and fixing one wrong line now beats untangling twenty later.
  • Climb the recovery ladder: redirect, rewind, revert to a commit, start fresh, or throw it away.
  • Commit after every working step. Commits are save points for you and for the agent.
  • When stuck, change the approach, not just the prompt.
  • Code is cheap now. Throwing work away and re-planning is often the fastest path.

Try it with your agent

Add this to your next task (or your memory file):

Commit after each step that passes the tests, with a descriptive message, so we can roll back. If a fix fails twice, stop and tell me what you learned instead of trying a third time. Never delete files, reset branches, or touch secrets to get unstuck.

Transcript

Intro

Every agent goes off the rails sometimes. The skill isn't avoiding it. It's noticing early, and recovering cheaply.

It's normal

Ben Vinegar makes a provocative point. If your agent never seems subtly wrong, if you never have to stop and scrutinize, that's a bad sign. It probably means you're just pressing go and merging.

Warning signs

Here are the warning signs we've met so far. It loops, trying the same thing again. It does work you didn't ask for. It weakens a test to get green. It agrees with you enthusiastically and keeps failing. Or its attempts get more and more extreme. Any one of these means: stop.

Interrupt early

The first tool is the escape key. Boris Cherny's advice: no matter what the agent is doing, you can always safely hit escape. It won't corrupt anything. If nineteen of twenty lines look right, stop it, correct the one, and let it continue.

The recovery ladder

When interrupting isn't enough, climb the recovery ladder. Each rung costs a bit more. Redirect with a quick correction. Rewind to an earlier point in the conversation. Revert the code to your last good commit. Start a fresh session from a summary. Or throw the work away and re-plan.

Save points

Reverting only works if there's something to revert to. In Anthropic's long-running agent experiments, the best behavior came from asking the model to commit its progress to git with descriptive messages after each step. That let it roll back bad changes and recover a working state on its own.

Start fresh

And when a session has gone sour, don't argue with it. As we saw in lesson four, a history full of failures invites more failures. Ask for a summary of what was learned, clear the session, and start over with a better prompt.

Change the approach

Sometimes the fix is to change the problem, not the prompt. Kent Beck's agent stalled on an algorithm in Rust. So he had it write a Python version first, with the same tests, in a less constraining language. Once the algorithm worked, he told it to erase the Rust code and transliterate the Python.

Throw it away

The top rung is the one people resist most: throwing the work away. But the economics have flipped. DHH says the cost of exploring a hunch has dropped a thousandfold. Kent Beck predicts teams will generate ten times as many experiments and keep one. Throwing away a failed attempt and re-planning is often the fastest path.

Make recovery cheap

A few habits make all of this cheaper. Commit after every working step. Keep tasks small, so a do-over costs minutes, not hours. Plan first, so mistakes surface in a document instead of a diff. And Mitchell Hashimoto suggests turning off agent notifications, so you decide when to check in, instead of being pulled away every few minutes.

Quick check

Quick check. Your agent has spent twenty minutes trying fixes. The diff keeps growing, and it just told you you're absolutely right, for the third time. What's the best move? Tap your answer.

Try it

Build recovery into your next task from the start. This prompt makes the agent leave save points, and tells it to stop and report instead of flailing.

Recap

Recap. Interrupt early; escape is always safe. Climb the ladder: redirect, rewind, revert, restart, throw away. Commit save points as you go. And when you're stuck, change the approach. That completes the core workflow. Next module: your toolkit, starting with memory files.