Mastering Loop Engineering
An agent is "an LLM running tools in a loop." This site covers the engineering of that loop itself, designing, controlling, verifying, and evolving it, across 12 sections and 62 chapters.
Who this is for
Section titled “Who this is for”- Developers who have built an agent — ran ReAct once but want to systematically understand why loops spin forever and when to stop them
- Engineers operating production agents — tackling cost blow-ups, context collapse, and reliability from a loop-design perspective
- AI system designers and researchers — going beyond single-shot prompting into the principles and limits of autonomous loops, multi-agent systems, and self-improving loops
What you will learn
Section titled “What you will learn”Click any card to jump to that section’s first chapter. The curriculum runs beginner (01–02) → intermediate (03–08) → advanced (09–11) → hands-on (12).
01. What Is Loop EngineeringLimits of single-shot prompting, the definition of an agent, workflow vs agent, the prompt→context→loop lineage, history
02. Anatomy of a LoopThe observe-reason-act-evaluate cycle, CoT, tool use/ACI, structured output, a 50-line minimal loop
03. Single-Agent Loop PatternsReAct, Reflexion, Plan-and-Execute, Self-Refine, Tree/Graph of Thoughts, ReWOO/LLMCompiler
04. Workflow PatternsPrompt chaining, routing, parallelization, orchestrator-workers, evaluator-optimizer
05. Context Engineering in the LoopAttention budget and context rot, lost in the middle, compaction, loop memory, JIT/fresh context
06. Loop Control and TerminationTaxonomy of stopping conditions, the generator-verifier gap, LLM-as-judge, test-driven loops, human-in-the-loop
07. Failure Modes and ReliabilityInfinite/doom loops, error cascades and goal drift, checkpointing/idempotency, retries/crash-only, sandboxing
08. Security and Adversarial LoopsPrompt injection and context poisoning, reward hacking, pre-action authorization, bounded autonomy and audit
09. Observability, Evaluation, EconomicsOpenTelemetry gen_ai tracing, trajectory evaluation, reproducible evaluation harnesses, SWE-bench, per-iteration economics
10. Multi-Agent and Long-Horizon LoopsOrchestrator-worker, handoff vs dispatch, A2A and Agent Skills, METR time horizons and error compounding
11. Self-Improving Loops and the RL FrontierThe loop as an MDP, DSPy, AlphaEvolve, Darwin Gödel Machine, GRPO/DeepSeek-R1
12. Hands-On: Building and Operating LoopsClaude Code/Codex case studies, SWE-agent, the Ralph technique, spec-driven design, pattern selection, the Software 3.0 future
Content principles
Section titled “Content principles”- Cite only verifiable primary sources — arXiv, official engineering blogs (Anthropic, OpenAI, DeepMind), NeurIPS/ICLR/ICML proceedings, respected practitioner blogs. No unsourced statistics.
- Compare alternatives in tables — trade-off-heavy topics like ReAct vs Reflexion vs Plan-Execute are laid out as tables.
- Every chapter has a visual — at least one ASCII diagram, comparison table, or Mermaid graph to make the loop structure visible.
- Code examples are Python-first — conceptual pseudocode; vendor-specific package names may differ from reality and are flagged as such.