Loop Engineering
Loop engineering: designing the observe-plan-act-check-repeat cycle an AI agent runs.

How AI Agents Work in the Background: Loop Engineering, Explained
The problem
You ask an AI coding assistant to fix a bug. Two minutes later, it has read six files, edited one, run a test, seen the test fail, re-read the test, edited the file again, re-run the test, and only then pinged you back with a green check. You didn’t see any of that — you just saw the result. Meanwhile, a customer-support agent on a different team is doing almost the same thing: open the ticket, search the knowledge base, draft a reply, check whether the policy allows that reply, send it, wait for the user’s reaction, and try again if the customer pushes back. Both of these agents are running the same underlying pattern. That pattern has a name. It’s called a loop, and designing it well is the new job.
What it is
A loop is the repeated cycle a single AI agent runs until its task is done. Concretely: it observes what’s in front of it (files, ticket history, a screen), plans what to do next, acts (edit a file, send a reply, click a button), checks whether the result actually solved the problem, and repeats if it didn’t. Loop engineering is the discipline of designing that cycle deliberately — the trigger, the guardrails, the verifier, and especially the stop condition — rather than improvising each prompt by hand.
The idea isn’t new. The academic seed is the 2022 ReAct paper, which taught language models to interleave reasoning with actions. In 2023, Reflexion added a self-critique step inside the loop so the agent literally tells itself what went wrong before retrying. By 2024, Anthropic’s own production guidance was calling agents “typically just LLMs using tools based on environmental feedback in a loop” — which is when the pattern stopped being research and became plumbing. In August 2026, the term “loop engineering” was crystallized by Peter Steinberger, the creator of OpenClaus, who put it bluntly: “You shouldn’t be prompting coding agents anymore. You should be designing loops that prompt your agents.”
How it works
Every well-designed loop has the same six moving parts. Skip any of them and you get a runaway or a frozen agent.
- Observe. Read current state — file contents, API responses, prior messages, a screenshot. Just enough. Re-reading the entire world every turn burns through the model’s finite “attention budget,” the limited working memory it has for parsing context (Anthropic, 2025).
- Plan. Decide what to do next. Useful only when the next move isn’t obvious from the current state. If you can write the plan as a fixed script, do that instead — a workflow is cheaper than an agent.
- Act. Invoke a tool — edit a file, run a command, call an API. Tool definitions deserve the same care as prompts. Anthropic’s own engineering team spent more time tuning tool schemas than the underlying prompt for their SWE-bench agent.
- Check. Evaluate the result against a success criterion: did the test pass, did the API return 200, does the file contain the expected string? Vague checks like “does this look right?” collapse into vibes-based termination.
- Repeat. Cycle back to Observe with updated state. The agent now knows what just happened, so its next plan is informed by reality, not by the original guess.
- Stop conditions. The contract that tells the loop “you’re done.” Two flavors: a measurable success signal (tests green, file matches) and a budget limit (max iterations, max tokens, max wall-clock, max cost). A loop without a stop condition is a runaway, not an agent.
The 2025 LangGraph documentation is blunt about why this matters in production: loops need persistence, memory, and human-in-the-loop hooks as first-class features, not afterthoughts. If you can’t replay and audit every iteration, you can’t debug the agent.
Where it works
Loops are quietly running in places most non-engineers already use.
- Coding agents that ship pull requests. Claude Code, Cursor, Codex, and similar tools are productized loops: read the repo, propose a diff, run the test suite, fix what’s red, repeat. The whole product is one giant check-and-retry cycle.
- Customer-support resolution. A support agent loops until the user’s problem is actually resolved — or until an escalation threshold trips. The measurable condition is “did the customer confirm their issue is fixed,” not “did an agent send a message.”
- Test-driven repair and refactoring. “Make the test suite pass” is a literal loop predicate. It’s the cheapest verifiable finish line in software, which is why almost every coding agent leans on it.
- Long-horizon research and synthesis. Multi-step web search where each retrieval informs the next query, capped by a final verifier that scores completeness against the original question.
- Data-pipeline and ETL repair. Detect schema drift, rewrite the query, run it, validate the row count, repeat until the count matches. The data warehouse is the verifier.
Where it breaks
Loops are not a universal hammer. Here are the failure modes that show up most often, and the one-line fix for each.
- No measurable finish line. “Make this blog post better” isn’t a loop predicate. The agent will thrash, rewrite, rewrite again, and exit on the budget cap instead of on quality. Fix: write the success criterion down before you start, in a sentence a machine could check.
- Irreversible side effects. Pushing to production, emailing a real customer, dropping a database. A loop’s compound errors bite hard here — one bad iteration poisons the next. Fix: require human approval before any irreversible action, and stage changes in a reversible environment.
- Highly branched, multi-specialty work. When you need parallel specialists with different tools and explicit routing between them, a single loop is the wrong shape — that’s graph territory, where multiple loops connect. Fix: treat each branch as its own loop and connect them with an orchestrator.
- Latency-sensitive interactions. Loops add round-trips; each iteration costs time. Under 200 milliseconds, the user is gone before the second turn. Fix: reserve loops for asynchronous or batch work; answer synchronously with a single LLM call or a fixed workflow.
- Long memory across sessions. A single loop is bounded by its context window. Cross-session memory lives outside the loop. Fix: add a real memory layer (a vector store, a structured notes file) and have the loop read from it at the Observe step.
The 2023 Reflexion paper hints at why these failures cluster: agents that verbally reflect on failure can self-correct, but only when the feedback signal is real. “Looks fine to me” is not a feedback signal — a passing test, a parsed schema, a returned status code, is.
What this article does NOT cover
- How to actually wire a loop in code (LangGraph, CrewAI, or raw tool-use APIs).
- Multi-agent graphs where multiple loops are orchestrated together.
- Cost-tuning and token-budget optimization across long-running loops.
- The safety and alignment debate around autonomous agents running with minimal human oversight.
Sources
- Building effective agents — Anthropic
- Effective context engineering for AI agents — Anthropic
- ReAct: Synergizing Reasoning and Acting in Language Models — Yao et al., arXiv 2210.03629 (2022)
- Reflexion: Language Agents with Verbal Reinforcement Learning — Shinn et al., arXiv 2303.11366 (2023)
- LangGraph overview — LangChain docs
- AI Daily Brief — “What the Heck is Graph Engineering?” (2026-08-10)
Sources
- Building effective agents — Anthropic
- Effective context engineering for AI agents — Anthropic
- ReAct: Synergizing Reasoning and Acting in Language Models — Yao et al., arXiv 2210.03629 (2022)
- Reflexion: Language Agents with Verbal Reinforcement Learning — Shinn et al., arXiv 2303.11366 (2023)
- LangGraph overview — LangChain docs
- AI Daily Brief — What the Heck is Graph Engineering? (2026-08-10)



Submit a take
Have a different read on this? Drop a comment below — your email isn't published, and I read every one. Nothing leaves the site until I approve it.