Skip to main content
Repeat a step until a condition is met. This pattern is ideal for iterative improvement, quality checking, and optimization workflows.
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.
The user requests repeated refinement; the repeat helper runs the step N times.

Quick Start

1

Define generator and stop condition

2

Run repeat workflow

Output:

API Reference

repeat()

Parameters

Condition Function

The until 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

Use Cases

How It Works


Best Practices

Cap repeat loops to prevent runaway cost when exit conditions never trigger.
Evaluator functions should return explicit booleans — avoid ambiguous string matching.
Repeat improves a single artefact; loop processes many items — do not confuse the two.
Inspect intermediate outputs when tuning evaluator-optimiser workflows.

Comparison with Loop

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