ALXPCK

The agent loop

What happens inside an AI coding agent, and why it matters for how you work with one

Perceive, decide, act, observe, repeat. Once you see the loop, you understand everything about how to work with an AI agent, and where you fit in it.

Every AI agent, no matter how sophisticated, runs the same basic loop:

  1. Perceive: take in context (your prompt, the codebase, tool outputs)
  2. Decide: determine what to do next
  3. Act: use a tool, write code, ask a question
  4. Observe: see the result
  5. Repeat

That’s it. That’s the whole thing. The magic isn’t in any one step. It’s in the loop. The agent gets better at the task with each iteration because each observation feeds back into the next perception.

Why this matters for you

When you work with an agentic coding tool, you’re part of the loop. You’re providing the initial context. You’re evaluating the output. You’re deciding when to intervene and when to let it run.

The quality of your collaboration depends on understanding where you fit in the loop:

Your job: taste, judgment, context, goals. What should this do? What does good look like? What constraints matter?

The agent’s job: speed, breadth, execution, iteration. Try things. Run tests. Explore options. Do the mechanical work.

Common mistakes

Over-specifying: Writing prompts that are basically pseudocode. If you know every step, just write the code. The agent is most useful when you describe the what and let it figure out the how.

Under-specifying: “Make it better.” Better how? The agent needs enough context to perceive the problem correctly. Garbage in, garbage out still applies.

Not reading the output: The agent shows you what it did. Read it. The observe step is where learning happens, for both of you.

The meta-loop

Here’s the thing that took me a while to understand: you and the agent are running the same loop. You perceive (read the agent’s output), decide (is this right?), act (approve, reject, redirect), and observe (what changed?).

Two loops, interleaved. That’s what agentic coding actually is.

When both loops are running well, when you’re providing clear context and the agent is iterating quickly, the result feels like thinking at the speed of typing. It’s the most productive I’ve ever been.

Get my best thinking on AI, delivered to your inbox a few times a month.

Not ready to talk?

See how AI can take over the operational side of your business, without touching the parts your audience trusts you for.