All right. So you learned a lot about agents already. You now understand a little more about how they work, when they're made for what makes them tick. Now let's get our hands on and actually build our first multi-agent systems ourselves. For this one, we're going to be building a crew that is able to do research and write an article for us. You're going to see how these agents work together, and how you're able to create something that's super valuable, true multi-agent collaboration. So you stick around, you're going to really like this one. Let's dive into it. All right. I'm super excited about this. We're going to be talking more about how to actually build multiple agent systems. I honestly believe this is the future. It's going to be a key part of how businesses are going to be built and how engineers can drive an immense impact on your jobs and your career. We are going to start by looking at how we can build our first multi-agent system, and we're going to try to do things simple. I'm going to start by just copying some code in here, making sure that we don't get any warnings along the way. So we're going to start by importing the three main things from crewAI. We're going to import agent, task and crew. Those three classes are the main important part from crewAI and how we are going to be building those multi-agent systems. Now that we have imported them, we got to choose what is going to be the LLM that is going to be the brain for all of our agents. So in crewAI, you can choose your agents to be run from different LLMs and by the food they all run from GPT-4. But in this case, let's make sure that they're running from GPT-3.5 turbo. And you can do that by setting environment variable called open AI underscore model underscore name. And in there you can add the name of the model. You're going to see down the road that you can connect your agents to any LLMs out there that are not necessarily Open AI. You can use local models. You can use any other major providers out there. So for this, let's make sure that we are using GPT-3.5. So let's start by creating our agents. Agents are corner piece of how we're going to build the multi-agent systems. So for this use case we're going to build three different agents. We're going to have a planner, a writer and an editor. These three agents together are going to help us come up with amazing technical articles. So how do you create an agent? Well, it's pretty straightforward. You basically create an instance of the agent class. When creating that instance, there are a few attributes that you really care about, namely the role, the go, and the backstory. So let's look into that. For our planner, we want to make sure that we set a role that matches what we want it to do. So we're going to keep it simple and we're going to say it's a content planner. You're going to notice that in the following of lessons we might do more complex roles and goals. But for this one, let's keep things simple. Now let's set up a goal for this agent. The goal for this planner is basically plan engaging and factually accurate content on a given topic. You notice here how we're interpolating the variable topic within the goal. You can do that in the role. You can do that in the goal. And you can also do that in the backstory. And I'm going to show you how that plays a role on actually running these agents down the road. So now let's set a back backstory to this planner agent. So if you look at this, you might be wondering, why are we going to the trouble of setting up the role that go into backstory? One thing that you're going to learn in future lessons is the fact that agents perform better with role playing. In this case, you can see that the agent's playing as a content planner. So as much context as we can set in terms of like what kind of agent it is, the better. Because it's going to conform to what we expect. So, now I'm going to set up a couple other attributes, namely when that say that this agent is not allowed to delegate work to another agent, and also making sure that it's verbose. So we can see how this agent runs its inner thoughts. Don't worry about those two attributes for now, we're going to get into them later. All right. So now that we have our planner here we can create this agent. And there we go. We have our planner agent ready to go. Now let's move on and create our writer agent. That is going to be responsible to actually write the content based on top of the research that the planner did. So in here you can see that we are doing a similar thing. This agent also has a role, also has a goal and also has a backstory. And you can see interpellation happening on multiple fronts. But all the interpellation that is happening is around the same variable called topic. And we are going to see how that plays a role in here by the end of it. So let's create our writer agent. Now let's create our final agent for this crew. And this agent is an editor. The editor is basically responsible to review the content, make sure that things are correctly formatted. That's good. And it's ready to go. So let's go ahead and create that editor agent as well. With that done, we have three agents, but we have no tasks and nothing to guide them. So let's now create a task for each one of these agents. Create the task is as simple as creating the agent. You need to create an instance of the task class. So in here you can see that you can just type task. In the task expect at least three attributes. The description, the expected output, and the agent. So the description is actually why do you expect the task to be. Why do you expect the agent to do so? In this case this is the planned task. So we expect our planner agent to look at the latest trends and look at the key players in making sure to create like a content or a research that we can use to actually write it down. The other argument that we expect in here is the expected output. And expected output here differs from the description, because it kind of acts as a forcing function to force you to think exactly what you want to get out of the task when you want this agent to produce as a final outcome. And here you can see that we're being very descriptive about it. We are saying that we want a comprehensive content plan with outline, audience analysis, SEO keywords, and resources. And then the final thing that we need to do is actually assign an agent to this task. So in this case, the agent that we're going to be assigning to this is our planner agent. And with that we created our first task. Now let's move on and create or write task. It's very similar but again different different arguments a different description and a different expected output. And here you can see that the expected output for the write task is actually the actual blog post. And we want it to be writing as markdown, having multiple sections in each section having between 2 or 3 paragraphs. So with that, we are ready to go because we have our two initial tasks. Now let's create our final task. This task is a little bit shorter because it's the edit task. This task is where the actor comes in and kind of proofreads the blog post. Make sure that the content is right, making sure that we have the progress that we need and that the thing is high quality. So we can also go ahead and create that task. So right now we have the agents and we have the tasks. We just need one way to mash those together. And that's where the third element of crewAI comes in. And that is the crew. Crew basically puts together agents and tasks so they can operate as a unit. So in here you can see that we set three attributes. The first attribute is a list of the agents. The second one is a list of the tasks. And then we have a verbose mode that allows us to see how this crew is executing, and look at some of its logs. One thing that I want to call out is that by default, a crew operates sequentially, meaning that one task is going to be executed after the next. Because of that, the order of the tasks. When you query the crew, it's important, given that the output of one task is going to be sent as part of the input for the next. So you really want to make sure that you get that right. We're going to learn down the road that that is not always the case. And you can have a way finer control on what order you want those tasks to be executed. If you want tasks to be executed in parallel, or if you want them to be executed hierarchically, it's all up to you. For this initial use case, though, this is going to work great. So how do we actually get our multi-agent system run? One thing that I want to highlight here is this verbose setting being set to two, depending on how you're setting up or crew. You might want to be able to see a certain level of granular logs. So in this case, you can set your verbose node between 1 and 2. And that will define how much verbosity you're going to see on your logs. If you're going to see all the logs that are possible or just a subset of them in this case, because we really want to see what is happening behind the scenes, we are going to set the highest number possible in this case number two. So now we have our agents and we have our tasks. So how do we get it run. How do we execute this multi-agent system. It's pretty straightforward. We use the crew dot kickoff method. So you can do this by basically calling kickoff So you can do this by calling kickoff and then passing an input dictionary into the kickoff method. In this input we have all the variables that you interpolated throughout your tasks and agents. So this is where that topic thing comes into play. So you remember how we interpolated this topic variable throughout or agents. when we first declare them up here. Well, now when we're kicking off our crew, we can actually send what is the word that we want to actually replace in all those different places. So now let's kick off our crew and see how that goes. So from the get-go, you can see that the content planner starts off and it's starting its first task that is prioritized the latest trend, keep players and node worse news on artificial intelligence, because that's the topic that we set. So we can see here that, you know, already did that and gave us an outline of what should be this article about what should be the main topics that should include on it. So now we can see that our new agent kicks in, our content writer, and it uses the previous information, the research that was made in order to put together a markdown blog post. So you can see in here how it's writing it all down for us. Now the editor comes in, proofreads and reviews and makes sure that it aligns with our brain's voice and that it looks great. And by the end of it, we should have a full-fledged post. For doing that, I'm going to be using this markdown helper. So once then you do that, you can plot the markdown here and we can see what this article looks like. It's called "The Rise of Artificial Intelligence: A Transformative Force in Today's World." And you can see that it has subtopics and each subtopics has some nice content into it. All right. So now we have our agents doing the work for us. And you can do it too. So I invite you to come in here and write the topic that you want your agents to write about. And you can execute this code and see they come alive and write this blog for you. So congratulations! This is your first multi-agent system and works great. Now let's talk about other use cases. So throughout this course we are going to use crewAI for all the examples. And you're going to probably find yourself looking at our docs at some point. So let me go ahead and tell you how the documentation that you find in crewAI is actually written by a crew. So this is another great practical use case that showcases how multi-agent systems can help you with engineering work as well. Where we don't have anyone on our team writing docs anymore, because now we have a multi-agent system that does that for us. So I would definitely recommend you to think about all those different use cases that you could apply those multi-agent systems into. Let's do a quick recap about everything that we learned so far. Before we move on to the next lesson. So we now fully understand what are agents. So we now understand what are agents. They're LLMs that can talk to itself. They have in your thought process. And they can receive tasks and use tools in order to give way more complex answers that they would be able to do otherwise. We also learned that you can have multiple agents hooked up together, showed that one agent can pass tasks to another agent. And by doing that, you can have specific agents that are great in one single thing. Basically, we learn the three main pieces and the corner pieces of crewAI. We learned about agents, tasks, and crews, and we now know how to put them together. But there are way more things that we learned throughout this. First, we learned that agents perform better when role-playing. Two you should focus on goals and expectations whenever creating or tasks in your agents. You need to make sure that you are setting up in a way they know what they're doing and they know what is expected of them. Three one agent can do multiple tasks if you want you. In our use case, we had one agent for every task, but we could go beyond that. We also learned that tasks and agents should be granular. You can see how we focus each agent on one very specific thing. And we also knew that tasks can be executed in different ways. We talked about tasks being executed in parallel or sequentially or hierarchically. And we are going to dive into all that in future lessons. And we also talked about how it's pretty easy to create multi-agent systems with crewAI. So, thank you so much for sticking around and learning more about multi-agent systems in this lesson. I'm looking forward to seeing you in the next one, where we're going to dive even deeper into how to build these agents, and making sure that we are taking full advantage of them and their tools.