Loop Engineering¶
Loop engineering designs, controls, and terminates the iterative loops agents run in, so they converge on the goal instead of spinning or burning budget.
The loop is the defining structure of agentic coding — tool loops, plan/act loops, verification loops, improvement flywheels, long-running autonomous loops. But coverage of how to engineer loops well is scattered. Loop engineering is the name for that cluster: the deliberate design of loops that terminate correctly and earn their cost.
It cuts across the site. The canonical treatment of each loop pattern still lives in its home discipline — agent design, workflows, verification, observability. This section owns the pages whose primary subject is the loop, and crosswalks the rest under one frame, built on the three-loops spine, so you can navigate "how do I design a loop that terminates correctly and earns its cost?" as a single topic.
What loop engineering is — and isn't¶
- It is the design discipline over the iterative structure: which loop type fits the work, how each turn is bounded, and when the loop stops.
- It is not all of agent design. Agent design covers composition, memory, delegation, and harness; loop engineering is the lens on the iteration specifically.
- It is not workflows. A workflow is a composed pipeline of agents and gates; loop engineering is about the loop inside a single agent's run (though improvement workflows are loops too — they crosswalk here).
- Termination and cost are the crux. Convergence detection, go/no-go gates, and runaway guardrails are what separate an engineered loop from a runaway — they are foregrounded below.
The crosswalk¶
The spine is the three-loops diagnostic — name the loop, then the symptom tells you the intervention.
- The Three Loops of Agentic Coding: A Diagnostic Vocabulary — tool, verification, and convergence loops; the vocabulary the rest of this section hangs on
- Loop Engineering: Stacking Outer Loops Around the Agent — the loopcraft / four-loop-stack framing: stacking verification, event-driven, and hill-climbing loops around the agent so the human stops being the throughput ceiling
Loop strategy and autonomy¶
How much context each iteration carries, and how much the loop runs on its own.
- Loop Strategy Spectrum: Accumulated vs Fresh Context — accumulated, compressed, or fresh context per iteration, chosen by workload
- The Ralph Wiggum Loop: Fresh-Context Iteration Pattern — each iteration runs in a fresh window, state persisted to disk
- Goal-Driven Autonomous Loop with Budget Cap — an objective-bound loop that stops on goal-done or budget exhaustion
- Long-Running Agents — making progress across many sessions by moving state into durable artifacts
- Agentless vs Autonomous — when a fixed pipeline beats a model-controlled loop
- Continuous Autonomous Task Loop — a self-directed loop that reads a backlog and executes each item
Loop structure and orchestration¶
The shape of a single iteration and what guarantees run inside it.
- Agent Loop Middleware — Safety Nets and Message Injection — wrap the loop from outside so critical steps always run
- CoALA Decision-Making Loop — propose/evaluate/select/act as a vocabulary for where tactics intervene
- ReAct Pattern — interleave thought, tool call, and observation each step
- Plan-First Loop — design a written plan before code, then loop on it
Termination, convergence, and cost gates¶
The crux — what stops a loop and what justifies running one at all.
- Convergence Detection in Iterative Agent Refinement — mechanical stopping criteria from change velocity, output size, and similarity
- Agent Loop Go/No-Go: When Looping Earns Its Cost — the four-condition gate before you build a loop at all
- Loop Budgeting: Allocating Iteration and Token Budget Across Turns — pick the budget primitive (iteration / token / wall-clock) and choose front-loaded vs even-split per-turn allocation
Runaway guardrails¶
Detecting and breaking loops that spin without converging.
- Loop Detection — catch repetition and stuck states before they burn budget
- Stuck-Loop Recovery: Detecting and Escaping Non-Converging Agent Loops — the recovery playbook once detection fires: nudge, replan, escalate, reset, hand off, abort
- Observability Feedback Loop — close the loop from telemetry back into agent behavior
Improvement and flywheel loops¶
Loops that make future agent work better, not just finish the current task.
- Agentic Flywheel — agents analyze their own operational data and generate harness improvements
- Self-Reporting Loops — out-of-scope observations filed so signal survives the session
- Continuous Agent Improvement — a standing loop that upgrades the agent setup over time
- Closed-Loop Agent Training — feed run outcomes back into training
- Skill Library Refinement Loops — iteratively refine a skill library from usage
- Humans and Agents Development Loops — interleave human and agent turns as one loop
Review loops¶
Iterative review as a loop structure.
- Agent Self-Review Loop — the agent critiques and revises its own output
- Review-Then-Implement Loop — review before implementing, then iterate
- Human-in-the-Loop — workflow-boundary HITL: where to place approval gates around an agent pipeline
- Human-in-the-Loop Checkpoints as Loop Control — the loop-internal counterpart: HITL as a four-verb suspend that bounds or redirects the iteration
- Failure-Driven Iteration — let failures drive the next iteration
Related¶
- Concept Map — all site content grouped by theme
- Agent Design — the canonical home for loop patterns
- Workflows — composed pipelines that wrap these loops
- Verification — the verification loop's home discipline