BatchedGridWorkflow pairs agents with tasks by position: the first agent gets the first task, the second agent the second task, and so on. All pairs run at the same time, one thread per agent. Use it when you have a different job for each agent and the jobs don’t depend on each other. run() returns a list with one entry per loop, and each entry is a list of the agents’ outputs in agent order.
Reference: BatchedGridWorkflow.
1. One task per agent
Three agents each get their own task. The tasks run in parallel, andresults[0] holds the first loop’s outputs in the same order as agents.
2. Read the output
BatchedGridWorkflow has no output_type and keeps no shared conversation. Each output is exactly what that agent’s run() returned, so the agent’s own output_type decides its shape:
With the agent default,
output_type="str-all-except-first", an output is everything in the agent’s history after its first task, as text. On the first loop that is just the answer. On later loops it also holds the earlier answers and the repeated task. Set output_type="final" on the agents when you want only the latest answer.
3. Run the grid more than once
Withmax_loops above 1, the workflow sends the same tasks again. Outputs are not passed between agents. Each agent keeps its own conversation from one loop to the next, so it can see and improve its earlier answer. Every run() call starts each agent from a clean history first, so nothing carries over from an earlier run().
This block reuses tasks from section 1 and gives its agents output_type="final":
max_loops must be a positive integer, or the constructor raises ValueError.
4. Handle errors
The number of tasks must match the number of agents. A mismatch raisesValueError, which run() logs and raises again. An agent that fails does not stop the others: its exception object takes its place in the results, so check for it before you use an output.
Tips
- Same task for everyone? Use a ConcurrentWorkflow instead.
BatchedGridWorkflowis for a different task per agent. - Need one agent’s output in another? Use a SequentialWorkflow or GraphWorkflow. The grid never passes outputs between agents.
- Check the cost.
workflow.usagesums the token usage of every agent in the grid. - Run one pass yourself.
workflow.step(tasks)runs the grid once and returns one list of outputs, without the loop and without resetting the agents.