Loop
<Loop> re-executes its children until a condition is met or a maximum iteration count is reached.
Workflow Definition
Running
Loop Props
| Prop | Description |
|---|---|
id | Unique identifier for the loop node. |
until | Boolean expression. When true, the loop stops. |
maxIterations | Safety cap on iterations (default: 5). |
onMaxReached | "fail" throws an error; "return-last" exits with the last output. |
Context Methods
ctx.outputMaybe(schemaKey, { nodeId })returns the value written by that task in the current render iteration (the iteration matching the current re-render frame), orundefinedif no row exists yet. To retrieve the highest-iteration row regardless of the current frame, usectx.latestinstead. The first argument is the schema key fromcreateSmithers, not a table name.ctx.iterationCount(schemaKey, nodeId)returns how many times a task has executed.ctx.latest(schemaKey, nodeId)always returns the highest-iteration row. Inside loops, this is often more convenient thanctx.outputMaybe.
Re-render Cycle
- The builder function
(ctx) => (...)runs on every render frame. - First render:
ctx.outputMaybe("review", ...)returnsundefined. The write task produces an initial draft. - After both tasks complete, the renderer persists outputs and re-renders.
- Next render:
latestReviewis populated. The loop evaluatesuntil. If not approved, the body executes again with the review feedback. - Repeats until approved or
maxIterationsis reached.