Skip to main content
<Loop until={done} maxIterations={5}>…</Loop> re-runs its children each frame until until evaluates true or maxIterations is reached.
Loop children are ordinary Tasks, so a loop drives compute tasks (an async function body, no agent) as well as agent tasks. Canonical non-agent case: a retry-until-green test loop.

Notes

  • Give every <Loop> an explicit id. An auto id derives from tree position, so a conditionally mounted/unmounted sibling shifts the path, re-keying the loop and resetting its iteration state from 0; an explicit id is immune.
  • onMaxReached has two values: "return-last" (default) ends the loop cleanly at maxIterations, keeping the last output; "fail" throws RALPH_MAX_REACHED and fails the run. Use "fail" when hitting the cap means the work never converged (tests never went green), the default when the best-so-far result is acceptable.
  • ctx.latest(table, nodeId) reads the highest-iteration output; until must use ctx.outputMaybe(), since output is absent on iter 0.
  • Direct nesting of <Loop> in <Loop> throws; wrap the inner loop in <Sequence>.
  • Custom Drizzle tables for loop tasks require iteration in the primary key.
  • Ralph remains a deprecated alias of Loop; new code should use Loop.