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
  • Re-run the same task grid for a set number of loops
  • Handle error scenarios gracefully
  • Control the number of execution iterations

Architecture

Installation

Key Features

Attributes

str
default:"auto-generated"
Unique identifier for the workflow. Auto-generated via generate_id("batched-grid-workflow") if not provided, producing batched-grid-workflow-<32 hex chars>.
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 a positive integer, or ValueError is raised at construction.
BatchedGridWorkflow has no output_type parameter and keeps no Conversation. run() returns each agent’s raw run() output.

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, or ValueError is raised.
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. Every loop re-sends the same original tasks; outputs are not fed back in as new tasks, though each agent keeps its own conversation memory between loops. 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, and that each step gets one task per agent
  • Agent Errors: An agent that raises during a step has its exception returned in that step’s results instead of stopping the other agents
  • Execution Errors: Catches, logs and re-raises any other exception during execution
  • Detailed Logging: Provides detailed error information including traceback

Best Practices

Use Cases

Source Code

View the source code on GitHub