Steps inside this pattern inherit the same
max_retries, guardrails, and output_file policies as top-level steps. See Nested workflows → Retry, guardrails, and output_file.Quick Start
1
Define generator and stop condition
2
Run repeat workflow
Repeating a list of steps
Pass a list to run several steps in order, once per iteration. Each step sees the previous step’s output.Ordering guarantees
API Reference
repeat()
Parameters
Condition Function
Theuntil function receives WorkflowContext and returns bool:
Result Variables
After repeat completion:Examples
Quality-Based Stopping
Counter-Based Stopping
With Agents
Evaluator-Optimizer Pattern
Classic pattern with separate generator and evaluator:With Early Stop
Two-agent back-and-forth
The simplest N-agent turn-taking pattern: alternate two agents for a fixed number of rounds.Discussion — it exists for exactly this.
Use Cases
How It Works
Best Practices
Set a sensible max_iterations
Set a sensible max_iterations
Cap repeat loops to prevent runaway cost when exit conditions never trigger.
Write clear until conditions
Write clear until conditions
Evaluator functions should return explicit booleans — avoid ambiguous string matching.
Use repeat for refinement, loop for batches
Use repeat for refinement, loop for batches
Repeat improves a single artefact; loop processes many items — do not confuse the two.
Log each iteration in staging
Log each iteration in staging
Inspect intermediate outputs when tuning evaluator-optimiser workflows.
Comparison with Loop
Repeat vs. Discussion
repeat() now handles both a single step and a fixed list of steps — pick the right tool:
- Use
repeat(step, until=...)when the same step should iterate to improve. - Use
repeat([a, b, ...], max_iterations=N)for a light back-and-forth of a small, fixed list. - Use
Discussionwhen you want a first-class N-agent conversation with round-robin/custom selectors,until, and per-turn logging.
Related
Workflow Patterns
Overview of routing, parallel, loop, and repeat
Workflow Loop
Iterate over lists and files
Workflow Routing
Decision-based branching
Workflow Parallel
Run independent steps concurrently
Workflow Discussion
N-agent conversation loop

