Skip to main content

Loop

<Loop> re-executes its children until a condition is met or a maximum iteration count is reached.

Workflow Definition

Running

Loop Props

Context Methods

  • ctx.outputMaybe(schemaKey, { nodeId }) returns the value written by that task in the current render iteration, or undefined if no row exists yet. The first argument is the schema key from createSmithers, not a table name.
  • ctx.iterationCount(schemaKey, nodeId) returns how many times a task has executed.
  • ctx.latest(schemaKey, nodeId) returns the highest-iteration row regardless of the current frame, unlike outputMaybe, and is often more convenient inside loops.
All intermediate outputs are persisted, so a mid-iteration crash restarts from the last incomplete task.

Re-render Cycle

  1. The builder function (ctx) => (...) runs on every render frame.
  2. First render: ctx.outputMaybe("review", ...) returns undefined, so the write task produces an initial draft.
  3. Once both tasks complete, the renderer persists outputs and re-renders.
  4. Next render: latestReview is populated. The loop evaluates until; if not approved, the body reruns with the review feedback.
  5. Repeats until approved or maxIterations is reached.