Chapter 11·20 min

The Autonomous Loop

Let your AI iterate independently toward a measurable goal without constant supervision.

Last updated: March 2026

When to Go Autonomous

A persistent TypeScript build error had 6 possible root causes. I could have tested each one manually — 15 minutes per hypothesis, so 90 minutes of back-and-forth. Instead, I defined the success metric ('npm run build exits 0'), set the crash policy (3 strikes and escalate), and let the autonomous loop run. It found the fix on hypothesis 4 in 12 minutes while I made coffee.

For your business, autonomous loops are powerful for tasks where the success metric is clear and the work is safe to iterate on. The AI runs the loop while you focus on other things.

The Loop Structure (7 Steps)

  1. 1Read current state — What exists right now? What are the baselines?
  2. 2Form hypothesis — What change might improve the metric?
  3. 3Commit intent — Record what you are about to try (before running it).
  4. 4Execute — Make the change.
  5. 5Measure — Check the single objective metric.
  6. 6Keep or Discard — Did it improve? Keep. Same or worse? Revert.
  7. 7Repeat — Back to step 1 with updated context.
Autonomous Loop (Autoresearch Pattern)Read StateHypothesisCommitExecuteMeasureKeep / DiscardKEEPMetric improvedAdvance commitDISCARDMetric same/worsegit reset, try nextCRASH (3x)Escalate to humanSingle metricdrives decisionsNever retry the exact same thing twice — that is not persistence, it is insanity
Fig 11 — Autonomous iteration loop

The Three-File Separation

Every autonomous task has three layers. Keeping them separate prevents the AI from accidentally changing the rules of the game.

Three-File Separationtext
FROZEN (Human sets once, agent never touches):
  - Evaluation criteria
  - Test suites
  - Constraints and boundaries

MUTABLE (Agent iterates on this):
  - Implementation code
  - Content drafts
  - Configuration values

LEVER (Human adjusts to steer the agent):
  - Agent instructions
  - Strategy documents
  - Program parameters

The Single Objective Metric

Every autonomous loop MUST have exactly one success metric. Not two, not a weighted combination — one. This forces clarity.

Metric Examplestext
| Task Type               | Single Metric                          |
|------------------------|----------------------------------------|
| Bug fix                | Failing test now passes (yes/no)       |
| Build fix              | npm run build exits 0 (yes/no)         |
| Performance tuning     | Response time in ms (lower = better)   |
| Copy optimization      | Click-through rate (higher = better)   |
| Code simplification    | Lines of code (fewer = better)         |

Binary decisions only.
No "it seems better" — either the number improved or it did not.

Crash Policy

What happens when an iteration crashes? The crash policy prevents infinite failure loops.

Crash Policytext
Crash detected →
  Is it an obvious fix? (typo, missing import)
    YES → Fix and retry (max 2 quick fixes per crash)
    NO → Is this the 1st or 2nd crash on this hypothesis?
      1st → Abandon hypothesis, try next idea
      2nd → Flag pattern, try different approach
      3rd consecutive crash → STOP. Escalate to human.

Rule: Never retry the exact same thing twice.
That is not persistence — that is insanity.
The Never Stop Directive: In autonomous mode, the AI does not pause to ask 'should I continue?' The human might be asleep. It runs until: the metric is met, max iterations are reached, or the crash policy triggers escalation.

Autonomous loops use agents defined in Chapter 3: Building Your First Agents, are governed by rules from Chapter 4: The Rules System, and produce results that feed into the knowledge base (Chapter 7: The Knowledge Base). The enforcement system from Chapter 6 ensures agents stay within their boundaries even when running unsupervised.

Frequently Asked Questions

Related Chapters