What is an agentic loop?
The smallest possible definition, why it's deceptively simple, and the four concepts it has to be kept apart from.
The smallest possible loop
Strip away the products and the vocabulary and an agentic loop is this:
while :; do cat PROMPT.md | claude -p; doneThat's the Ralph loop, credited to Geoffrey Huntley in July 2025. It runs an agent, waits for it to finish, and runs it again with the same prompt, forever. Each pass starts with a fresh context window, but the workspace (files, git history, test output) still holds the evidence of every earlier attempt. The agent "remembers" by reading what it left behind (geocod.io, Sid Bharath).
It sounds too dumb to work, and for many tasks it isn't dumb at all. That gap between how simple the mechanism looks and how much it gets done is why loops became a topic in 2026.
The general shape
Every agentic loop, from the bash one-liner to a multi-agent research system, has the same skeleton:
- Observe. Gather context: files, tool output, the task, the state left by previous iterations.
- Decide. The model chooses what to do next.
- Act. Execute it: run a command, edit a file, call an API, spawn a sub-agent.
- Check. Look at what happened. Did it work? Are we done?
- Repeat or stop. Something decides whether another iteration is needed.
Anthropic describes Claude Code's core loop as gather context → take action → verify work → repeat. OpenAI's Unrolling the Codex agent loop walks through the same cycle inside Codex, focusing on how context is built and cached on each pass. Oracle's explainer puts it plainly: the core architecture is stable, and the work now is in context management, coordinating many loops and auditing decisions.
Why "just a while loop" is both true and misleading
Critics on Hacker News and in the tech press (summarized here) are right that the mechanism is trivial. They are wrong if they conclude that the design is trivial. The while is easy. The hard parts are:
- The exit condition. How does the loop know it's done? If the answer is "the model says so", the model will sometimes say so too early, or never.
- The budget. What stops a loop that will never succeed from running all weekend?
- The state. What survives between iterations, so iteration 40 doesn't repeat iteration 12's mistake?
- The trigger. What starts the loop: a person, a timer, a webhook, another loop?
- The blast radius. What is the agent allowed to touch while nobody is watching?
As one widely shared X post put it: "the loop is the easy part. The work is the context and the stop condition: the check that ends it, the budget that caps it."
Four concepts to keep apart
Much confusion in discussions about loops comes from four distinct ideas being used interchangeably. This guide keeps them apart:
- Agentic loop
- The execution mechanism: observe, decide, act, check, repeat. It says how work proceeds, not what the work is for.
- Goal
- The persistent objective, ideally with acceptance criteria, that survives individual turns and decides when the loop may stop. See the Goals section.
- Harness
- The runtime around the model that makes the loop useful and safe: tools, permissions, sandbox, budgets, hooks, scheduling, compaction.
- State and memory
- What survives an iteration, a context reset or a crash. State is what is happening now (iteration count, subgoals done). Memory is what should be kept for later (failed approaches, preferences).
The split between state and memory comes from a useful framing in a parallel analysis of the topic, and lines up with how Anthropic's long-running harness separates a progress file (state) from git history and feature lists (durable artifacts).
Loop vs. workflow vs. agent
Two neighbouring terms are worth separating:
- A workflow is a fixed sequence of steps defined in advance. The path is designed by a human; the model fills in the steps.
- An agent chooses its own path at runtime, usually inside a tool-calling loop.
- A loop in the 2026 sense is what you wrap around an agent: a structure that re-invokes it, checks it and decides whether to keep going. Andrew Ng and Addy Osmani both describe "loop engineering" as designing the system that prompts the agent, rather than prompting it yourself.
A useful mental shift
The old question was "how do I make the model do another iteration?" The new question is "how do I make an autonomous process do the right iterations, keep its progress, know when it has succeeded, and stop when continuing isn't worth it?"
Where to go next
- The four layers: the inner loop, goal loop, scheduled loop and meta-loop, and why mixing them up causes arguments.
- Anatomy of a loop: the building blocks every well-designed loop has.
- The Ralph loop: a closer look at the one-liner that started it.