# Inner Loop / Middle Loop / Outer Loop: The Three Closed Loops of Agent Work
Agent work isn't linear β it splits into three nested closed loops: the inner loop (code-test), the middle loop (task-review), and the outer loop (metrics-improvement). Understanding this model is foundational to designing AI4SE processes.
The Three-Loop Model
Outer Loop (weeks/months): Measure β Improve Rules/Process/Methods
βββ Middle Loop (hours): Plan β Execute β Review
βββ Inner Loop (seconds/minutes): Code β Test β Fix
Key Activities per Loop
| Loop | Cadence | Driven by | Output |
|---|---|---|---|
| Inner | Seconds to minutes | Agent | Code + tests + immediate fixes |
| Middle | Hours to days | Human + Agent | Completed tasks + passing review |
| Outer | Weeks to months | Human-led | Metrics β updated Rules / Spec / Harness |
Why the Three Loops Matter
- Different loops need different metrics
- Inner optimizes for speed, Middle optimizes for quality, Outer optimizes for the system
- Optimizing only the Inner loop = a local-optimum trap
In Practice
- Inner: leave it to the Agent, intervene minimally
- Middle: place gates at Review and Plan
- Outer: check metrics periodically, adjust global constraints