repeat runs one heading body in rounds. After each round it tests a value the round produced,
and either stops or starts another round, up to a fixed limit. Use it for review and rework
cycles, objection rounds and verification loops: work that runs at least once and whose next step
depends on what the round produced. Use for-each to run
the same steps once per item of a list.
Syntax
repeat id=review-notice
Fields
The fence takes no attributes after
id, and its body takes no other fields.
$round is the current round number, starting at 1. It can be used in the round body and in
on_continue, including in title and instructions templates. Inside on_continue it is the
number of the round that just finished.
Round values and carry
A round’s steps produce values that only that round can see. Those values driveuntil, and
collect and outputs copy them out of the loop.
carry is different: it is state the next round reads, such as a draft that gets revised. Many
loops need no carry.
- Each carry entry needs a real
initialvalue. A value with no sensible starting value is a round value, not carry. nextmust give every carry entry a new value. Its expressions can read round values,on_continuevalues and the current carry. Allnextentries are computed together from the finished round, so one entry never sees another’s new value.- A carry name can’t reuse a name that is already visible, such as a procedure input.
until
until.value must be a value the round body produces on every path. It can’t be carry or a value
from outside the loop, because those don’t change during a round. The values in in or not-in
are typed YAML values that must fit the tested member’s schema, for example in: [true] for a
boolean.
on_continue
on_continue runs only when the loop has already decided to run another round. It never runs
before round 1 or after the last round. Put rework there, not in the round body:
on_continue can read the finished round’s values, the carry and values from outside the loop.
Its own values can be used by next and then disappear.
When rounds run out
When the round numberedmax_rounds finishes without passing until:
on_exhausted: continuecloses the loop with the final round’soutputsandcollect, and the run continues. Route on the result afterwards if running out is a business outcome.on_exhausted: { fail: <code> }fails the run. The run’sfailure.codeisrepeat_exhausted, and its message is your code, such asnotice-not-approved. Codes are lowercase and hyphenated. Nothing is copied out of the loop.
Headings
The repeat follows the same heading rules as achoice:
the repeat is the last fence in its section, body and on_continue are direct child headings of
that section, placed first and together, and the run continues at the next heading after them.
on_continue sits beside the round body, not inside it.
A round body can hold any steps, including tasks, agents, waits and nested constructs. If a round
body reaches complete, the run ends.
Example
Compliance reviews a cancellation notice. If it asks for changes, an agent session revises the draft and compliance reviews again, at most three times. The group and policy values are illustrative.notice-rework.procedure.md
failure.code repeat_exhausted and the message notice-not-approved.
On retry and resume
- Each round is its own step. A step in round 2 is a different occurrence from the same step
in round 1, with its own identity. Each round’s task, agent session or call is created once, and
an effect’s
operation.idempotencyKeydiffers between rounds. - Collected values are kept. A finished round’s
collectvalues are recorded when the round ends. A resumed run doesn’t gather them again. - Exits happen in one step. When the loop ends, its
outputsandcollectlists become visible together. If the loop’s end also ends an enclosing body, both close together. - The loop’s own steps record nothing. Testing
until, computingnextand starting the next round don’t call anything. Steps inside the bodies behave as they do anywhere else.
Common errors
See also
- for-each node: one run of the body per list item
- choice node: routing inside a round, and the heading rules
- task node and agent node: review and rework steps
- Writes to your systems