Parallel Pattern: Agents Working Simultaneously

~10 min read

Each agent tackles a different subtask at the same time, and their outputs merge into one result — reduces latency in high-throughput pipelines where subtasks don't depend on each other.

The Parallel pattern directly addresses Sequential's main weakness: where Sequential runs agents one after another because each depends on the last, Parallel runs multiple agents at the SAME time, each tackling a genuinely different subtask, with their outputs merged into a single final result only at the end. This course's own example spans data extraction, web retrieval, and summarization all running concurrently, rather than one waiting on another.

The prerequisite for this pattern to make sense is exactly the opposite of Sequential's: the subtasks need to be genuinely INDEPENDENT of each other — no subtask's input depends on another subtask's output. If agent B needs agent A's result before it can start, you're back to Sequential (or a hybrid); Parallel only helps when the work can truly happen at the same time without one part waiting on another.

This course is direct about where this shines: it's perfect for reducing latency in high-throughput pipelines, like document parsing or API orchestration — cases where you have several genuinely independent pieces of work that all need to happen, and running them concurrently instead of one-by-one can meaningfully cut the total wall-clock time down to roughly the SLOWEST individual agent's time, rather than the sum of all of them.

The added complexity versus Sequential: you need an explicit aggregation step to combine the independently-produced results into one coherent output (this is closely related to, though distinct from, the separate Aggregator pattern, which is specifically about combining independent OPINIONS into a consensus rather than just merging independent subtask results), and you need genuine confidence the subtasks really are independent — mistakenly parallelizing tasks that actually have a hidden dependency produces subtly wrong results rather than an obvious failure.

💻 Code example

import asyncio
from openai import AsyncOpenAI

client = AsyncOpenAI()

async def extract_data_agent(doc: str) -> str:
    resp = await client.chat.completions.create(model="gpt-4.1", messages=[
        {"role": "user", "content": f"Extract key entities from: {doc}"}
    ])
    return resp.choices[0].message.content

async def summarize_agent(doc: str) -> str:
    resp = await client.chat.completions.create(model="gpt-4.1", messages=[
        {"role": "user", "content": f"Summarize: {doc}"}
    ])
    return resp.choices[0].message.content

async def sentiment_agent(doc: str) -> str:
    resp = await client.chat.completions.create(model="gpt-4.1", messages=[
        {"role": "user", "content": f"Classify sentiment: {doc}"}
    ])
    return resp.choices[0].message.content

async def parallel_pipeline(doc: str) -> dict:
    # None of these 3 subtasks depend on each other's output —
    # run them concurrently instead of one after another
    entities, summary, sentiment = await asyncio.gather(
        extract_data_agent(doc), summarize_agent(doc), sentiment_agent(doc),
    )
    return {"entities": entities, "summary": summary, "sentiment": sentiment}

💬 Deep Dive with AI

Key points

  • Multiple agents tackle genuinely independent subtasks simultaneously, with outputs merged into one final result
  • Only makes sense when subtasks truly don't depend on each other's output — otherwise you're back to Sequential
  • Perfect for reducing latency in high-throughput pipelines like document parsing or API orchestration
  • Total wall-clock time drops to roughly the slowest individual agent's time, not the sum of all agents
  • Requires an explicit aggregation step, and genuine confidence the subtasks are truly independent — mistaken parallelization produces subtly wrong results