CrewAI - Your Own Team of Autonomous Agents

A concise tutorial by LARRUZ (YouTube, Jan 13, 2024) demonstrating CrewAI—an open-source framework for orchestrating autonomous AI agents—via a Google Colab notebook. The video walks through installing CrewAI and dependencies, configuring Gemini Pro (via LangChain Google Generative AI) and a DuckDuckGo search tool, defining two agents (a senior research analyst and a writer) with roles/goals/backstories, assigning two sequential tasks, creating a crew, and running the workflow to produce a final report. The creator notes the project’s popularity (Product Hunt trend, ~4000+ GitHub stars) and points out minor inaccuracies in the generated content while highlighting CrewAI’s visibility into internal LangChain prompt templates and chat-history-based coordination.
Questions this video answers
January 13, 2024.
Over 4,000 stars (presenter states ~4000+).
Gemini Pro (via LangChain Google Generative AI).
DuckDuckGo search (via a DuckDuck search package).
Senior Research Analyst and Writer.
Chapters
Today we're going to look at CrewAI, which is an open source project for orchestrating autonomous AI agents in functionality. It's very similar to Autogen from Microsoft, but I think it's a lot easier to use and has been designed with production in mind. The project is already trending on Product Hunt and has over 4000 stars on GitHub. Here is how it works. So there are role based API agent design. Each agent can be considered as an LLM that has access to certain tools and each agent is assigned a specific task. Then the agents can work collaboratively together to achieve those tasks and work as a team. And that's why it's called crewai. CREWAI works with both open source as well as proprietary LLMs. And in this video I'll show you a very simple way of how to use this in a Google Colab notebook for absolutely free. Apart from the documentation, the authors have also put together a custom GPT for crewai. So you can actually ask questions regarding different features available from this custom GPT, which is extremely helpful. So for example, here's a question that I asked, how to create a chatbot in qai and it essentially walked me through a step by step process. So first we need to define a chatbot's role or go. Then we need to set up agents, then define a task for each agent, then create a crew of agents and then at the end we need to simply kick it off for it to start processing our requests. Next, let's look at a quick example of how to use this. I'm going to be using a Google Colab notebook, so everybody has access to the code. So for this tutorial we're going to be using Google Colab. First we need to install some of the packages, so we need to install the CrewAI package. We will be using Search as a tool, so that's why we need this DuckDuck search package as well. And we're going to be using Gemini Pro as the LLM for this example. That's why we need the LangChain Google Generative AI package as well. You can copy and paste all this code that I'm about to show you in a Python script file and run it in Visual Code Studio. But for easyl Fuse I will be just providing this Google Colab notebook. Next we need to import some of the required packages, so we are importing the OS package. Now, as I said, I'll be using the Gemini Pro as an example LLM in this case, but you can use both OpenAI as well as Open source large language models. In a subsequent video, I'll show you how to run this with open source large language models as well. I'm using Gemini Pro because you don't need a powerful GPU for it to run. Anybody can run it on their computer because you're accessing it through an API. And the best part is you don't have to pay for anything. And from the crewai package we are importing Agent Task Crew and then a process for this tutorial. An amazing community member, Phenomenology, helped me out with the code on how to use Gemini Pro. So shout out to Phenomenology. Also, if you haven't, check out the Discord server. There are some really amazing people who are helping each other out. As I said, we're going to be using the Gemini Pro as an LLM. So we will use this chat Google Generative AI, which is a function within the LangChain Google Generative AI package. You can play around with the temperature as well. And at the end you will need to provide your own API key. To get your API key you need to go to Google AI Studio, then click on Get API key, create a new API key and just copy that in here. Next we will set up tools that we want our agents to use. So in this case I'm just providing a search tool and the search is going to be performed through the DuckDuckGo search engine. Next we can start defining our agents. Now it's up to you how many agents you want. But you want every agent to have a different role, different goal and a background story or essentially a system prompt. Okay, so here is how you define an agent. First we're going to be using the agent class and you need to provide certain attributes. So first is the role. In this case we are calling this a senior research analyst. We also need to provide what the goal of this agent is going to be. In this case, uncover cutting edge developments in AI and data science. Then for each agent you also need to provide a backstory or a system prompt of what exactly the abilities of this agent are. Next we are setting verbose to true. You can also delegate tasks among different agents. So you can give this the ability to dedicate tasks to different agents or not. But in this case we are setting it to false. Then we need to provide the LLM it's supposed to use. So in this case we are using Gemini Pro. However, if you were to use an open source LLM, so you could run the LLM through Ollama and just provide that in here. So here's an example. Or you can do exactly the same with OpenAI models, for example, GPT4 or GPT 3.5. Now in that case, you will also need to set the corresponding environment variable with the OpenAI API key, but to replace the LLM that you're using. It's very simple. Next, if you want agent to have access to certain tools, you can provide a list of tools in here. In this case, we're just providing the search tool. Our first agent was researcher. Here we are also creating another agent and we're calling it Writer. Now this agent doesn't have access to any tools, but again, it has a role corresponding goal that we want it to achieve and the corresponding backstory or abilities that the agent has. Next, we need to provide a list of tasks that these agents are supposed to perform. In this case, there are simply two tasks. The first task is conduct a comprehensive analysis of the latest advancements in AI in 2024. Then you need to also provide which agent is going to perform this task. So we say that that is going to be the researcher's role. And the second task is using the insights provided. Develop an engaging blog post that highlights the most significant AI advancements. So this is a task for the writer, and that's why we assigned it to the writer. Now the next step is to create a crew. So the crew is basically all the agents that you have. So we are providing both the agents. I think you can create multiple crews as well, which can do different tasks. And we also give it a list of tasks. Now in this case, it's going to do the task sequentially. So task one is, is going to be completed, then task two. And it seems like on the roadmap they have plans for other type of execution as well. And we want a warboost set to level two. Now you can actually look at the crew of what exactly is going on behind the scenes. So first it has the task. This is basically the list of tasks that we provided to the crew. Then the LLM that is supposed to be used in here. Now there is even a prompt template. So in the back end it's using LangChain, and you can see a prompt template from LangChain. And it's actually pretty good to see that they provide so much visibility to the internal working of the crew. If you look at the prompt template. So it seems to have a chat history as well. Also it accepts the tool name, what tools are provided. So it seems like it's keeping track of all the interactions in the chat history and those are exchanged among agents, depending on how many agents you have defined in here. Okay, so the last step is just to kick off the crew and let the magic happen. Now let's look at the internal working of the crew. So first it's using the senior research analyst agent and here it's its thought process. So as I said, it's using LangChain in the backend. So the first thought was do I need to use a tool? The answer is yes and the action is to do search through the DuckDuckGo search engine. So here's the action input. This is basically the task that we provided. And here's the final answer. So the senior research analyst actually generates the report in here. And after that, since we are using a sequential execution, so it gives this to the a writer agent. Right. And the writer agent again has an internal thought, do I need to use a tool? The answer is no. And then it goes on and starts writing the final report in here. Now the final report does have, I think some issues. For example, it says the accessibility of open source pre trained AI models developed by tech joints such as IBM and NASA is revolutionizing the way business leverage AI. I don't think IBM and NASA has actually released any open source pre trained LLMs, but other than that it actually looks pretty good. Anyways, this was a quick tutorial on how to set up CREWAI in Google Colab and interface it with Gemini Pro. It's a very interesting project. It's under active development, so I think we can expect some really cool things coming out of this project. Let me know what you think about the autonomous AI agents frameworks that are coming along. Hope you found this video useful. Thanks for watching and as always, see you in the next one.










