The Problem
For the last few years, good results from AI needed good prompting. You wrote the request with care. You gave it context, showed it an example and asked for a format. Then you read the answer, saw what was wrong, and prompted again.
Look closely at that last step. The AI answered once. You were the loop.
You ran the command it suggested and saw the error. You pasted the error back and asked again. The model did the writing. But the checking, the retrying and the decision “this is finished” were all your work.
That works for a question. It falls apart for a task. “Fix the gaps around the images on my blog” is not one answer. It is look, change, measure, adjust and measure again, until the result is right.
That second shape is looping. I am sure that all of this is going there.
Prompting vs Looping
| Prompting | Looping | |
|---|---|---|
| Shape | one request, one answer | goal → act → observe → check → repeat |
| Who checks the result | you | the loop, against something real |
| What “done” means | the answer sounds right | a check passes |
| What you write | the prompt | the goal, the tools, the checks and the limits |
| How it fails | confidently wrong text | runs too long, does too much (unless you limit it) |
A prompt aims for an answer that sounds right. A loop aims for a result that is right. The loop measures each step against the world. That can be an exit code, a file that exists or not, or a number on a dashboard.
A Loop I Run Every Day
On my laptop, I keep a small local model (7B-class) in a tiny agent loop for terminal chores. The whole thing is a few dozen lines. Its shape is the shape of every loop that is worth building:
# simplified from the real script
def run_agent_loop(goal, auto_yes=False, max_turns=8):
messages = [system_prompt, f"Accomplish this task: {goal}"]
for turn in range(1, max_turns + 1): # 1. a hard limit on steps
reply = ask_model(messages, temperature=0.1)
if reply.startswith("DONE:"): # 2. an explicit way to stop
return print(reply)
cmd = extract_command(reply) # 3. one action per step
if not auto_yes and input(f"Run {cmd}? [Y/n/edit] ") == "n":
return # 4. a human checkpoint
result = run(cmd, timeout=60) # 5. every action has a timeout
messages += [reply, f"Output:\n{result}"] # 6. reality goes back in
It has six ingredients, and each one matters:
- A step budget. After eight turns it stops, no matter what.
- An explicit finish line. The model must say
DONE:and give a summary. It cannot trail off. - One action at a time. Small steps are easy to read, easy to approve and easy to undo.
- A checkpoint. By default I approve every command (Y / n / edit). The
-yflag is for chores I trust. - Timeouts. A command that hangs becomes an observation (“timed out after 60 s”). The loop does not freeze.
- Feedback from the real world. The real output of the command goes back to the model, errors included. That is the whole trick. The model does not guess what happened. It reads it.
A 7B model is not brilliant. In a loop like this, it does not need to be. It only needs to read an error message and try something else.
Loops Are Already Everywhere in My Lab
When you see the pattern, you notice something. Most of the automation I trust is already a loop, with or without AI in it:
The supervised reboot drill. My fleet updater has a “reboot live” mode that goes through the nodes one at a time. First it runs the fleet-wide health check. Then it reboots one host.
While the host is down, it probes DNS and internet from the point of view of a client. It waits for the host and its own self-check to come back. Only then does it move to the next host. It stops at the first problem. That is a loop whose check is “is the realm still healthy?”, and I watch it.
The documentation explainer. A small model on my AI node writes plain-English explanations for every file in my homelab wiki. It runs as a drip: at most 4 answers per run, with a 45-second pause between them.
Before every request, it reads the GPU and CPU temperatures from my monitoring. It stops if either one is too hot, or if the temperature data is missing or stale. For the explainer, missing data means “not safe”. It does not mean “carry on”. The cache uses a hash of the input as the key, so the model never explains the same thing twice.
The fairy who patrols the lab. Navi, the character in my homelab game, runs on a 15-minute loop. Every tick reads the state of the lab and reacts. The AI writes her lines, but it never decides outcomes. Combat, loot and penalties come from a deterministic engine.
Everything she posts goes through a privacy filter first. She also has a daily budget of posts and replies.
On-demand backups. When I run my backup tool, it does not trust that the backup command worked. It checks the backup store afterwards. A backup counts only when a snapshot newer than the run really exists.
This blog. I asked an AI coding agent to fix the gaps around images on this site. The first answer was not the useful part. The loop was.
The agent built the page and measured the blank space next to every image in a headless browser. It adjusted the layout rule and measured again. It stopped when no image on any post left more blank space than normal paragraph spacing.
The first attempt looked fine, but it still left a 220 px hole on one post. The measurement caught it. A prompt never would have.
Why Looping Is Where We’re Headed
Because checking beats sounding right. The biggest weakness of AI output is that it is fluent, correct or not. A loop takes away the chance for the model to only sound right. The next step depends on whether the last one worked.
Because the environment is the source of truth. Your servers, files, tests and dashboards know things that no model knows. A loop lets the model read them directly, at every step.
Because small models become useful. A local model can fumble a hard one-shot answer. But it can still finish a task if it can try, observe and correct. Loops trade intelligence for persistence. Persistence runs fine on a 6 GB graphics card.
Because your job moves up a level. When you prompt, you write requests. When you loop, you design systems.
You decide the goal and the tools the loop can touch. You decide what counts as done, when the loop must stop and where a human signs off. That is not prompt engineering. That is engineering.
How Loops Go Wrong (and the Guardrails I Use)
Loops are powerful because they keep going. That is also how they hurt you. Each failure I worried about has a boring guardrail:
- It never stops. → A hard step budget and a time budget. No exceptions.
- It does something destructive. → An allowlist of tools, read-only by default. Anything that deletes or publishes needs a human. My training game puts a read-only policy in the command-line tool itself. The tool enforces it before anything runs, so even the server cannot widen it.
- It burns resources. → Budgets per run and per day, and pauses between steps. Gates read real conditions (like temperature) before each step.
- It acts on stale or missing information. → Fail closed. If the input is missing or old, the loop waits or stops. It does not guess.
- It declares victory too early. → “Done” is a check: an exit code, a measurement, a file that exists.
- It repeats work or applies a step twice. → Use the input hash as the cache key. Number your steps and record them, so no step runs twice.
- It hides what it did. → Log every action and its result. You cannot trust a loop that you cannot audit.
Prompting Isn’t Dead
To be fair to the prompt, a lot of work is still one-shot. Examples are explaining a concept, drafting a paragraph or answering a question. A good prompt is still the first step of every loop. The goal and the rules you write at the start shape everything after them.
But some things must work: a fix, a migration, a layout, a backup. For those, I stopped asking for the right answer. I ask for a loop that can prove it.
Building Your First Loop
If you run a homelab, you can start small:
- Pick a chore with a clear check. “Disk usage below 80%”, “this service returns 200”, “no backup older than a day”.
- Give the loop one or two tools, read-only if you can.
- Write the check first. The loop ends when the check passes, not when the model says so.
- Add the limits before you run it: step budget, timeout per action, a human confirm for state changes.
- Log everything. Read the logs for a week before you give it the
-yflag.
Takeaways
- With prompting, you are the loop. You check, you retry and you decide when to stop.
- A loop moves that work into the system: act, observe, check against reality, repeat.
- The power of a loop comes from feedback from the real world, not from a smarter model.
- Even a small local model becomes useful in a good loop.
- Design the loop, not only the prompt: goal, tools, checks, budgets, stop conditions and human checkpoints.
- Guardrails make loops safe: hard limits, read-only defaults and fail-closed inputs.
- Budgets, idempotent steps and audit logs are guardrails too.
- Let AI choose words and next steps. Let checks decide if it worked.
- The prompt still matters, as the first step of every loop.
- But the future of real work with AI is a loop.