Notebooks
O
OpenAI
Parallel Agents

Parallel Agents

chatgptopenaigpt-4agents_sdkexamplesopenai-apiopenai-cookbook

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
[ ]
  1. Define your Agents
[2]
[3]
  1. Create function for parallel execution
[4]
[5]
Final summary: ### Executive Summary

The AuroraSound X2 wireless noise-cancelling headphones offer a blend of premium design and advanced features. The headphones boast a matte-finish with comfortable, memory-foam padding, making them ideal for extended use. With Bluetooth 5.2, they provide seamless connectivity and stable communication. The noise-cancelling capabilities effectively reduce ambient noise and feature a well-tuned Transparency mode for essential sound transmission.

**Audio Quality** is a highlight, delivering rich, balanced sound with customizable EQ presets including “Podcast,” “Bass Boost,” and “Concert Hall.” Intuitive touch controls allow for easy navigation, though some users report occasional misfires. The extended battery life offers over 30 hours with ANC on, with a quick-charge option for convenience.

**Minor Limitations** include a bulky carrying case, occasional touch control issues, and limited color choices (black or white). Despite these, the overall sentiment is highly positive, with users particularly appreciating the headphones' design, connectivity, and performance. The product is recommended for those seeking high-quality audio experiences with effective noise-cancelling features.

### Star Ratings

- **Features**: ★★★★☆
- **Pros & Cons**: ★★★★☆
- **Sentiment**: ★★★★★
- **Recommendation**: ★★★★★

Overall, the AuroraSound X2 headphones are a compelling choice, offering excellent value despite minor drawbacks.
Output

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.

[7]
Final summary: **Executive Summary: AuroraSound X2 Wireless Noise-Cancelling Headphones**

**Features (⭐️⭐️⭐️⭐️⭐️ 5/5):** The headphones boast a premium, matte-finish design with comfortable memory-foam cushioning. They offer seamless Bluetooth 5.2 connectivity, impressive noise-cancelling capabilities, and a well-tuned "Transparency" mode. The audio quality is rich and balanced, with customizable sound options via a dedicated EQ app. Additional features include intuitive touch controls and excellent battery life paired with a quick-charge option.

**Pros and Cons (⭐️⭐️⭐️⭐️ 4/5):** 
- **Pros:** Premium design, comfortable fit, seamless connectivity, effective noise-cancelling, clear voice input in "Transparency" mode, customizable audio, intuitive controls, long battery life.
- **Cons:** Bulky carrying case, occasional touch control sensitivity issues, limited color options.

**Sentiment (⭐️⭐️⭐️⭐️ 4/5):** The overall sentiment is highly positive, with appreciation for the design, comfort, connectivity, noise-cancelling effectiveness, and audio quality. Minor drawbacks are noted but do not outweigh the benefits.

**Recommendation (⭐️⭐️⭐️⭐️ 4/5):** Highly recommended for those seeking premium noise-cancelling headphones with versatile features and excellent audio performance. The minor drawbacks are outweighed by the comprehensive suite of high-quality features.
Output

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.