Skip to main content
A 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 drive until, 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 initial value. A value with no sensible starting value is a round value, not carry.
  • next must give every carry entry a new value. Its expressions can read round values, on_continue values and the current carry. All next entries 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 numbered max_rounds finishes without passing until:
  • on_exhausted: continue closes the loop with the final round’s outputs and collect, 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’s failure.code is repeat_exhausted, and its message is your code, such as notice-not-approved. Codes are lowercase and hyphenated. Nothing is copied out of the loop.

Headings

The repeat follows the same heading rules as a choice: 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
If compliance approves in round 2, the loop runs the agent once, between rounds 1 and 2. The run ends with the round 2 draft and two feedback entries. If round 3 still asks for changes, the run fails with 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.idempotencyKey differs between rounds.
  • Collected values are kept. A finished round’s collect values are recorded when the round ends. A resumed run doesn’t gather them again.
  • Exits happen in one step. When the loop ends, its outputs and collect lists 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, computing next and starting the next round don’t call anything. Steps inside the bodies behave as they do anywhere else.

Common errors

See also