AI Engineering

Loop engineering

The third lever is not what you say or what the model sees, it is what happens around each response, and it is where most silent failures get caught or missed.

7 min

Engineering the loop, not the prompt

Prompt engineering changes what you say. Context engineering changes what the model can see. Loop engineering is different again: it changes what happens around each response, before the model acts and after it acts, without touching the prompt or the context at all.

An agent does not produce one answer and stop. It runs a loop: decide on a next step, act by calling a tool, observe the result, and decide again. Left alone, that loop will happily stop as soon as it produces something that looks finished. Looking finished and being correct are not the same thing, and the gap between them is exactly what loop engineering closes.

The concrete moves are the tools you give the agent, the hooks that fire automatically on events like a file write, the subagents you send off to check a result independently, and the retry logic that sends the agent back around the loop when a check fails instead of accepting the first attempt. None of these change what the model was told or what it could read. They change the system the model operates inside.

This matters because it is a system-level decision, not a per-message one. You configure loop engineering once, in a hook script or a subagent definition or a settings file, and it applies to every request that follows. A sharper prompt only helps the one time you type it.

DECIDEmodel picks next moveACTruns a toolOBSERVEreads the resultVERIFYthe lever you engineerITERATEloop again, or stop

Select a numbered hotspot to see what occupies that part of the diagram.

A data migration task, walked through the loop, showing where a verify step catches a wrong result before anyone ships it.

Step 1: The request

You ask Claude Code to write a migration script that backfills a new `display_name` column on the `users` table, using `first_name` and `last_name` where both exist, falling back to `email` (the part before the @) otherwise. Decide: Claude reads the schema, sees the three columns, and plans a single UPDATE statement with a CASE expression.

Step 1 of 4

Question 1 of 4

What distinguishes loop engineering from prompt engineering and context engineering?

Answer choices for question 1