Workflow Repeat (Evaluator-Optimizer)
Repeat a step until a condition is met. This pattern is ideal for iterative improvement, quality checking, and optimization workflows.Quick Start
API Reference
repeat()
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
step | Any | required | Step to repeat (function, Agent, WorkflowStep) |
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 |
Best Practices
- Always set max_iterations - Prevent infinite loops
- Clear stopping conditions - Make conditions unambiguous
- Track progress - Use variables to track iteration state
- Handle edge cases - Consider what happens at max iterations
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 |

