foreach() method to define a nested agentic workflow. In this method, define the following parameters:
| Parameter | Type | Required | Description |
|---|---|---|---|
| item_schema | BaseModel | Yes | The schema that defines each item to iterate over. |
| input_schema | BaseModel | No | The input schema for the nested agentic workflow executed by the foreach node. |
| output_schema | BaseModel | No | The output schema for the nested agentic workflow executed by the foreach node. |
Example
Example
Python
Foreach processing method
You can configure how your foreach node processes input items. There are two processing methods:- Sequential A sequential foreach processes items one after another. The next item starts only after the previous one finishes. Use this method when the order of item processing affects the result.
- Parallel A parallel foreach processes one or more items at the same time. In most cases, this method runs faster than the sequential approach.
policy() method in your foreach node. This method accepts the following parameter:
| Parameter | Type | Required | Description |
|---|---|---|---|
| kind | ForeachPolicy | Yes | Defines the processing method. Use ForeachPolicy.SEQUENTIAL for sequential processing or ForeachPolicy.PARALLEL for parallel processing. |
Python

