← Blog

    What is an agent loop? A plain-English guide.

    Agent loops, AI loops, looping agents — same idea, different names. Here’s what they actually do.

    Published May 10, 2026 · 5 min read

    If you’ve used Claude Code, Gemini, Codex, Devin, or any modern AI coding tool, you’ve used an agent loop. You probably didn’t call it that. You probably just typed something like “fix the failing test” and watched the assistant grind for a few minutes.

    That grinding is the loop. This post is about what’s actually happening, why it costs what it costs, and what to do when it goes off the rails.

    The four-step loop

    Every agent loop — whether it’s called an AI loop, an agentic loop, an autonomous loop, or a looping agent — runs the same four steps in a circle:

    1. Observe. Read the codebase, the error, the previous attempt.
    2. Plan. Decide what to try next.
    3. Act. Edit a file, run a command, call an API.
    4. Verify. Did that work? If not, go back to step 1.

    That’s the entire pattern. The magic is that it can do this hundreds of times before you finish your coffee. The problem is the same.

    Why this is different from a chatbot

    A chatbot answers once. An agent loop keeps going until it thinks it’s done — or until something stops it. There’s no human in between attempt 1 and attempt 47. That’s the whole point. It’s also how a $2.40 estimate becomes a $65 surprise overnight.

    We wrote about that exact failure mode in the $65 overnight Ralph loop story.

    Where loops go wrong

    Three things mostly. First, the loop has no idea when to give up. Second, the loop has no idea what “done” means — so it claims victory on stuff that isn’t finished. Third, when it’s over, you have no clean record of what it actually did.

    The fix is boring and obvious: give the loop a budget, give it a way to actually check its work, and write down what happened. That’s what MartinLoop does. See the complete guide to agent loops, AI loops & Ralph loops for the full breakdown.

    Try it yourself

    npx -y martin-loop@latest start
    # Alternative: install globally
    npm install -g martin-loop@latest
    martin run "fix the failing test" --budget-usd 3 --verify "pnpm test"

    That’s a governed agent loop. Hard $3 ceiling. Only marks “done” if your tests pass. Free, Apache 2.0 licensed, no account.