Workflow Loop Processing
Execute a step for each item in a list, CSV file, or text file. This pattern is ideal for batch processing and data pipelines.Quick Start
Loop Over List
Loop Over CSV
Loop Over Text File
API Reference
loop()
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
step | Any | required | Step to execute (function, Agent, WorkflowStep) |
over | Optional[str] | None | Variable name containing list to iterate |
from_csv | Optional[str] | None | Path to CSV file |
from_file | Optional[str] | None | Path to text file |
var_name | str | "item" | Variable name for current item |
Context Variables
Inside the loop, these variables are available:| Variable | Type | Description |
|---|---|---|
item (or custom) | Any | Current item being processed |
loop_index | int | Current iteration index (0-based) |
Result Variables
After loop completion:| Variable | Type | Description |
|---|---|---|
loop_outputs | List[str] | All outputs from loop iterations |
Examples
Custom Variable Name
CSV with Headers
Givendata.csv:
With Agents
Chained Loops
Loop with Aggregation
Use Cases
| Use Case | Description |
|---|---|
| Batch Processing | Process files, records, or data items |
| Data Migration | Transform and migrate data row by row |
| Report Generation | Generate reports for each entity |
| Email Campaigns | Send personalized emails to list |
| API Calls | Call API for each item in list |
Best Practices
- Handle errors per item - Don’t let one failure stop the entire loop
- Log progress - Use verbose mode or custom logging
- Batch large datasets - Consider chunking for very large files
- Clean up resources - Close files and connections properly

