Skip to main content
Ralph Loop runs a verifier-first goal loop inside the normal agent middleware pipeline. It keeps the agent working across bounded continuation turns until the model signals that it is ready to finish and trusted verifier evidence agrees. The middleware provider name is ralph-loop.

Core Idea

Ralph Loop is no longer just “retry until <promise>DONE</promise>”. The completion marker is treated as a finalization intent, not proof that the task is complete. By default, completion is accepted only when both conditions are true:
  • The latest AI answer includes <promise>DONE</promise>.
  • The latest trusted verifier evidence has passed.
If the model claims completion without passing verifier evidence, Ralph Loop rejects the completion, creates a compact continuation prompt, clears the message history for that channel, and routes the run back to the model.

Goal Slash Command

When an agent is connected to Ralph Loop, the middleware exposes a runtime slash command:
The command is declared by RalphLoopMiddleware.meta.slashCommands. The runtime command is sent to the composer as an insert_invocation command, so the UI inserts /goal ... rather than expanding the full prompt template on the client. The default /goal template asks the agent to follow:
It also tells the agent to use the strongest applicable verifier before finalizing. If UI screens or visual parity are part of the goal, the template explicitly asks the agent to use Playwright Interactive to inspect and compare the result.

Completion Marker

Ralph Loop still uses this marker:
The marker means “the model believes the goal is ready to finalize”. It does not bypass verification. When completion is accepted, the middleware removes the marker from the visible answer.

Verifier Evidence

Ralph Loop collects recent ToolMessages from configured verifier tools. The default trusted verifier tool list is:
The middleware matches verifier output back to the originating AI tool call and records:
  • tool name
  • tool call id
  • command, when available
  • status, either pass or fail
  • output content
  • observed timestamp
Verifier evidence is recorded as failed when the tool output indicates a nonzero exit, timeout, or tool error. Otherwise, it is recorded as passing evidence. Ralph Loop does not execute verifier tools directly from the middleware hook. The model must call tools through the normal tool pipeline, so streaming, HITL, tool limits, and tool retry middleware still apply.

How It Works

The continuation prompt carries:
  • original objective
  • current iteration
  • compact runtime summary
  • last verifier evidence
  • continuation reason
  • expected next behavior
It tells the agent to continue with Plan -> Act -> Verify -> Reflect -> Retry, fix failed verification, run a verifier when evidence is missing, and only then finalize with the completion marker. If the original human message contained structured content parts, Ralph Loop preserves them behind the continuation prompt.

Configuration

Example:

Runtime State

Ralph Loop stores these state fields: Terminal statuses are completed, blocked, and budget_exhausted. A new objective or a terminal prior run starts a fresh run.

Budget Exhaustion

When maxIterations is reached before the verifier-first completion contract is satisfied, Ralph Loop stops retrying and appends a verifier-aware notice to the latest answer:
The run status becomes budget_exhausted.

When To Use

Use Ralph Loop for goals where the agent should keep working until there is external evidence of completion:
  • migrations and refactors that must pass tests
  • UI parity tasks that need Playwright Interactive inspection
  • long implementation tasks where the model may stop early
  • research or analysis tasks with explicit verifier commands
  • tasks where a clean continuation prompt is better than carrying a cluttered history
Avoid using Ralph Loop as a full task runtime. It does not add a /goal product surface with pause, resume, clear, reports, or separate goal runtime state. It stays inside the existing middleware hook shape.

Troubleshooting

  • The final answer shows no <promise>DONE</promise>: This is expected. Ralph Loop strips the marker after accepting completion.
  • The model says it is done but keeps looping: The completion marker was not accompanied by passing trusted verifier evidence.
  • Verifier output failed: Ralph Loop will continue with the failure context so the agent can fix the root cause and verify again.
  • No verifier is detected: Ensure the agent has access to a tool listed in verifierToolNames, or configure the list for your verifier tool.
  • The agent stops with a budget notice: Increase maxIterations, clarify the objective, or inspect the last verifier evidence to see what blocked completion.