Quick Start
How It Works
The loop iterates with tools; after each iteration an independent judge reads the goal plus the latest output and returnsdone or continue.
The judge is strict about evidence:
Do NOT accept mere claims of completion (e.g. the word ‘done’) as evidence. Require concrete evidence that the goal is actually met.
Acceptance Criteria
GoalCriteria describes what “done” means, how to check it, and what must never happen.
| Field | Type | Default | Description |
|---|---|---|---|
outcome | str | "" | What “done” means in one line — the definition the judge anchors to |
verification | str | "" | The concrete evidence bar the judge requires before returning done |
constraints | List[str] | [] | Must-not-violate conditions; any violation forces continue |
run_goal() Options
| Option | Type | Default | Description |
|---|---|---|---|
task | str | — | The task/prompt the agent executes |
goal | str | — | The goal text the judge evaluates against |
criteria | Optional[GoalCriteria] | None | Structured acceptance criteria (recommended) |
max_turns | int | 20 | Judged iterations before a recoverable pause |
judge_model | Optional[str] | OPENAI_MODEL_NAME env or "gpt-4o-mini" | Independent judge model — use a different model from the actor to avoid self-enhancement bias |
resume | bool | True | Resume a persisted paused run for the same goal instead of restarting |
Completion Reasons
The loop returns anAutonomyResult whose completion_reason tells you why it stopped.
completion_reason | Meaning |
|---|---|
"goal_met" | Judge returned done with concrete evidence — success=True |
"budget_paused" | max_turns exhausted, or the judge returned 3 consecutive unparseable responses — success=False, run is recoverable via a second run_goal(..., resume=True) call |
| (other) | Falls back to the standard run_autonomous heuristics — see Autonomy |
The Independent Judge
The judge is deliberately simple, cheap, and safe to fail.Independent
Independent
Uses a separate judge model so the acting model never self-grades — this avoids self-enhancement bias.
Fail-open
Fail-open
A broken or timed-out judge yields
continue, so a weak judge never wedges progress.Cheap
Cheap
Only the goal plus the last ~4000 characters of agent output are judged, not the whole transcript.
Constraint-strict
Constraint-strict
Any constraint listed in
GoalCriteria.constraints blocks a done verdict.Auto-pause safety valve
Auto-pause safety valve
3 consecutive unparseable judge responses auto-pause the loop with
budget_paused, so a wedged judge cannot silently burn the whole budget.Async Variant
run_goal_async() mirrors run_goal() for async code.
run_until(goal=...) Delegation
Passing goal= to run_until() now delegates to run_goal() — the acceptance-criteria judge gates a real tool-iteration loop instead of re-generating a whole answer.
Best Practices
Use a different judge model
Use a different judge model
Set
judge_model to a different model than the actor so the run is not self-graded.Write verification as a checkable condition
Write verification as a checkable condition
Use concrete, checkable evidence (“exit code 0”, “PR URL exists”), not a feeling.
Keep max_turns low for first runs
Keep max_turns low for first runs
Start with
max_turns=10–20 and let resume=True continue a paused run when needed.Fill constraints with forbidden actions
Fill constraints with forbidden actions
constraints is the only field that can block a done verdict — list what must never happen.Related
Autonomy — the autonomous loop and its completion signals
Goal Engineering — specify and score a goal (the Goal Loop runs and gates toward one)
Evaluation Loop — the
run_until Ralph LoopSDK Reference — the underlying
run_autonomous loop
