Autonomous Loops & Supervisors

The defining characteristic of an autonomous agent is its ability to run in an unattended loop: receiving a high-level goal, decomposing it into subtasks, executing changes, verifying results, and iterating until the objective is accomplished.

However, unbounded autonomous loops introduce critical engineering hazards: infinite cycling, runaway token expenditure, and drift from the original specification.

If you ask an autonomous agent to build a multi-page app without supervision, it's like leaving an over-enthusiastic junior developer alone in the office for a weekend: they might rewrite the entire database, install 30 unnecessary libraries, get stuck in an endless loop trying to center a button, and spend $500 in cloud credits.

The Supervisor Harness provides the guardrails: it limits the number of attempts, stops the agent when it loops in circles, and assigns an independent "Checker" agent to approve every pull request.


1. Goal Loops vs Single-Turn Q&A

A conventional assistant operates in a Single-Turn Request/Response mode: the human must evaluate every step and manually prompt the next action.

An Autonomous Goal Loop delegates the execution loop to the harness:

                      ┌───────────────────────────┐
                      │    User Dispatches Goal   │
                      │  "Implement feature X"    │
                      └─────────────┬─────────────┘
                                    │
                                    ▼
                      ┌───────────────────────────┐
                ┌────►│   Harness Evaluates Loop  │◄───┐
                │     │   Iteration & Budget Cap  │    │
                │     └─────────────┬─────────────┘    │
                │                   │                  │
                │                   ▼                  │
                │     ┌───────────────────────────┐    │
                │     │   Worker Agent Executes   │    │
                │     │      Subtask In Focus     │    │
                │     └─────────────┬─────────────┘    │
                │                   │                  │
                │                   ▼                  │
                │     ┌───────────────────────────┐    │
                │     │   Supervisor / Verifier   │    │
                │     │    Audits Changed Code    │    │
                │     └─────────────┬─────────────┘    │
                │                   │                  │
           Pass │                   ▼                  │ Fail
         Check  │            All Invariants            │ (Inject
                │               Passed?                │ Diagnostic)
                │              /       \               │
                │          Yes/         \No            │
                │            /           \             │
                │           ▼             ▼            │
                │     ┌───────────┐ ┌─────────────┐    │
                │     │ Check Off │ │ Cycle Check │────┘
                │     │ Subtask   │ │ & Fix Turn  │
                │     └─────┬─────┘ └─────────────┘
                │           │
                │     More  │
                │    Tasks? │
                └───────────┤
                            │ All Done
                            ▼
                      ┌───────────────────────────┐
                      │ Final Integration Pass &  │
                      │ Complete User Notification│
                      └───────────────────────────┘
Predict First
If an autonomous coding loop gets stuck in an oscillating ping-pong loop (editing File A breaks File B, editing File B breaks File A), what will happen if you only enforce a step cap (e.g. max 30 turns) without cycle detection?

2. Cycle Detection & Circuit Breakers in Python

To prevent infinite oscillation, the harness hashes workspace diffs and error outputs after each turn. If the identical state hash repeats, a Circuit Breaker halts the loop.

Run this live in-browser Python implementation to see how the cycle detector detects an oscillating agent:

Run it yourself
import hashlib
from typing import List, Dict

class CycleDetector:
def __init__(self, repeat_threshold: int = 2):
self.history: List[str] = []
self.threshold = repeat_threshold

def record_and_check(self, edited_file: str, diff_text: str, error_msg: str) -> bool:
# Generate deterministic fingerprint of turn state
payload = f"{edited_file}:{diff_text}:{error_msg}"
turn_hash = hashlib.sha256(payload.encode()).hexdigest()[:8]
self.history.append(turn_hash)
occurrences = self.history.count(turn_hash)
print(f"Turn {len(self.history)}: State Hash=[{turn_hash}] (Observed {occurrences} time(s))")
if occurrences >= self.threshold:
print(" >>> CIRCUIT BREAKER TRIGGERED: Agent is oscillating in an infinite loop! <<<")
return True # Tripped!
return False

detector = CycleDetector(repeat_threshold=2)

# Simulated Agent Turns (Ping-Pong oscillation between router.py and handler.py)
simulated_turns = [
{"file": "router.py", "diff": "import handler", "err": "ImportError: cannot import name 'router' from partially initialized module"},
{"file": "handler.py", "diff": "import router", "err": "ImportError: cannot import name 'handler' from partially initialized module"},
{"file": "router.py", "diff": "import handler", "err": "ImportError: cannot import name 'router' from partially initialized module"}, # Repeated!
]

for t in simulated_turns:
tripped = detector.record_and_check(t["file"], t["diff"], t["err"])
if tripped:
print("Harness Action: Halting loop, injecting architectural refactor prompt into agent context.\n")
break


3. Anthropic's Multi-Agent Triad (Planner-Generator-Evaluator)

When a single model acts as both author and auditor of its own code, confirmation bias leads to blindness: the model believes its code is correct because it wrote it.

Anthropic's long-running agent research formalizes the Supervisor Triad:

Multi-Agent Supervisor Protocol
Anthropic Triad: Planner → Generator → Evaluator
1. Planner AgentACTIVE
Owns global decomposition, budget tracking, and atomic step definitions.
2. Generator Agent
Writes pure code and test edits. Operates strictly inside the isolated sandbox.
3. Evaluator Agent
Deterministic referee. Runs pytest, verifies invariants, signs off on commits.
Step 1: Planner ScopingStep 1 of 5

Planner ingests the user request, inspects repository state, and writes an atomic work order to feature_list.json.

TASK_DISPATCH: Implement exponential backoff in retry_policy.py (tests/test_retry.py required)
External State Artifact: feature_list.json
⏳Feature: Add exponential backoff algorithm with max jitter cap
◻Feature: Add Redis distributed lock provider
◻Feature: Telemetry Prometheus metrics exporter
Anthropic's long-running agent architecture separates concerns into specialized agents. The Generator never marks its own work as complete; only the independent Evaluator can sign off on verification and state externalization.

4. OpenAI's Pattern: Background Entropy & Garbage Collection Agents

In OpenAI's 1-million-line production Codex experiment, a critical finding emerged: autonomous agents write code faster than human teams, but they also accumulate subtle technical debt (stale comments, duplicate utility functions, dead imports).

To solve this, the harness runs automated Entropy Collection Agents asynchronously:

OpenAI Codex 1M LoC Findings
Continuous Codebase Entropy & Sweeper Agent
Codebase Entropy & Technical Debt Level:35% (Clean & Stable)
AST Structural Tests
0 Violations
Guarantees architectural boundaries and disallowed imports.
Dead Code & Unused Imports
14 Warnings
Automated AST sweepers eliminate unused symbols without human triage.
Pytest Execution Velocity
0.6s (Optimized)
Fast test feedback keeps autonomous agent self-correction under 15 seconds.
Ryan Lopopolo's 1M LoC OpenAI study demonstrated that autonomous coding agents generate rapid architectural entropy: orphaned helpers, duplicate logic, and loose types. A dedicated background entropy agent continuously scans and cleans the codebase, keeping test runs fast and hallucinations low.

Running entropy passes continuously prevents autonomous codebases from decaying into "AI slop."


5. Empirical Performance Across Tasks

The ablation studio below shows how closing the loop with automated supervision and halting controls transforms reliability across diverse task categories:

Benchmark Scenario
Same Foundation Model, Different Harness Architecture
Zero-Shot
Prompt-Only LLM
Task Completion14%
Premature Victory82%
Codebase Regression42%
Produces plausible architecture doc but builds 0 functional integrations.
Unverified Loop
Basic ReAct Agent
Task Completion42%
Premature Victory49%
Codebase Regression29%
Suffers context rot after turn 9; re-implements already existing helper functions.
Closed-Loop Cybernetic
Full Production Harness
Task Completion93%
Premature Victory0%
Codebase Regression2%
feature_list.json tracks completed subtasks; memory compactor keeps token budget sharp.
Empirical Ablation: Testing the identical frontier LLM across 3 harness configurations. The model reasoning engine is held constant -- all performance gains in task completion and safety come entirely from the engineering of the surrounding harness.

Supervisor Golden Rule

An agent should never judge its own work. Always enforce the Maker-Checker separation: the Generator proposes patches inside the sandbox, while an independent Evaluator verifies deterministic proofs and signs off on git commits.

Track Complete

You have mastered the foundational pillars of Harness Engineering. Return to the Harness Engineering Roadmap or dive into building your own sandboxed agent loop.

Last updated Oct 29, 2026Edit this pageReport an issue