Skip to Content
loop.fun
Foundations

The four layers

"Agentic loop" names at least four nested things. Most disagreements are people talking about different layers.

When someone says "I run my agents in loops", they could mean any of four different things, and the layers nest inside one another:

4Meta-loops & graphs

Loops that start, check and restart other loops: planner → generator → evaluator, agent teams, kanban boards of goals.

3Scheduled & ambient loops

Something wakes the agent: a timer, a cron line, a heartbeat, a webhook. /loop, routines, HEARTBEAT.md.

2Goal loop

Re-prompt across turns until a completion condition holds. The Ralph loop, /goal.

1Inner tool loop

Model → tool call → observation → model … until the model answers. Every agent has this.

Each layer wraps the one inside it. Most arguments about "agentic loops" are two people talking about different layers.

Layer 1 · The inner tool loop

This is the loop inside every agent: the model emits a tool call, the harness executes it, the result goes back into the context, and the model continues until it produces a final answer instead of another tool call.

It is a solved, standard part of every agent. OpenAI's Unrolling the Codex agent loop is the most detailed public description of one: how the harness assembles the prompt on each pass, uses prompt caching, and manages the context window. Anthropic's Claude Agent SDK post describes the same thing for Claude Code.

What ends it: the model decides it has answered. That's one model turn, from the user's point of view.

Layer 2 · The goal loop

This is what most of the 2026 conversation is about. The goal loop wraps the inner loop and refuses to let the turn end until some condition holds. When the agent tries to stop, something checks whether the goal is met; if not, the agent is sent back to work.

What ends it: a completion check (often a separate judge model), a budget, or a human. This layer is where goals come in, and they get their own section.

Layer 3 · The scheduled or ambient loop

Here the loop isn't driven by "not done yet" but by time or events. Something wakes the agent up: a timer, a cron line, a webhook, a new email. The agent does a round of work and goes back to sleep.

  • Claude Code's /loop repeats a prompt on an interval (an often-cited example is /loop 5m /babysit for PR babysitting, per this unofficial catalogue). Routines and scheduled tasks run on a calendar (MindStudio comparison).
  • OpenClaw's heartbeat wakes the agent every 30 minutes by default to read a checklist file called HEARTBEAT.md (guide).
  • Antigravity has /schedule. Hermes has cron.

This layer is what makes agents feel always on. Claire Vo's line about OpenClaw: it "has a heartbeat but not a brain" (X).

What ends it: usually nothing. It's a standing process. See Ambient loops and Standing goals.

Layer 4 · Meta-loops and graphs

At the top are loops that orchestrate other loops: a planner that writes a spec, a generator that implements it, an evaluator that tests it and sends it back. Or a team of agents sharing a task list. Or a kanban board where each card is its own goal loop.

What ends it: an orchestrator's own stop logic, which itself is a goal loop one level up.

Why the distinction matters

If someone says…They're probably talking aboutThe hard problem at that layer
"Agents are just a while loop with an LLM"Layer 1Context assembly, caching, tool design
"I let it run overnight until the tests pass"Layer 2Writing a goal that can be checked and can't be gamed
"My agent checks my inbox every morning"Layer 3Silence criteria, cost of idle wake-ups, standing goals going stale
"Loops are dead, graphs are the future"Layer 4Coordination, handoffs, shared state

A cost complaint about Layer 2 (a goal loop re-reading 400k tokens on every continuation) is a different problem from a cost complaint about Layer 3 (a heartbeat waking up 48 times a day to say "nothing to report"). Both get called "loops burn tokens". See Cost.

Andrew Ng's version adds two layers outside the machine

Ng's three-loop model puts the agentic coding loop (minutes) inside a developer feedback loop (hours) inside an external market/user feedback loop (days). Those outer two are human loops, and they set the pace for everything inside them.

loop.fun

Patterns, hints and tools for designing the loops that keep agents working, and for widening the set of loops you can think of.

© 2026 loop.fun · CC BY 4.0

On this page