Loop (LOOP)
Repeats the modules on its Body output until a Validator inside them passes — for example "try again until the answer is good enough". If no Validator ever passes, the loop stops after a fixed number of rounds and the Done output runs once.
Category: Flow Control · Deployed: yes · Tool-capable: no
Ports
| Port | Kind | Purpose |
|---|---|---|
Input ( |
Input |
The starting value — the result of the previous module |
Body ( |
Output |
The modules to repeat. Connect the work here |
Done ( |
Output |
Give-up signal only. Runs once when the loop stops without a Validator having passed |
There is no Tool port.
Properties
| Field | Required | Meaning |
|---|---|---|
Max Iterations ( |
Yes |
The most times the Body runs before the loop gives up. Whole number above 0. Higher → more chances to succeed, but a run can take much longer and cost more. Lower → the loop gives up sooner |
Done Message ( |
No |
The text that Done passes on when the loop gives up. Empty → a generated text that says how many rounds ran and why the loop stopped |
How the loop ends
The Loop has no exit condition of its own. The exit is a Validator inside the Body.
-
Success. Put a Validator in the Body. Connect its Pass output to whatever should run after the loop. When the Validator passes, the loop ends at once. Done does not run.
-
Another round. When the Validator goes to Fail, the Body runs again. You can leave Fail empty. If you connect something to Fail, it runs first and then the next round starts.
-
Give up. If the Max Iterations rounds are used up without a pass, the loop ends and Done runs.
-
Done is not the success path. Work that must run after a successful loop belongs on the Validator’s Pass, not on Done. Connected to Done, it would run only when the loop failed.
What Done passes on
Done passes on the Done Message as plain text. It passes it even when nothing is connected to Done, but then nothing uses it. With an empty Done Message, the generated text reads like "Loop finished after 3 iteration(s): MAX_ITERATIONS".
| Reason in the generated text | Meaning |
|---|---|
|
All rounds ran and no Validator passed |
|
Nothing is connected to Body. No round ran |
Use cases
-
Draft and check: Loop → Body: Agent writes a draft → Validator checks it → Pass → next step. A bad draft goes back for another try.
-
Retry: Loop → Body: API Call → Validator checks the response → Fail retries.
-
Improve until a quality bar is met, with Max Iterations as the upper limit for time and cost.
Notes
-
A Body without a Validator runs all Max Iterations rounds, every time, and then runs Done. Nothing else can stop it early.
-
Every round is a full run of the Body, including all model calls in it. Set Max Iterations on purpose.
-
The pipeline cannot be deployed without Max Iterations. A missing value, or a value of 0 or less, is reported as a missing field when you save to a running agent or assign the pipeline.
-
Any Validator in the Body counts, also one that sits behind other modules in the Body.