What to look at: six pieces that fit together into one machine. Each section below is a piece — put them all together and you have a loop.
🧠 The model (the decision-maker)
At the center is a single LLM that decides what to do at each turn. In Claude Code, it’s Claude itself reading your instructions and choosing the next action. You no scripts the steps — the model chooses.
🧩 Why it’s universal
Every source that actually describes an agent loop puts a model at the center, directing each iteration. Anthropic’s one-line definition is literally: "LLMs using tools autonomously in a loop." Remove the model and there’s no loop—just a script with fixed steps.
🔧 The tools (how it acts in the world)
Tools are the actions the model can take: read and write files, run commands in the terminal, run tests, search, call an API. In Claude Code, they’re built in. Without tools, the model only talks — it doesn't act.
💡 The craft is in the tools
Anthropic says it's "crucial to design toolsets and their documentation clearly." In other words, the loop itself is trivial; the real work lies in which tools the agent has and how well described they are.
read/edit files
run commands
run tests
search / call API
🧵 State / feedback carried forward
The result of each action returns to the context, so the next pass is smarter than the previous one. It could be a tool result, a failed test, or a notes file that the agent rereads.
📊 For long tasks: state on disk
Anthropic’s research on long-running agents is explicit: a raw model in a loop isn’t enough. The agent needs externalize the state stop to commit + progress files and “leave the environment clean” for the next cycle to resume.
🎯 The goal (what “done” means)
A clear goal, written so the model knows when it's finished. “Make all the tests in the folder pass” is a goal. “Improve the code” isn’t.
✓ Verifiable goal
- ✓"Every test in /tests passes when you run npm test."
- ✓“Under 50 words AND mentions the price.”
- ✓“The build compiles without errors.”
✗ Vague goal
- ✗“Improve the code.”
- ✗“Make it good.”
- ✗“Clean this up.”
🧩 One of the few true invariants
Nearly every source—formal or practitioner—names an objective as the loop’s target: task complete, success criterion, evaluator returns PASS. Even the most radical version still says: "give it an objective, then loop on the objective."
✅ Verification (the step people skip)
Before continuing, the agent checks its own work against the objective: runs the tests, rereads the requirement, confirms the file changed. In Claude Code, the natural pattern is gather context → act → verify → repeat.
Read the diagram: verification is the gate. If it passes, it's "done." If not, the loop goes back to act — and that's what makes it converge instead of drift.
💡 “The most underrated step”
Anthropic's Agents SDK names "check your work" as a distinct step and calls it "the most underrated." It's what separates a loop that converges on a real result from one that confidently produces junk.
🛑 The stopping condition (you control the brakes)
Something that ends the loop. The cleanest option is completing the goal (tests pass). But also add a hard limit: a maximum number of rounds, or you watching and pressing CTRL+C. Don't assume the model always stops on its own.
🚨 Here, the sources disagree—that’s why you define the brake
Formal tools provide a hard cap on turns (max_turns). Grassroots loops like Ralph don't have stop condition on the model’s side, and they run until an operator kills them. An objective is invariant; a “stop” emitted by the model isn’t. So you’re the one who has to apply the brake.
# Checklist dos 6 elementos — cole no Claude Code e ele monta seu loop
Quero rodar uma tarefa em loop. Antes de começar, confirme comigo os 6 elementos:
1. Modelo: você (o agente) decide cada passo.
2. Ferramentas: pode usar <ex.: editar arquivos em /src, rodar `npm test`> — e NADA fora disso.
3. Estado: anote o progresso em PROGRESS.md a cada passo que melhorar.
4. Objetivo: <ex.: todos os testes em /tests passam>.
5. Verificação: como você vai checar <ex.: rodar `npm test` e ler a saída>.
6. Parada: pare quando o objetivo for cumprido OU após <ex.: 10> tentativas.
Repita os 6 de volta pra mim, então comece.
How to verify: the agent must repeat the 6 completed items before acting. If it skips the verification or the stop condition, your loop is still incomplete—reinforce it in the prompt.
🧾 Module Summary
Next:
1.3 — The field map: 11 schools