Skip to main content

Overview

The BatchedGridWorkflow is a multi-agent orchestration pattern that executes tasks in a batched grid format, where each agent processes a different task simultaneously. This workflow is particularly useful for parallel processing scenarios where you have multiple agents and multiple tasks that can be distributed across them. The BatchedGridWorkflow provides a structured approach to:
  • Execute multiple tasks across multiple agents in parallel
  • Manage conversation state across execution loops
  • Handle error scenarios gracefully
  • Control the number of execution iterations

Architecture

Installation

Key Features

Attributes

str
default:"swarm_id()"
Unique identifier for the workflow.
str
default:"BatchedGridWorkflow"
Name of the workflow.
str
Description of what the workflow does.
List[AgentType]
default:"None"
List of agents to execute tasks.
int
default:"1"
Maximum number of execution loops to run (must be >= 1).
BatchedGridWorkflow does not currently accept an output_type parameter — there is no earlier documented parameter in the constructor beyond the ones listed above, and it does not maintain a Conversation object internally.

Methods

step()

Execute one step of the batched grid workflow. Pairs each agent with the task at the same index and runs all agent/task pairs concurrently via batched_grid_agent_execution. The number of tasks must match the number of agents.
Parameters:
  • tasks (List[str]): List of tasks to execute, one per agent (must be the same length as agents)
Returns: List[Any] - Results from each agent, in the same order as agents. If an agent fails, the exception is included in the results.

run()

Run the batched grid workflow with the given tasks for max_loops iterations. This is the main entry point that includes error handling (logs and re-raises any exception).
Parameters:
  • tasks (List[str]): List of tasks to execute, one per agent
Returns: List[List[Any]] - A list with one entry per loop iteration; each entry is the list of per-agent results returned by step() for that loop.

run_()

Internal method that runs the workflow without the top-level try/except error handling.
Parameters:
  • tasks (List[str]): List of tasks to execute, one per agent
Returns: List[List[Any]] - A list with one entry per loop iteration; each entry is the list of per-agent results returned by step() for that loop.

Usage Examples

Basic Usage

Multi-Loop Execution

Error Handling

The workflow includes comprehensive error handling:
  • Validation: Ensures max_loops is a positive integer
  • Execution Errors: Catches and logs exceptions during execution
  • Detailed Logging: Provides detailed error information including traceback

Best Practices

Use Cases

Source Code

View the source code on GitHub