From the course: Building AI Agents for Beginners by Microsoft

How to use a multi-AI agent system

(gentle electronic music) - What is the multi-agent design pattern? When is a good time to use multiple AI agents instead of one? And what kind of control and visibility do we have when working with multiple agents? We're going to answer these questions in the eighth lesson of the AI Agents For Beginner's Course. In this course, we take you from concept to code, covering some of the fundamentals of building AI agents. And this is a short video that follows along with the written lesson, including translations and code samples that you can find at the link above and below this video. To put it simply, the multi-agent design pattern is where we have multiple AI agents working together to complete a common goal or task. But the real question is, how exactly do the AI agents do that? And there are different design patterns that apply depending on their goal. There is group chat, where just like a group chat with your friends and colleagues, every message in the chat is broadcasted to each agent, and depending on the contents of that message, a group chat manager, typically another AI agent, will select the appropriate AI agent to handle performing the task. For example, you might build an airline customer service application where there are separate agents that handle booking or customer complaints or questions about flight status. A customer could type their message into the chat and there would be a task request that would be routed to the proper agent. There may be scenarios where an AI agent needs information from another AI agent before completing its task. And this is called a handoff pattern, where there is an AI agent completing each step in a defined workflow before handing it off to the next. And lastly, there are cases where you want each AI agent in your application to perform some tasks, and this is called collaborative filtering. In this design pattern, each agent acts as a specialist in some task or area and responds to that task in their own unique way. And this is great when performing some type of analysis where you want different inputs or perspectives on some data. And as you can see, the multi-agent design patterns cover a widespread of different use cases. Let's really see how it works by heading over to our code area. Okay, so now we're in our coder looking at the chapter eight, or lesson eight, example. Again, this code sample is available at the GitHub above, GitHub repo above, the link above and below this video. In this scenario, we're actually going to have two agents, one kind of producing content or writing content, and another agent reviewing that content. So, this is kind of the reviewer checker pattern, or again, utilizing multiple agents to produce a better result. In this case, we're going to have one reviewer agent, which is the concierge. And we've given specific instructions to the concierge in terms of being able to both focus on recommending non-touristy experiences for travel. So, we want kind of this local and authentic experience that a good concierge should provide, right? And then we're also got to make sure that it doesn't actually, you know, providing the insights. I mean, it also just only provides insights on recommendations for improving that suggestion, but doesn't provide a specific example. So, we don't want the, you know, the concierge to just make new examples. And we, because what we would want to happen is, we have this other agent, which is the front desk agent, and we've also given it kind of instructions to provide one single recommendation per response. So again, allowing the concierge to review that and make any suggestions, but not new recommendations. But we also then want the front desk agent to consider those suggestions and refine that idea that they have. So, in this case, we're going to then, what's might be new with multiple agents here is that we have this termination function, and this is going to be a function that we want to essentially terminate the interactions between the agents. In this case we have this, we've defined that this is going to be when the concierge has given approval of the most recent response. So, the other most recent suggestion that the front desk, when it meets their standards in terms of having a local and authentic experience. And then we also have the selection process, which is where we're going to define basically how this conversation will take place. So, we're going to have that, you know, each participant takes a turn in the next conversation, we're all going to choose from these participants, again, the reviewer and the, which is the concierge and the front desk. And then we've also defined what's going to happen. You know, the user is going to have an input or a question, going to go first to the front desk. Then the front desk is going to reply. Then it's reviewer's turn to do their instructions, which is again, to review the front desk's suggestions. After that, they're going to provide some feedback and then it's up to the front desk to then suggest something new. So, in this case, then we want to go and look at what this output will look like. And again, we have this input and this person would like to go to Paris. It was a general question. And then the front desk is going to recommend the Louvre Museum. The Louvre is, you know, great, great museum and the concierge recognizes that, says, you know, this is undeniably a world renowned site, but it's also one of the most popular tourist destinations. Again, we want to give a very local and authentic experience, something kind of off the beaten trail in terms of suggestions. So, go suggesting a lesser known museum or local art gallery. So, this is kind of again, giving feedback to the front desk. And then the front desk comes back. The front desk agents says, visit the museum de l'Orangerie for an intimate experience with Monet's Water Lilies. So, great, the concierge says, approved, which then, that terminates our conversations because now it meets the kind of criteria for the concierge. And then we can see that this is complete, is true. And this is just one type of pattern that we can apply to in terms of using multiple agents. And you can see here now, the kind of power between not just having one agent make suggestions, maybe having, you know, in hoping the user makes feedback, but even using an agent to refine those results and giving back a better suggestion. So, that was the end of lesson eight, for in terms of multiple agents. But see you in lesson nine. (brief electronic music)

Contents