Skip to main content
Loop tasks turn a single task into one subtask per row of a CSV or text file — no manual iteration.

Quick Start

1

Loop a task over a CSV

2

Same task, async entry point


How It Works

The workflow reads input_file before the run loop begins and expands the loop task into one subtask per row.

Choose the Right Loop


Sync vs Async

Loop pre-expansion runs identically for workflow.start() and await workflow.astart(). Prior to SDK versions from 2026-07-27 the async path ran the loop task once as an ordinary task and ignored input_file; prior to PR #5320 (2026-09-30) the async path also silently skipped a mid-workflow loop task with no input_file set — sync workflow() defaulted it to tasks.csv, async aworkflow() did not. Both start-task and mid-workflow loop-task fallbacks now match across sync and async. If you were using async workflows with task_type="loop" reached via next_tasks / condition, upgrade to pick up the fix.

Common Patterns

Summarise a list of URLs

Loop then post-process each row


Best Practices

When task_type="loop" and no input_file is set, the workflow reads tasks.csv from the working directory. This applies to both the start loop task and loop tasks reached mid-workflow via next_tasks / condition routing — in sync (workflow.start()) and async (workflow.astart()) engines equally. See the Sync vs Async note above for the version history.
Each row is passed to {input} as a single string. Put structured data in JSON inside the row and parse it in the agent instructions.
Subtasks execute one after another. Use AgentFlow.parallel when you want fan-out across rows.
Other rows still run. Check per-subtask TaskOutput to find which rows failed.

Workflow Loop

AgentFlow-level loops over a CSV as a pipeline step

Workflow Repeat

Repeat a step until a condition is met — no file needed