ClosedLoop.ai
Concepts

Loop until correct

Why ClosedLoop.ai retries bounded phases with promises and validation instead of accepting one-shot outputs.

Most agent systems take a single output and hope it is correct. ClosedLoop.ai does not.

Each phase in a loop is a promise (a specific exit condition) plus a validation (a deterministic check) plus a budget (a max iteration count).

How it works

An agent starts a phase, does work, and emits a promise token at the end:

<promise>PLAN_VALIDATED</promise>

A SubagentStop hook (loop-stop-hook.sh) reads the state file, checks the promise token against the configured validation script, and either:

  • lets the agent exit successfully, or
  • blocks the exit with an error message, increments the iteration counter, and forces the agent to retry.

Configured loop agents

The loop agents in plugins/code/scripts/loop-agents.json:

AgentMax iterationsPromise
code:plan-draft-writer10PLAN_VALIDATED
code:plan-writer5PLAN_WRITER_COMPLETE
code:plan-validator5PLAN_VALIDATION_COMPLETE
code:implementation-subagent4IMPLEMENTATION_VERIFIED
code:code-reviewer5CODE_REVIEW_PASSED

If an agent cannot satisfy the promise within its budget, it returns control with an explicit failure the orchestrator can surface.

Why bounded retries beat one-shot

Unbounded retries make agents spiral. Zero retries make agents flaky. A small, named budget lets the system be both reliable and fast:

  • Most agents converge in one or two iterations.
  • A deterministic gate means "almost right" still fails, so agents stop producing plausible-looking but broken output.
  • The budget caps the worst case so the loop cannot run forever.

Why this pairs with judgment

Loop-until-correct gets the output to pass a deterministic gate. Judges grade whether the output actually matches the spec. You need both: the first catches structural errors, the second catches semantic drift.

See Judges for how scoring works.

On this page