Prompt Chain

Run Specialized Agents in Parallel

Fan out specialized OpenAI Agents SDK agents in parallel, then fan their outputs into one meta-agent answer.

Works with openai

92
Spark score
out of 100
Updated 23 days ago
Version 1.0.0
Models

Add to Favorites

Why it matters

Reduce latency and cost in production workflows by fanning out multiple specialized agents concurrently and fanning in their outputs to a meta-agent.

Outcomes

What it gets done

01

Define multiple focused agents using the OpenAI Agents SDK.

02

Execute agents concurrently using asyncio or the Agents SDK.

03

Gather outputs from parallel agents.

04

Feed parallel agent outputs into a meta-agent for a final answer.

Install

Add it to your toolbox

Run in your project directory:

curl -fsSL https://spark.entire.vc/get/oai-parallelagents | bash

Steps

Steps in the chain

01
Install dependencies
02
Define your Agents
03
Create function for parallel execution

Overview

Running Specialized Agents in Parallel with the OpenAI Agents SDK

An OpenAI Agents SDK cookbook demonstrating fan-out/fan-in parallel agent execution via asyncio or agents-as-tools, merged by a downstream meta-agent. Use it when a workflow needs multiple independent analyses on the same input merged into one outcome. Choose asyncio for determinism and lower latency, agents-as-tools for dynamic planning.

What it does

This notebook demonstrates running several specialized agents concurrently to answer independent questions about the exact same piece of content, then feeding all of their outputs into a downstream meta-agent that produces the final, user-facing answer. Running analyses one at a time increases both overall latency and, if any single step fails and needs a retry, the total cost - fanning multiple agents out in parallel and fanning their results back in together reduces that latency considerably.

When to use - and when NOT to

Use this pattern when a production workflow needs several independent analyses run on the same input and merged into one outcome - customer-support triage, content moderation, or similar multi-angle analysis scenarios. The toy example in the notebook is intentionally one you likely wouldn't parallelize for real, chosen purely to demonstrate the mechanics rather than to model a genuine production case.

Inputs and outputs

Two distinct ways to run agents concurrently are shown: Python's asyncio (asyncio.gather) for lightweight, lower-latency parallelization with a deterministic execution order, and the Agents SDK's own "agents as tools" approach, which lets a planner dynamically decide which tools to call and in what order at the cost of extra latency from the planning call itself and the added tool-call overhead and context. A simple timeline visualization included in the notebook makes the latency difference between running agents serially versus in parallel visible directly.

Integrations

The choice between the two approaches comes down to three tradeoffs: convenience versus customization (agents-as-tools is more convenient; asyncio.gather gives more control over how fan-out and fan-in compose across multiple layers), planning versus determinism (agents-as-tools lets a meta-agent planner decide dynamically; asyncio.gather runs a fixed, deterministic order), and latency sensitivity (asyncio avoids the extra planning call and tool-call overhead that agents-as-tools introduces).

Who it's for

Developers and teams building OpenAI Agents SDK workflows that need multiple independent analyses on the same input merged into a single answer, who need to choose between asyncio-based determinism and SDK-native dynamic tool planning based on their latency and control requirements. The notebook walks through this in four concrete steps - installing dependencies, defining the individual specialized agents, writing the function that runs them in parallel, and wiring their combined outputs into the final meta-agent - making it straightforward to adapt the same four-step structure to a real production workflow rather than the toy example shown here.

Source README

Running Specialized Agents in Parallel with the OpenAI Agents SDK

Why would you want to do this?
In many production workflows you must answer several independent questions about the same piece of content.
Doing those analyses one-by-one increases latency and can increase total cost if any step fails and forces a retry.
By "fanning out" multiple specialized agents at the same time and then "fanning in" their outputs to a final “meta” agent, you're able to reduce this latency.

This notebook present a toy example that you likely wouldn't parallelize in the real world, but that shows:

  1. How to define several focused agents with the OpenAI Agents SDK.
  2. How to execute them concurrently using either Python asyncio for lower latency, lightweight parallelization or directly through the Agents SDK for ease of management and dynamic tool call planning.
  3. How to gather their individual outputs and feed them into a downstream meta-agent that produces the final, user-ready answer.
  4. A simple timeline visualization so you can see the latency benefit of parallelization.

This same pattern can be adapted to real world scenarios such as customer-support triage, content moderation, or other scenarios where you might want to run multiple independent analyses on an input and merge them into a single outcome.

  1. Install dependencies

  2. Define your Agents

  3. Create function for parallel execution

The agents can also be parallelized directly through the SDK via the "agent as tool" route, adding convenience and the assistance of the planner dynamically deciding which tools to call at the expense of higher latency. This latency comes both from the additional planning API call up front, along with the higher overhead and context from the tool call objects.

Summary

From the above, we can see two different patterns for parallelizing agents. Ultimately, the approach you use will depend on the balance you want between:

  1. Convenience vs. customization
    • If you prefer convenience, the agent as tool route is the way to go. If you want to customize how agents fan in and out across multiple layers, building a graph with asyncio.gather might make more sense
  2. Planning vs. determinism
    • If you want your planner (in this case the meta agent) to dynamically decide which tools to call and the order, you should use agents as tools whereas asyncio.gather makes more sense if you want a deterministic order.
  3. Latency sensitivity
    • If you're highly sensitive to latency, you may want to use asyncio to avoid the additional upfront cost of planning the parallel tools and the overhead of tool outputs and longer context windows.

FAQ

Common questions

Discussion

Questions & comments · 0

Sign In Sign in to leave a comment.