Okay. By now you're starting notice you're seeing how these things are coming together, right? You can see how you can view these agents and how they work and how can they be super helpful. So let's try to expand on that. Let's start to think about what other use cases. What else can we build. In this lesson we're going to be using a multi-agent system to help with customer support automation. So it's a different use case but a very interesting one. Stick around I'm sure that you're going to like this one. Let's dive into it. All right. Welcome to this lesson. I'm super excited about this one because we're going to be talking about how to use multi-agents for customer support automation. And that is such a big use case. If you think about customer support it feels like a no-brainer to have AI agents, to help our customers, to have just a better service in being able to tap into all of the docs, knowledges, and help center in order to provide very meaningful answers to these people that are trying to use customer support. Let's try to do some code and see how that works. Again I'm going to start just doing some boilerplate code to make sure that warnings don't get in the way. And I'm also going to import the same components that we learned on the last lesson, where we bring the agent, the task and the crew classes into this. For this example, we are going to be using GPT-3.5 turbo once again. So let's go ahead and set that environment variable. All right. So now let's dive into agents and how we can make them great. How we can bring everything that we learn in the slides into actually creating this agents. So we know that agents are impacted by the role-playing, the focus, the cooperation, the tools, the guardrails and the memories. All right. So for this use case, we are going to be building a support multi-agent system. The goal is going to be to help supporting customers that might have wing queries about a product. supporting customers that might have inquiries about a product. So the first agent that we are going to create is a support agent. So this support agent should be straightforward. You can see here that the role is a senior support representative. You can see how we use the key word "senior" here again to imply that we expect answers that are a little bit more polished than what you would mostly get out of the box. For the goal, we also mentioned that the goal is to be super friendly and helpful. So there will also play a piece on every stab on the process. And for the backstory, we basically told this agent works at crewAI And for the backstory, we basically told this agent works at crewAI and they are helping a specific customer. You can see the interpolation happening here. Again, trying to answer a specific question. But that agent alone is not going to help us. We're going to need another agent as well. So this other agent is going to be a support quality assurance agent. So let me copy that and paste it here. So this agent exists to help the support agent by fact checking everything that it says and making sure that is the best response possible for this customer. All right. So now we have both our support agent in our support QA agent. So far we can see how we are doing very focused approach here. Where we are prompting the agents to be very much getting into the character of their role. You can also see how one agent is not allowed to do any delegation, because we are setting allow delegation to false, but we are not doing that for the support quality assurance agent. That means that this agent can delegate, work back to the original support agent if it decides to. So this is an important trait for your QA agents. Make sure that if they find something that doesn't feel right, they don't necessarily need to fix themselves, but they can actually delegated back to another agent that might be better suited to do it, because either has like the right set of tools or the right set of backstory, goals and roles. So you might be wondering when exactly an agent decides that's reasonable to delegate work to another, or to ask question to another. And this is some of the differences between regular engineering and AI engineering. AI applications, again, they have fuzzy inputs, fuzzy transformations and fuzzy outputs, meaning that they don't necessarily follow the same pattern all the time. So in this case, we're relying on the brains, the LLMs, to make a conscious, reasonable call on when to delegate and when not to delegate. All that goes back to the fact that these models have a level of cognition, because they understand the language. So depending on the customer inquiry, they may understand that it's worth delegating and to do more research. But if it's more simple inquiry that demands a simpler answer. You might not want to delegate it back. So this is not something that you necessarily will have full control off. But you don't really want to, right? That's the magic of AI apps. It's the ability for these apps to react on runtime, on how they're going to handle with the information that they're being handled. So make sure to keep that in mind, that allowing an agent to delegate work and ask questions don't necessarily imply that it's going to do it every time, but that instead will give it the ption to do so if it chooses to. So this is one way on how you can get your agents to collaborate together in a great example, and how collaboration helps with better quality responses. So this is a very common pattern that we see throughout many users on crewAI. I usually having a final agent that is kind of like a quality assurance agent helps a lot and go a long way because they can do a final pass on whatever you want to do: writing a blog post, entering a customer, whatever it might be. So I do recommend you considering adding a QA agent of sorts into whatever multi-agent systems that you do, and that does tend to perform better than regular, regular agents without it. So far, this is a great example of role playing focus and cooperation. All right. So now let's move on and talk about tools, guardrails and memory. For that, we're going to be using crewAI tools. So crewAI also has a tools package with a set of tools that you can use. They have simple ones, like the ones that allow you to search the internet They have simple ones, like the ones that allow you to search the internet to more complex ones that allow you to do RAG over GitHub if you want to, or websites. There is many that you can explore, but we're going to stick with some of the simpler ones in here. We're going to use the server dev tool. We're going to use the scrape website too. And we're going to use the website search tool. Server dev to basically integrates with server. It's an external service that allows you to search Google. Scrape website is a simple scraper that allows your agent to access a given url and extract the contents of that. And the website search tool, is actually doing RAG over a website. If you don't know what a RAG means, it's basically doing a semantic search over the content of that website. So, in here you can see that we are importing the crewAI tools package in then, these three classes from it. And so let's go ahead and run that. So this is a great place where you can also think about other tools. So we're not going to talk about creating our custom tools right now. But this is a place where you could bring like tools that load customer data that tap into previous conversations or that load data from a CRM, checking existing bugs, feature requests, or ongoing tickets, all useful tools that would help these agents to provide better answers to the customer inquiry. So you can see here on how you should be thinking about what tools you should provide to your agents in order for them to provide meaningful responses. All right. So for every crewAI tool, there is a few different ways that you can use it. Let's say that we want to use the server dev tool. This is the only thing that we would need to do. Create an instance of the server devtool, and we assign that into a variable and we should be able to use that. We can also do the same thing for the scrape website tool, where we create an instance of that. And now we have that a tool. And we can assign that to an agent or to a task. But another interesting feature of crewAI is that you can also be more specific about how you want these tools to be used. So let's say that in this case I want of my agents to only search the crewAI docs. So I don't want it to be able to scrape any website out there. But I wanted to scrape specifically, one single page off our documentation. So I can actually do it when I instantiate this scrape website too. I can set an optional argument called website URL, and in that URL I can set a specific URL that I want this to to be able to scrape. So here is a great use case where you can see that you use the same tool, but one tool, would allow your agent to scrape any URL that it becomes aware of, as long as the agent teams that are scraping that URL would be beneficial. The second one allows your agent only to scrape one certain URL, and not every URL that it finds. So you can see how this can be very versatile as you're building our agents. For now, let's focus only on our docs search tool and see what our agents can do with that. All right. So now we already understand how we can bring tools into this. So how do we assign those tools? How do we give our agents those tools? There are basically two different ways that you can give your agent tools. You can give them at the agent level or you can give them at the task level. What that means is that if you give your agent a tool that tool belongs to the agent, it can potentially use that to for any task that it performs. But if you give it to the task, that means that the agent will only use that tool when performing that specific task. So an easier way to put this, is that task tools override the agent tools. So an agent might have ten tools at his disposal. But when performing a given task, if that task only says that it has three tools at his disposal, then the agent will only use those three tools. So let's start by creating our first task. And the first task that we are going to do is the inquiry resolution task. So in here, you can see that we are playing even more with the interpolation. Where we are saying, "hey, this customer, just reached out with a super, super important ask. Here is the inquiry. The person that works at this customer is the one that reaches it out. Make sure to use everything that you know to provide the best support possible. You must strive to provide a complete answer." So you can see here how this looks like more, regular prompting. But we are using that interpolation in a lot of different ways. And then again, we come with an expected output which very clear instructions and what we want to get back from this agent. And we provide the tools in here. So the tools is just an argument within the task. And it's an array that includes all the tools that you want to be available when the agent performs this task. In this case, it's only one tool, docs scrape tool. So let's go ahead and create this task. Now we're going to create our new task. That is going to be the task that the key way agent will use in order to review the work that the support agent did. So it's a similar task that doesn't use interpolation but rechecks what the agent viewed. You can see that in this case this task has no tools at its disposal, meaning that the QA agent, when performing this task, won't be able to look at our docs. It's purely assessing what is the actual response by the support agent wrote. All right. So now we got our two tasks that were created. That's great. So let's put our crew together. Create our crew. And in this crew, we're going to bring our two agents the support agent and the support quality assurance agent. And also the two tasks the Inquiry Resolution and Quality Assurance review task. And also, you notice that we're using memory for this one. So using memory with crewAI is super easy. You don't have to worry about it. You don't have to think about it too much. You can set this one single attribute on your crew, and that enables all those memories for you. The short term memory, the long term memory and the entity memory. So you don't have to configure anything other than set this one flag and everything works out of the box. So let's now focus on executing this crew so that we can actually get some results from it. In order to execute this crew, we need to pass inputs to it. We need to basically override all those interpolations We need to basically override all those interpolations that we did in the tasks and in the agents definitions. So in this case we had three main interpolation variables. We had the customer the person and the inquiry. Here, we are saying that the customer is DeepLearning.AI. The person that is asking the question is Andrew. In the inquiry is it needs help setting up a crew and kicking it off. And you want to make sure that it's using memory to set up that crew. Can the agents provide some guidance and actually help Andrew with that? Let's see how our agents do in trying to help Andrew. So from the get-go you can see that our senior support representative is kind of like kicking things off starting to look into the issue that Andrew brought up. You can see here the interpolation play its part where DeepLearning.AI, it's kind of like popping up in the task. So we can see that the agent now decides to read the website content, and it's actually looking into the documentation that we provided it with. So with the access to that documentation, it's learning everything about crewAI and how to create these agents, how to create the crews and how to kick it off. And then it comes up with an answer. In this answer you can see that it's super polite. It's says, "hey, Andrew. Hey, dear Andrew, thank you for reaching out for assistance..." And then goes on into explaining how to install both crewAI, crewAI tools, how to create agents, and then how to create a crew with the memory and everything with it. And you can see that once that this work is done, we now have our next agent. The support QA specialist kicks off to make sure that this is the best answer possible. So in here you can see that it didn't really like some of the responses. So we decided to delegate the work back to the coworker asks this to review and revise the response to ensure that it's comprehensive, accurate, and friendly. So now, if we write being a little bit more friendly on the response, you can see that it's more direct. It's basically saying like, this is how you set our crew in, this is how you add memory. Because those were the specific topics that Andrew originally asked for. So, you can see here how the answer looks way better. And now we should be able to get back to Andrew with that. You can see that the agent still is not super fan of that. So we decided to ask question to the coworker again to confirm if those are how the steps to create a crew and to add memory. And if there's nothing that is missing in there. So this agent kind of gives like more information around anything that might be helpful. And after that it puts together a final answer. And the final answer says: Hello DeepLearning.AI, Thank you for reaching out for assistance in setting up a crew and adding memory. I have reviewed the response draft and made some revisions to ensure clarity and completeness. Below are the steps that you need to follow." And then goes on like with the steps to create the crew and to add memory to that. So now this is something that we could actually set up and send back to Andrew. Make sure that it has all the information that it needs. And there we go. We created a new multi-agent system that is now capable of collaboration. So two agents are navigating and asking questions to each other. They are using memory. So they remember what they are doing as they are doing. And they are very much going into their roles by using role-play. So you can see all those elements that we talked about in those lines being played at here at real time. So let's go back to our lives real quick.