An LLM agent can do a lot by itself. But as an application grows, the agent may need to handle different kinds of work.
At that point, it can be useful to introduce a multi-agent setup and split the responsibilities.
In this post, we’ll discuss how to build practical multi-agent systems using the OpenAI Agents SDK. We’ll specifically look at two patterns that are the building blocks for the more complex multi-agent architecture: agent-as-a-tool and handoff.
We’ll illustrate both patterns with two case studies.
···
Contents
1. It’s All About Delegation
A multi-agent system requires splitting responsibilities across multiple agents.
Once those responsibilities are split, the agents would need a way to work together. This is where delegation comes in.
In practice, there are two widely used patterns for delegation, i.e., agent as a tool, and handoff.
1.1 Agent as a Tool
Suppose one agent receives a request and needs help from a specialist. The main agent can then call that specialist agent.
The specialist agent works on a well-bounded subtask and returns its result to the calling agent once it finishes. The calling agent remains active, and it’s its responsibility to produce the final answer by combining the specialist’s response with possibly other information.
In this scenario, this specialist agent is effectively a tool from the perspective of the calling agent. And we can easily scale to several specialist agents, where the main agent decides which specialists to consult given the task.
This gives us the so-called “agent-as-a-tool” pattern. In the OpenAI Agents SDK, we create this relationship with specialist_agent.as_tool(...). We’ll see the complete setup in the first case study.
1.2 Handoff
Another way to delegate is to transfer control to a specialist agent.
In this scenario, the initial agent receives the request and decides which specialist to call. What’s different here is that the specialist agent would actually take over and become the active agent. It then becomes the specialist agent’s responsibility to produce the final response.
Here, the initial agent primarily serves as a router, routing the request to the appropriate specialist.
In the OpenAI Agents SDK, we can configure the initial agent with a list of possible handoff targets through handoffs=[...].
These two mechanisms form the building blocks, and based on them, we can build a variety of multi-agent systems.
We’ll return to these larger compositions at the end of the post. But first, let’s see some code examples that implement the above two foundational patterns.
···
2. Putting Delegation into Practice
For the case study, let’s build two small assistants around electric cars.
In the first case study, we consider the following situation: a family needs to decide whether buying an electric car fits their situation. They live in Zurich, Switzerland, and they drive around 15,000 kilometers per year. They have a budget of 45,000 Swiss Francs, but cannot install a private charger. To make a useful recommendation, our multi-agent system needs to look at suitable models, charging options, and ownership costs.
In the second case study, we help someone who already drives an electric car and relies on public charging in Zurich. The user wants to understand the available networks, subscriptions, and prices.
For the above tasks, we’ll implement two multi-agent assistants with the OpenAI Agents SDK.
We start with the purchase adviser.
2.1 Building an EV Purchase Adviser
For the purchase question, it naturally breaks into several independent lines of research: we need to find suitable vehicles, assess charging practicality, and understand ownership costs. These findings are useful only when combined into one recommendation.
This makes the agent-as-a-tool pattern a natural fit.
We can have specialist agents investigating each of those aspects, while we keep a purchase adviser agent in control and task it to synthesize their findings.
We first configure the shared client and model:
As we mentioned earlier, we use three specialists:
-
a vehicle researcher;
-
a charging researcher;
-
an ownership-cost researcher.
We give each specialist the web search tool:
Now comes the key step: we expose the above-defined specialists as tools for the purchase adviser:
Note that the tool_name and tool_description tell the purchase adviser what each specialist can do.
Now we define the coordinating agent:
Everything is set up. We test it with an actual request:
We run the adviser:
In my run, the adviser agent concluded that an electric car could fit the family’s driving needs, but that the lack of private charging would be the main constraint. It then compared several current models and explained the relevant trade-offs.
We can also inspect how the answer was produced:
The trace shows that the adviser called the vehicle, charging, and ownership-cost researchers, then remained the final agent.
So, the pattern of the “agent-as-a-tool” is clear: the specialists contributed their findings, while the manager agent retained responsibility for the answer.
2.2 Building an EV Support Agent
The second task considers a different scenario: an existing EV owner wants practical help with public charging.
Since this request belongs primarily to one specialist, a handoff is a natural fit.
To demonstrate this point, here, we define three possible specialists:
The support agent receives these possible handoff targets:
Note that we used an explicit handoffs list to inform the support agent which specialist agents can be delegated to. Here, the support agent does not need to combine several research reports. Its role is to identify which specialist should take responsibility for the request.
We test it with a charging question:
We run the support agent:
In my run, the request was handed to the charging specialist, who researched the available networks and produced the final response.
We can inspect the handoff directly:
Here is the result:
···
3. From Two Patterns to Larger Systems
Once we have these two delegation mechanisms, we can combine them to build different kinds of multi-agent systems.
In my experience, a useful way to think about the multi-agent system along three dimensions:
-
Delegation: does the delegated agent return its result, or take over the task? This is essentially what we have covered in this post, and we have two concrete patterns, i.e., agent-as-a-tool or handoff.
-
Topology: how are the agents connected? Practically, there could be many variants, such as connected through a central coordinator, a chain, a hierarchy, or a peer-to-peer network.
-
Execution: do agents run sequentially, in parallel, or repeatedly?
With these dimensions in mind, many common multi-agent patterns become easier to understand.
3.1 Fan-Out / Fan-In
A coordinator has several independent subtasks, or the same subtask but wants different agents to work on it from different angles. It can send them to multiple specialists in parallel and combine their results afterwards.
This is commonly called a fan-out / fan-in pattern.
Its delegation style is agent-as-a-tool. Its topology is centralized, and its execution is parallel.
3.2 Pipeline
In a pipeline, different agents handle different stages of a task. Here, the topology is a chain, and execution is sequential. The delegation is usually a handoff type.
3.3 Hierarchical Agents
As a system grows, one specialist may itself need help from more specialized agents. This naturally creates a hierarchical structure:
The topology is now a tree.
A common way to implement this is recursively with agents-as-tools. A manager calls a specialist, and that specialist can in turn call its own workers.
3.4 Evaluator-Optimizer
Some tasks benefit from an iterative process.
For example, one agent can produce an answer while another evaluates it. If the evaluator finds problems, the generator tries again using the feedback.
This is often called an evaluator-optimizer pattern.
The delegation can be implemented as the agent-as-a-tool, since the generator and evaluator provide outputs back to a coordinating workflow. The topology is centralized, and the execution happens in a loop.
3.5 Swarm / Peer-to-Peer
At the other end of the spectrum, we can remove the central coordinator. Instead, the currently active agent can decide which specialist should take over next.
This gives us a peer-to-peer, or swarm-style architecture.
Its delegation mechanism is mainly handoff, its topology is peer-to-peer, and its execution is dynamic.
3.6 Putting It Together
Although we sampled several common multi-agent system patterns above, their underlying agent interaction mechanisms are really built from the same foundation:
-
Agent-as-a-tool, where the caller agent retains control while delegating tasks to specialist agents.
-
Handoff, where the caller agent moves control to another agent.
By arranging these relationships with different topologies and execution strategies, we can build much larger multi-agent systems.
