ai-agents-for-beginners

Multi-Agent Design

(Click the image above to view video of this lesson)

Multi-agent design patterns

As soon as you start working on a project that involves multiple agents, you will need to consider the multi-agent design pattern. However, it might not be immediately clear when to switch to multi-agents and what the advantages are.

Introduction

In this lesson, we’re looking to answer the following questions:

Learning Goals

After this lesson, you should be able to:

What’s the bigger picture?

Multi agents are a design pattern that allows multiple agents to work together to achieve a common goal.

This pattern is widely used in various fields, including robotics, autonomous systems, and distributed computing.

Scenarios Where Multi-Agents Are Applicable

So what scenarios are a good use case for using multi-agents? The answer is that there are many scenarios where employing multiple agents is beneficial especially in the following cases:

Advantages of Using Multi-Agents Over a Singular Agent

A single agent system could work well for simple tasks, but for more complex tasks, using multiple agents can provide several advantages:

Let’s take an example, let’s book a trip for a user. A single agent system would have to handle all aspects of the trip booking process, from finding flights to booking hotels and rental cars. To achieve this with a single agent, the agent would need to have tools for handling all these tasks. This could lead to a complex and monolithic system that is difficult to maintain and scale. A multi-agent system, on the other hand, could have different agents specialized in finding flights, booking hotels, and rental cars. This would make the system more modular, easier to maintain, and scalable.

Compare this to a travel bureau run as a mom-and-pop store versus a travel bureau run as a franchise. The mom-and-pop store would have a single agent handling all aspects of the trip booking process, while the franchise would have different agents handling different aspects of the trip booking process.

Building Blocks of Implementing the Multi-Agent Design Pattern

Before you can implement the multi-agent design pattern, you need to understand the building blocks that make up the pattern.

Let’s make this more concrete by again looking at the example of booking a trip for a user. In this case, the building blocks would include:

Visibility into Multi-Agent Interactions

It’s important that you have visibility into how the multiple agents are interacting with each other. This visibility is essential for debugging, optimizing, and ensuring the overall system’s effectiveness. To achieve this, you need to have tools and techniques for tracking agent activities and interactions. This could be in the form of logging and monitoring tools, visualization tools, and performance metrics.

For example, in the case of booking a trip for a user, you could have a dashboard that shows the status of each agent, the user’s preferences and constraints, and the interactions between agents. This dashboard could show the user’s travel dates, the flights recommended by the flight agent, the hotels recommended by the hotel agent, and the rental cars recommended by the rental car agent. This would give you a clear view of how the agents are interacting with each other and whether the user’s preferences and constraints are being met.

Let’s look at each of these aspects more in detail.

Multi-Agent Patterns

Let’s dive into some concrete patterns we can use to create multi-agent apps. Here are some interesting patterns worth considering:

Group chat

This pattern is useful when you want to create a group chat application where multiple agents can communicate with each other. Typical use cases for this pattern include team collaboration, customer support, and social networking.

In this pattern, each agent represents a user in the group chat, and messages are exchanged between agents using a messaging protocol. The agents can send messages to the group chat, receive messages from the group chat, and respond to messages from other agents.

This pattern can be implemented using a centralized architecture where all messages are routed through a central server, or a decentralized architecture where messages are exchanged directly.

Group chat

Hand-off

This pattern is useful when you want to create an application where multiple agents can hand off tasks to each other.

Typical use cases for this pattern include customer support, task management, and workflow automation.

In this pattern, each agent represents a task or a step in a workflow, and agents can hand off tasks to other agents based on predefined rules.

Hand off

Collaborative filtering

This pattern is useful when you want to create an application where multiple agents can collaborate to make recommendations to users.

Why you would want multiple agents to collaborate is because each agent can have different expertise and can contribute to the recommendation process in different ways.

Let’s take an example where a user wants a recommendation on the best stock to buy on the stock market.

Recommendation

Scenario: Refund process

Consider a scenario where a customer is trying to get a refund for a product, there can be quite a few agents involved in this process but let’s divide it up between agents specific for this process and general agents that can be used in other processes.

Agents specific for the refund process:

Following are some agents that could be involved in the refund process:

General agents:

These agents can be used by other parts of your business.

There’s quite a few agents listed previously both for the specific refund process but also for the general agents that can be used in other parts of your business. Hopefully this gives you an idea on how you can decide on which agents to use in your multi-agent system.

Assignment

Design a multi-agent system for a customer support process. Identify the agents involved in the process, their roles and responsibilities, and how they interact with each other. Consider both agents specific to the customer support process and general agents that can be used in other parts of your business.

Have a think before you read the following solution, you may need more agents than you think.

TIP: Think about the different stages of the customer support process and also consider agents needed for any system.

Solution

Solution

Knowledge checks

Question: When should you consider using multi-agents?

Solution quiz

Summary

In this lesson, we’ve looked at the multi-agent design pattern, including the scenarios where multi-agents are applicable, the advantages of using multi-agents over a singular agent, the building blocks of implementing the multi-agent design pattern, and how to have visibility into how the multiple agents are interacting with each other.

Got More Questions about the Multi-Agent Design Pattern?

Join the Azure AI Foundry Discord to meet with other learners, attend office hours and get your AI Agents questions answered.

Additional resources

Previous Lesson

Planning Design

Next Lesson

Metacognition in AI Agents