Skip to main content

Welcome to a Grasp lesson

Create a free account to keep studying and create your own study path.

Lesson 47

Orchestrating Parallel Agent Execution and Result Aggregation

Recommended resources

Introduction

In our previous lesson, we explored the multi-agent debate, a powerful pattern for sequential collaboration where agents refine solutions through iterative critique. This established a foundation for structured, turn-based interaction. Now, we will transition from the sequential to the parallel, addressing a fundamental challenge in agentic systems: latency. Many complex tasks don't require strict sequential processing; instead, they can be decomposed into independent sub-tasks that can be executed concurrently.

This brings us to this lesson's objective: to orchestrate the parallel execution of multiple agents and implement a structured result aggregation strategy. We will explore how to design systems where multiple specialized agents work simultaneously and how to intelligently synthesize their individual outputs into a cohesive final result. Your background in distributed systems and asynchronous programming will be particularly relevant here, as we'll frame this challenge through the lens of parallel computing and production-grade architecture.


1. From Sequential Chains to Parallel Graphs

A single agent, or a sequence of agents, working on a complex problem often becomes a bottleneck. Each LLM call and tool execution adds to the total wall-clock time. If sub-tasks are independent, forcing them into a sequence is inefficient.

Designing an Agent Runtime from First Principles - TianPan.co

This article by Tian Pan articulates the core problems with simple, sequential agent loops and makes a strong case for graph-based execution.

Please read the first two sections, The Three Problems That Break Simple Loops and Why Graphs, Not Chains. Focus on how latency arises from serialization and how a graph structure inherently enables parallelism.

As the article argues, moving from a list-based or "chain" mental model to a graph-based one is a critical architectural shift. A graph allows us to express that multiple tasks (nodes) can run concurrently, dramatically reducing overall execution time for decomposable problems. This leads to the Orchestrator-Worker pattern, also known as fan-out/fan-in.

This diagram illustrates the Orchestrator-Worker pattern. An "Agent Message Router" fans out tasks to specialized agents (Budget, Venue, Catering), which execute in parallel. A "Synthesizer Agent" then fans in their results to produce the final plan.

This architecture consists of three main components:

  1. Orchestrator/Dispatcher: A central component that receives a high-level task, decomposes it into sub-tasks, and dispatches them to appropriate worker agents.
  2. Worker Agents: A pool of specialized agents, each designed to perform a specific function (e.g., research, data analysis, code generation). These agents execute their tasks in parallel.
  3. Aggregator/Synthesizer: A component that collects the results from all worker agents and combines them into a single, final output.

The core decision in such a system is how the components coordinate. The following video discusses the two primary patterns for distributed coordination.

From Chaos to Choreography: Multi-Agent Orchestration Patterns That Actually Work — Sandipan Bhaumik

In this excerpt from "From Chaos to Choreography," Sandipan Bhaumik explains the trade-offs between two fundamental coordination patterns: choreography and orchestration.

Watch the segment from choreography or orchestration. Pay close attention to the distinction he draws between the decentralized, event-driven nature of choreography and the centralized, controlled nature of orchestration, and his reasoning for preferring orchestration in high-stakes, debuggability-focused domains like finance.

For building complex, reliable systems where you need clear dependency management, state tracking, and easier debugging, the orchestration pattern is generally preferred. The central orchestrator provides a single point of control and observability, which aligns with our goal of engineering production-grade workflows.


2. Parallel Primitives: A First-Principles Approach

To build this orchestration logic from scratch, we can borrow powerful and well-understood concepts from parallel computing. Instead of thinking of agents as anthropomorphic entities, we can treat them as "smart" processing units in a parallel algorithm.

This framing allows us to use fundamental primitives that you might recognize from your computer science background.

Parallel Primitives for Multi-Agent Workflows

This insightful blog post by Fergus Finn reframes multi-agent coordination as a parallel computing problem and introduces two core primitives: fold and unfold.

Please read the article from the beginning up to the end of the "Hylomorphism" section. Focus on these key ideas: The analogy between multi-agent systems and getting many obedient processors to cooperate. The definitions and asyncio pseudocode for fold (parallel reduction/fan-in) and unfold (parallel decomposition/fan-out). How a hylomorphism combines these two to represent the classic "divide-and-conquer" pattern.

The unfold-fold pattern, or hylomorphism, provides the formal structure for our orchestrator:

  • Unfold (Fan-Out): The orchestrator uses a decompose function (which could be an LLM call or fixed logic) to break a large problem into a list of smaller sub-problems. It then dispatches these to worker agents in parallel, for example using asyncio.gather as shown in the pseudocode.
  • Fold (Fan-In): The aggregator uses a combine function to recursively merge the results from the worker agents. This is done in a tree-like fashion to maintain logarithmic time complexity, drastically reducing the number of sequential steps required for aggregation. The combine function is where the "structured aggregation" logic resides.

3. Strategies for Structured Result Aggregation (The "Fold")

The fold or fan-in part of the pattern is where the intelligence of the system truly shines. Simply concatenating the outputs of parallel agents is often insufficient. The aggregator must synthesize the results in a way that is coherent, useful, and achieves the overall task goal.

The following video, though it uses a specific framework, provides an excellent survey of practical aggregation strategies that can be implemented from first principles.

Python + Agents: Orchestrating advanced multi-agent workflows

This presentation from Microsoft Reactor demonstrates several powerful patterns for aggregating the results of concurrent agent workflows.

First, watch the initial segment from concurrent execution to understand the basic fan-out/fan-in topology and see a simple concatenation-based aggregator. Then, focus on the detailed exploration of advanced aggregation patterns from So now let's talk more about aggregation. Pay attention to the different techniques demonstrated: LLM-based Summarization: Using a final LLM call to synthesize results into a brief. Structured Extraction: Forcing the aggregated output into a specific JSON schema. Ranking and Scoring: Using an LLM as a "judge" to evaluate and rank multiple outputs. Voting: An algorithmic approach where an aggregator tallies structured votes from worker agents without needing a final LLM call.

Let's summarize these aggregation strategies, which you can implement within the combine function of your fold primitive:

  1. Concatenation: The simplest form. The aggregator just joins the text outputs from all workers. Fast, but lacks synthesis.
  2. LLM-Powered Synthesis: The aggregator collects all worker outputs and feeds them into a final LLM prompt, asking it to summarize, create a report, or answer a question based on the provided context. This is the summarize_combine function shown in the "Parallel Primitives" article.
  3. Structured Extraction: Similar to synthesis, but the aggregator's LLM is prompted to return a JSON object conforming to a specific schema (e.g., a Pydantic model). This is extremely useful for downstream programmatic use.
  4. LLM as a Judge (Ranking/Scoring): When worker agents generate multiple alternative solutions (e.g., different marketing slogans), the aggregator can use an LLM to rank them based on specified criteria. This allows the system to select the "best" result from a pool of options.
  5. Algorithmic Aggregation (e.g., Voting): If the worker agents are designed to output structured data (like a classification or a vote), the aggregator can be a simple piece of code that tallies votes, averages scores, or performs some other deterministic computation. This avoids the latency and cost of an additional LLM call at the aggregation step.

4. Production-Grade Orchestration

When building a system for production, implementing parallel execution and aggregation correctly involves more than just asyncio.gather. You must consider state management and reliability, areas where your distributed systems experience is key.

Deterministic Concurrency and State

A naive parallel implementation can lead to race conditions if multiple agents modify a shared state.

Designing an Agent Runtime from First Principles - TianPan.co

Let's revisit Tian Pan's article to see a robust solution for managing state in a parallel execution model.

Read the section on The Execution Model. The concept of "super-steps" is a powerful pattern from parallel graph processing that ensures deterministic execution by isolating state changes within a round and merging them predictably.

Immutable State for Aggregation

This principle of deterministic state management extends to how results are passed between agents. Using shared mutable state is a recipe for bugs. A much safer pattern is to treat state as immutable.

From Chaos to Choreography: Multi-Agent Orchestration Patterns That Actually Work — Sandipan Bhaumik

Sandipan Bhaumik's talk also provides a clear model for production-grade state management and overall architecture.

Watch the segments on let's talk about the thing and what a production architecture would look like. Notice how he advocates for immutable state snapshots with versioning to eliminate race conditions and provide a clear audit trail for debugging.

In this model, when the aggregator combines results, it doesn't modify the existing state. Instead, it creates a new, versioned state object. This append-only approach to state evolution is fundamental to building reliable and debuggable distributed systems, and it applies directly to multi-agent architectures.

The final architecture combines these ideas: a central orchestrator manages a workflow graph, dispatching tasks to be run in parallel within a "super-step", and aggregates their results into a new, immutable state snapshot before proceeding to the next step.


Conclusion

In this lesson, we have moved beyond sequential agent interactions to design systems capable of parallel execution. This is a crucial step towards building efficient and scalable agentic workflows that can handle complex, decomposable tasks.

Key Takeaways:

  • Orchestration for Parallelism: The Orchestrator-Worker (or fan-out/fan-in) pattern, managed by a central orchestrator, is a robust architecture for parallel agent execution.
  • Parallel Computing Primitives: The unfold (fan-out) and fold (fan-in) primitives provide a first-principles, algorithmic foundation for implementing divide-and-conquer strategies with agents.
  • Structured Aggregation is Key: The "fold" step is critical. We explored several strategies, from simple concatenation to sophisticated LLM-based synthesis, extraction, and ranking, as well as algorithmic methods like voting.
  • Production-Grade Design: For reliable systems, use patterns like "super-steps" for deterministic concurrency and immutable, versioned state snapshots to prevent race conditions and ensure traceability.

Preview of the Next Module:
We have now designed workflows that are both complex and distributed. With complexity comes a higher probability of failure. An LLM API might be temporarily unavailable, a tool might time out, or an agent might produce an invalid output. Our next module, Agent Reliability and Recovery Patterns, will equip you with the engineering techniques to handle these inevitable failures gracefully. We will begin by implementing essential patterns like retry strategies with exponential backoff and jitter for transient API failures.