bit by bit.
Entry 001Engineering notes

Loop engineering, explained with a toy robot

A robot puts away one toy, then says the room is clean. The gap between doing a task and checking the result explains why AI agents need a feedback loop.

In this entry

Ask a robot to clean your room. It puts one toy on the shelf, turns around, and announces that it’s finished. The books are still on the floor and the laundry is still on the chair.

You ask it to look again. It spots the books and puts them away. On the next pass, it notices the laundry. The robot is just as smart as it was the first time. This time it has a way to check its work and do something with what it finds.

That’s what I mean by loop engineering. You design what happens after an AI system takes its first step. What does it observe? How does it decide whether the task is done? What can it try when the result falls short?

Give the agent a way to check its work

Imagine asking a travel agent to find the cheapest flight to Tokyo with at most one stop, checked baggage included, and a total price under $800. The first search returns a $620 fare. It looks promising until you open the fare details and find two stops.

The agent can check the stop count, filter the next search, and keep looking. A second fare comes back at $710, but the baggage price is missing. The agent fetches the fare rules now and tries to calculate the total. If that price stays unavailable, it can flag the uncertainty and keep that fare out of its verified results.

What the agent observesWhat it does next
The cheapest fare has two stopsFilter for flights with at most one stop
A fare has an unknown baggage feeFetch the fare rules before comparing totals
A fare meets every constraintReport the cheapest verified option found and ask before booking
The search budget runs outShow the options it verified and explain what remains uncertain

Design the decisions between attempts

The loop needs state. In this example, that could be the search parameters already tried, the fares that passed each check, the reasons others failed, and time or tool calls left. Carrying that information forward lets the next attempt build on the last one instead of repeating it.

It also needs a stopping rule. For this example, we could set a limit of five searches and a 30-second deadline. A temporary search error is a good reason to retry within that budget. A missing travel date is a good reason to ask the user. A purchase is a reason to pause for approval.

Sketch the loop before writing the prompt

Start by writing down what counts as success and who can verify it. List two ways the first attempt could fail. For each one, decide whether the agent should revise its work, retry later, ask a question, or stop. Then test those cases along with the happy path.

Back in the bedroom, the stopping rule is simple. Check the floor, the shelves, and the laundry before calling the room clean. An AI workflow needs its own version of that checklist, plus a clear way to say what it was able to finish.

Adapted from my original article on X.

Image: Cycle of Loop Engineering
Image: Cycle of Loop Engineering