Recommended resources
The freely available resources this lesson will direct you to.
Introduction
In our last lesson, you mastered the art of the handoff, learning how to pass structured context and instructions from a parent agent to a single child agent. This 1-to-1 delegation is fundamental, but real-world problems are rarely so simple. A complex user request often requires insights from multiple specialized domains, demanding the coordinated effort of several worker agents.
This lesson builds directly on that foundation, moving from single delegation to multi-agent orchestration. We will explore how a supervisor or orchestrator agent can manage multiple workers and, crucially, how it can aggregate and synthesize their individual responses into a single, coherent, and unified result. You will learn the key architectural patterns for managing both sequential and parallel sub-tasks and the implementation techniques within the Vercel AI SDK to bring them to life. This is the next critical step toward building the sophisticated, multi-layered agentic infrastructure you've planned.
The Supervisor as Synthesizer
An orchestrator's job doesn't end when it delegates tasks. In fact, one of its most important roles begins once the workers have completed their assignments. The orchestrator must act as a final synthesizer, taking disparate pieces of information and weaving them into a cohesive whole.
This process can be visualized as a fork-and-join pattern. The orchestrator "forks" the workflow by dispatching tasks to multiple agents, and then "joins" the results, summarizing them for the final output.

There are two primary ways an orchestrator can manage this flow: sequentially for dependent tasks, and in parallel for independent ones.
Pattern 1: Sequential Synthesis
Sequential synthesis is necessary when the output of one agent becomes the input for the next. This creates a chain of dependencies where tasks must be completed in a specific order.
Consider a user asking, "What's the weather like in San Francisco, and what are some good attractions to visit based on that?" This requires two steps:
- Agent A (Weather Agent): Fetches the current weather (e.g., "73°F and sunny").
- Agent B (Attractions Agent): Takes the location and the weather as input to recommend appropriate attractions (e.g., "Golden Gate Park" and "Land's End").
The ToolLoopAgent in the Vercel AI SDK is inherently designed to handle this. When an agent runs in a loop, it can make a series of tool calls. The results of each call are automatically added to the context, making them available for the model to use in subsequent steps, whether that's calling another tool or generating the final text response.
This video from Vercel provides a concise demonstration of this exact scenario.
Multi-Step (Agentic) Generation with the AI SDK
This video, "Multi-Step (Agentic) Generation with the AI SDK," clearly illustrates how the SDK handles sequential tool calls and result synthesis.
Watch the segment from Max steps to multiple tools. Pay close attention to how the model first calls the weather tool. The result is then implicitly used in the context for the next step, where it calls the attractions tool with both the location and the temperature. Finally, the model synthesizes information from both tool calls into a single, comprehensive text response.
In this pattern, the "synthesis" is handled by the LLM's natural ability to reason over the accumulated context from the tool call history. Your primary job as the developer is to provide the agent with the right tools and a clear prompt explaining how it should use them to build a final answer.
Pattern 2: Parallel Synthesis
While sequential execution is powerful, it's inefficient for tasks that are independent of one another. If a user asks a question that spans multiple domains, like "What's the financial outlook for Eli Lilly, what do their recent clinical trials show, and what's the latest news about them?", you don't need to wait for the financial data before you start fetching news.
This is where parallel synthesis shines. The orchestrator can dispatch all three requests to three specialist agents simultaneously, dramatically reducing the total response time. The implementation of this pattern involves two distinct phases:
- Dispatch and Collect: Use JavaScript's
Promise.allto invoke all the necessary child agents concurrently. This executes them in parallel and waits for all of them to return their results. - Synthesize: Once all results are collected, make one final call to an LLM. In this call, you provide the collected results (typically as a structured JSON object) and a specific prompt instructing the model to synthesize them into a single, well-structured answer.
The Vercel AI SDK documentation offers an excellent code example for this "Parallel Processing" pattern.
This page from the AI SDK documentation details several advanced agentic workflows. The "Parallel Processing" example is a perfect blueprint for this lesson's outcome.
Study the code block under the Parallel Processing heading. Note how three different generateText calls (representing three specialized reviewers) are wrapped in a Promise.all. This is the Dispatch and Collect phase. Afterward, observe the crucial Synthesize phase: a final generateText call is made with a prompt that explicitly says, Synthesize these code review results, passing the aggregated reviews object as context.
This two-phase approach is fundamental to building efficient, multi-agent systems. It leverages concurrency to reduce latency and uses a dedicated synthesis step to ensure the final output is coherent and valuable.
Implementation in Practice: The Orchestrator Agent
Let's ground this in the context of the hierarchical system you're building. Your orchestrator agent will be responsible for this synthesis. It will have other agents (e.g., a Financial Analyst, a Scientist, a Journalist) available to it as tools.
The following article provides a complete, practical implementation of an orchestrator that does exactly this. It's a prime example of how to structure your code.
Building Multi-Agent Research Systems using Vercel AI SDK
This article by Prosper Otemuyiwa is a fantastic guide to building an orchestrator-worker system, which is directly aligned with your goals.
First, read the section The Architecture to solidify your understanding of the Orchestrator-Worker pattern and the importance of parallel execution. Next, focus on the code block for the orchestrator agent itself, under the heading The Orchestrator. This is the most critical part. Observe how: The financialAnalystTool, scientistTool, and journalistTool are defined by wrapping the respective child agents. The orchestrator's instructions explicitly tell it what to do: Synthesize results from multiple agents. This demonstrates the synergy between code and prompting: you provide the agent with the capability to call multiple workers (via tools) and the instruction to synthesize their outputs.
Let's apply this to your medical clinic system.

Imagine a user says: "I need to book an appointment with a cardiologist for next Tuesday, but first, can you tell me their credentials?"
An effective orchestrator would recognize the two independent sub-tasks and execute them in parallel:
- Task 1 (to
Availability Agent): "Find available slots for a cardiologist next Tuesday." - Task 2 (to
FAQs Agent): "Fetch credentials for cardiologists."
Using Promise.all, the orchestrator would get back results like:
Result 1:{ available: true, slot: "..." }Result 2:{ credentials: "Dr. Anya Sharma, MD, FACC..." }
Finally, it would perform the synthesis step with a prompt like:"Synthesize the following information into a helpful response for the user. Inform them of the doctor's credentials and then offer the available appointment slot. Results: ${JSON.stringify([result1, result2])}"
The final output would be a single, unified message: "Dr. Anya Sharma, a board-certified cardiologist, is available next Tuesday at 2:00 PM. Would you like to book this appointment?"
Conclusion
You have now moved beyond simple delegation to orchestrating multiple agents. By understanding and implementing these aggregation and synthesis patterns, you are building the "brain" of your hierarchical system—the component that assembles a complete picture from multiple, specialized points of view.
Key Takeaways:
- Supervisor as Synthesizer: An orchestrator's role includes not just delegating but also collecting and combining results into a final, unified response.
- Sequential Synthesis: For dependent tasks, the
ToolLoopAgentin the AI SDK naturally handles passing context from one tool call to the next within its execution loop. - Parallel Synthesis: For independent tasks, use a two-phase approach:
Promise.allto Dispatch and Collect results concurrently, followed by a final LLM call to Synthesize them. - Prompting for Synthesis: The synthesis step relies on a clear, explicit prompt that instructs the LLM to combine the structured results from child agents into a coherent narrative.
We have now explored how an orchestrator can delegate tasks and synthesize the results. But a crucial question remains: how does the orchestrator know what tasks to delegate in the first place? In the next lesson, we will begin our deep dive into the orchestrator by tackling its first major responsibility: designing an orchestrator that decomposes incoming requests into subtasks for the agent hierarchy.