# I was building loops wrong...

## Executive summary

The video details the architecture and implementation of 'loops'—autonomous AI systems designed for continuous development and operations. These loops move beyond simple agent prompting by establishing a structured system where an agent can independently decide on work, execute tasks, verify results, and self-improve over time. The core structure involves defining a Loop Contract (Goal, Boundaries, SOP), maintaining State/Logs, utilizing specific Trigger mechanisms, and employing multi-role agents with mandatory verification steps.

## Key takeaways

- The Anatomy of an AI Loop: Every internal loop is structured around a markdown file containing the 'Loop Contract' (Goal, Boundaries, SOP), 'State' (current hypothesis/backlogs), and 'Logs' (append-only record). This serves as the living documentation for the system.
- Advanced Trigger Mechanisms: Beyond standard continuous (`while` loop) or cron job triggers, effective loops often use 'Event-based' (reactive to external events like new emails/incidents) or 'Combo/Workflow' triggers. The latter is highly efficient as it programmatically checks data sources (e.g., Intercom updates) before waking the agent, preventing unnecessary runs.
- The Evolve Loop Concept: Loops are designed to improve themselves. An 'Evolve Loop' is a dedicated session where the AI analyzes its own past run state, logs, and configuration to suggest improvements—such as optimizing triggers or refining the SOP—making the system self-optimizing.

## Technical details

- Loop Contract Components: The contract defines three critical elements: 1) The Goal (what success looks like), 2) Boundaries (what the agent can do autonomously vs. what requires human escalation), and 3) Standard Operating Procedures (SOPs).
- Agent Architecture for High-Stakes Tasks: For complex tasks, the agent structure is broken down into roles: an Orchestrator (planning/research), multiple Sponsor Agents (isolated work trees for parallel execution), Executors, and a Verifier. The Verifier is crucial for quality assurance, testing results, and attaching evidence to PRs.
- Verification Systems: To ensure high-quality output, the process requires verification. Tools like Playwright or CRI are used to allow agents to test work and record video/image evidence, while remote sandboxes (e.g., Crabbox) prevent local resource limitations.
- Example: React Doctor Loop: A practical example is the 'react-doctor' loop, which runs an open-source CRI tool on the codebase daily. The loop identifies critical issues and automatically attempts to fix the most severe one, following defined boundaries and verification processes.

## Practical implications

- Implement structured documentation (Loop Contract) to govern agent behavior, clearly separating autonomous actions from human review points.
- Adopt 'Combo' or workflow triggers instead of simple cron jobs for cost and token efficiency by batching work and only triggering the agent when real tasks are available.
- Mandate a multi-stage agent process (Orchestrator -> Sponsor -> Executor -> Verifier) to ensure high-stakes code changes include verifiable evidence and testing.
- Use 'Evolve Loops' periodically to allow the AI itself to optimize the loop's configuration, SOPs, and triggers.

## Topics

Autonomous Agents, AI Workflow Design, Continuous Integration (CI), System Architecture, LLM Automation, Loopany platform, Skill for setup verifier, Superdesign platform

Source: https://www.youtube.com/watch?v=JQ_We_ztxrI
