Quick Start
Output:API Reference
repeat()
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
step | Any | required | Step to repeat (function, Agent, Task) |
until | Optional[Callable] | None | Function returning True to stop |
max_iterations | int | 10 | Maximum number of iterations |
Condition Function
Theuntil function receives WorkflowContext and returns bool:
Result Variables
After repeat completion:| Variable | Type | Description |
|---|---|---|
repeat_iterations | int | Number of iterations executed |
Examples
Quality-Based Stopping
Counter-Based Stopping
With Agents
Evaluator-Optimizer Pattern
Classic pattern with separate generator and evaluator:With Early Stop
Use Cases
| Use Case | Description |
|---|---|
| Content Generation | Generate until quality threshold met |
| Optimization | Iterate until optimal solution found |
| Validation | Retry until validation passes |
| Data Collection | Collect until enough data gathered |
| Self-Correction | Agent corrects itself until correct |
How It Works
| Phase | What happens |
|---|---|
| 1. Start | repeat() records the initial repeat_index = 0 in context variables |
| 2. Generate | The wrapped step runs and returns a StepResult |
| 3. Evaluate | The until callable receives the updated WorkflowContext; returns True to stop |
| 4. Repeat | If until returns False and max_iterations not reached, the step runs again |
| 5. Return | Final StepResult is passed to the next workflow step |
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
| Feature | loop() | repeat() |
|---|---|---|
| Purpose | Iterate over data | Iterate until condition |
| Data source | List, CSV, file | None (generates) |
| Stopping | When data exhausted | When condition met |
| Use case | Batch processing | Iterative improvement |
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

