Thumbnail for Orchestrating LLM AI Agents with CrewAI | Ai Heroes 2024 Talk by AI Heroes

Orchestrating LLM AI Agents with CrewAI | Ai Heroes 2024 Talk

AI Heroes

28m 51s4,425 words~23 min read
Auto-Generated

[0:00]So, what's CrewAI about? CrewAI is an open source tool, so you can use it with Python. What you can do with it is working with agents, orchestrating agents, in a very simple way without taking care of how these agents are built, how this reasoning is built under the hood. You just have to focus on the business problem. When do you need it? First, when you need multi-agent collaboration. When you need to work with an LLM and you need a good interface, I think that's also the case. Uh, when you want something that is scalable, we will see that you have if you have to work with agents. Working with this library makes everything super scalable, so you don't have to, uh, take care of, uh, very weird refactoring and, I don't know, something super exotic to fix your LLM application.

[1:01]Uh, this presentation is about orchestrating LLM AI agents with CrewAI. Uh, so guess what, still about agents. Um, this is my, this was my approach to, um, implementing applications based on agents during the last year. I did a lot a lot of fun. I did work on a lot of projects. This is, in this case, I will prepare, I will show a small use case, which is based on something that I did this year. Um, and, uh, it doesn't come from my work experience, but it's more a personal project for the sake of the presentation, but it would be quite entertaining. Uh, we will see what's Agentic AI, uh, what's behind, what's behind all these marketing words that we, we probably, you probably heard during the last year. Uh, we will dive into the package, CrewAI, this is an open source package, and we will look into the concepts of agents, tasks, and crews. Um, we'll move to the orchestration, and then there will be a small use case and the conclusion. Um, this is the, yeah, this is the most egocentric way I have to tell you who I am. It's, it's, I didn't expect, expect such a big screen. I have to be honest. Um, so I work as a data scientist, uh, and actually this slide is most mostly for you because I'm in a natural, I'm a data scientist, I've been exposed to many domains, ride-hailing, uh, logistics, but I, we can also talk about something else after presentation, I'm really approachable. So if you don't like data science, we can talk about ski, guitar, whatever you want. How many data scientists in the room? Real data scientists? Someone? Uh, how many prompts engineers? Yeah, not shying, right? All right, so what's Agenti AI? Um, still, you know, we, we, we have this problem of, um, basically, um, uh, having this placeholder. One of them is AI. AI, back then when I started working on deep neural networks, it was about deep neural networks. Before it was about rule-based systems. So we had this placeholder for a lot of technologies. Now when we talk about Agentic AI, it's about working with agents. Uh, but I consider it a placeholder. I think that for convenience, it's nice to say okay, agents, AI, we know what we mean. Um, but, uh, now AI is, uh, kind of about like LLMs. And what I've seen during the last months is that we have prompts everywhere. Uh, this is something that I, um, like, but at the same time, I don't really like it because it's, as you can see, suitable for small tasks, but it it also creates a lot of problem. And you probably know what I mean because whenever you have to productionize something based on prompts, it makes everything, uh, very complicated, it's not scalable, it's is not modular. Um, so I think if you're a prompt engineer, a very good one, if you get a master's on prompt engineering, you know what I mean. And, um, if we go back to 2022, uh, we started with a, with a, with LLMs, large language model. And what happened is that we have, um, we started working with this very interesting approach which changed the world. Um, and is about creating, sending a query to this LLM, and then there is a generation, and after this generation, we get an answer. And this was our first approach to LLMs. At some point, we move to Compound Systems. Perhaps you know about them as Retrieval-Augmented Generation. And how this, um, changed the way we use the generation, is that now we have some sort of database we can access to. So, in a nutshell, whenever we ask something to an LLM, um, in, we know that there is a generation approach, so the LLM doesn't know anything about your vacation days, about what you're gonna do tomorrow, of course. But if you put this information into something that is accessible to the LLM, then you have this some sort of compound system. And then we move to, let's say, in 2023 or lately, we move to LLM agents. LLM agencies is something, um, in my opinion, very easy to understand.

[5:25]There's nothing really complex in it. Um, in the end, you can see the agent as a loop around this system that includes, uh, LLM, like ChatGPT in this case, uh, the tasks and the tools. So, is a way of, um, developing something that incorporates reasoning. Of course, there is no real reasoning behind it, even though we don't really know how we reason. But we can say that there is a reasoning implemented in it, and this loop feedback is thanks to some memories, some actions. It's incorporating this reasoning approach to validate the output and create an even stronger and sound output. And we can say that's pretty much it, right? So we we we don't want to dive too much into agents, but in a nutshell, this is what is happening. Um, we have a lot of frameworks around, so just, just to be clear, CrewAI is one of them. I really like it when it's about agents, uh, and that's my, that's my choice usually. But there's, there's also something else. Now, um, another point for me was that, um, I, um, work as a data scientist, but, um, as a software engineer, I need to implement applications. So I need to implement stuff that actually working, that I can use in production, I can send to my clients, I can walk, I can use myself. And the problem that I usually have whenever I work with, I started working with LLMs was that basing everything on prompts or, uh, basing everything on LLM that is not trained by me, it was complicated because of, uh, all these best best practice I was bringing from software engineering. So I wanted to build something that is modular, that that is actually close to the way I was used to work as a software engineer. Uh, and that's also one of the reason why I like to work with interfaces like CrewAI. So, what's CrewAI about? Um, now, CrewAI is, uh, an open source tool, so you can use it with Python. There is also an enterprise version, which is not part of this token, and I'm, I'm, I'm actually, I've never used it. I'm not really interested in it. Um, what you can do with it is working with agents, orchestrating agents in a very simple way without taking care of our, these agents are built, how this reasoning is built under the hood. You just have to focus on the business problem, and you have core concepts like agents, tasks, and crews. We will see what is it, implemented under the hood by someone else, so you don't really have to take care of all these concepts. I like to really focus on this part and highlight the things that are provided by CrewAI. Uh, because these are all things that you don't have to implement yourself, and we will dive a bit into the package and you will see how complicated it is to, um, reach this point if you have to work on something like this and build it from scratch. When do you need it? Um, first, when you need multi-agent collaboration. Uh, when you need to work with an LLM and you need a good interface, I think that's also the case. Uh, when you want something that is scalable, we will see that you have if you have to work with agents. Working with this library makes everything super scalable, so you don't have to, uh, take care of, uh, very weird refactoring and, I don't know, something super exotic to fix your LLM application. Now, let's have a look at, uh, the components of this library. Um, I think that since we're gonna look into the interface and not the actual implementation, we're gonna focus on the business use cases around this, uh, package. First the agent. The agent is this, uh, so-called autonomous unit. We, the agent, we can perform tasks, we can make decisions, uh, and we can communicate with other agents. What happens when you define the agent is that you have this role, uh, and you have a goal, and then I back story. Here you, you can already see that we're not telling anything about, uh, we're not, we're not telling the agent, uh, what to do exactly. Because this is implemented in another class, which is the task. With the task, we define what the agent is going to do. So we're basically taking this out, we're not writing everything in a huge string, but we're taking this out, and if we want, we can also use the task in another project, we can assign the task to another agent, and this is up to us, and everything is separated.

[10:44]So we, as you can see, we, we started using some modules and this is already scalable. In the, in the definition of the task, we can define the description of the task, the expected output, this is also very powerful if you are working with prompts, and if you're working with LLMs, you know that this is, uh, this is a, a very nice to have. Um, and then the agent, uh, this task is gonna be assigned to, and of course, if we want, we can also take this and assign it to another agent. And then we have the crew. Uh, with the crew, we're basically putting every everything together. So we're saying, okay, I have a set of agents, I have the tasks that these agents have to perform, and putting everything together within the crew. And in the crew, I define, uh, what are the agents for the scope that I have in mind, uh, the tasks, uh, which kind of process we will see what it is, the agent, I gonna work with, uh, and some other, some other small, uh, uh parameters. Speaking of process, uh, what happens when you work to when you want to create some sort of orchestration? Um, you can do it in a in in a very simple way, you can just use sequential, but if you want, you can also you can also use hierarchical. Uh, this is also, this is very powerful. So when you use sequential, basically, you execute, you execute one task after the other. So you're not doing anything special. Uh, but when you use hierarchical, you can say, okay, I have these three managers with three different tasks. Sorry, it's three tasks agents with three different tasks, and then, uh, because of what I want to do, and we will see an example, I'm defining an agent, a new task, a new agent, which is a manager. This manager, like a real life manager, can actually oversee what the agents are gonna do, and adjust the shot while working on while running the application. The manager is gonna be sure that if you have any constraints in mind, the application is going that direction, so it's going to help the agents to reach the goal. One example is, let's say that you have a very important constraint that is, okay, I want to be sure that the budget is under this, uh, value. The agents are doing something very, uh, I don't know, like very tough, and there is a manager on top of it saying, hey, be sure that the budget is the total budget is gonna be under this, uh, value, because otherwise we're gonna fail. Then, uh, another thing that we can do with CrewAI is tools. I think you, if you, if you have used some LLM frameworks, you're probably used to this concept. Working with tools, it means that, uh, actually, tools are something that belong to agents, to Agentic AI. And the idea is to let your application to use external tools to accomplish something, browsing the web, accessing some external APIs, and so far, so on. Um, it can be done in a very simple way. In this case, in this case, I'm using SerperDevTool. Who doesn't know who knows Serper? Okay, Serper is for browsing the web. It gives a very, it it's, it's uh, you there is a subscription, but you can also use it for free. My advice is to use it as soon as possible because it, it is a crazy tool. Uh, what you can do is creating an agent, in this case, the marketing research analyst, which, uh, thanks to the SerperDevTool can access the web. So he's kind of browsing the web for you. And Serper provides a very smart way to browse the web without using too many tokens, and so far, so on. And this is one of the powerful things that you can do. That's why we call it agent, because they can do more than just relying on, uh, the rug or, uh, what's inside the LLM. Then we have a very nice way of dealing with the memory. Um, this is probably a bit too technical, but I wanted to show what's inside. Create crew memory, this is inside the library is not super helpful, but it's, it's nice to have a look at it. Overall, what you see in the documentation is this. So we have the different types of memory, so if you, if you need a short-term memory, long-term memory, you can deal with it and it's really easy. You just have to provide a parameter to the crew. Uh, but this is what's happening inside. So this basically means that if you want, you can do more. If you want to change the type of memory, if you have a different type of memory, if you're implementing something yourself, you can tell CrewAI, hey, I'm providing a different memory system, and that's it. So also very powerful. Uh, and then, let me take this out because I don't want to, uh, show you my secret files on Google Drive. Um, then what happens is that, um, the collaboration, uh, is, of course, a very important part of, uh, multi-agent orchestration. And, uh, why I have a slide about this with no code? Um, because the code about the collaboration, if you look into the library, is is is complicated, is and is also out of scope here. Uh, what's important is that you don't have to do it. Creating a system with, uh, that that lets agents, uh, collaborate is very complicated. It requires a big effort, and it's not something you do in a weekend. This is all implemented, so the information sharing, the task assistance, resource allocation, all things that have been studied a lot and implemented in CrewAI and in some other frameworks, and you don't have to take care about it. So you focus on your application. Now we are all experts. How many experts do we have about CrewAI? I think all of us, I mean, I, I told you everything, right? I told you everything. Okay. Once again, how many experts? Okay. Come on, come on. You two, I saw you, you are an expert, you are an expert. Great, great, great. Um, this is for warming up because you have to ask questions. Um, perfect. Now, let's move to the use case. Um, as I said, I cannot share too much about what I did, um, in my organization, but I prepared a really nice use case, which is something I used, um, because this is from the first picture I like to ski. Uh, I'm not a professional. I started two, three years ago, and I had a lot of questions when I started skiing. This is a friend of mine laying on the snow. Uh, he fell, and I and I created this picture. So what happened is that I had a lot of questions and planning our ski trip was very complicated. The main reason was that, uh, there were a lot of, um, small things that we have to optimize for, and I didn't really know how to find the best place, how to deal with friends that are living in Madrid. I'm based in Hamburg, some other people in Italy, and it was very complicated to find a place where to go and some other stuff. And at some point, I realized that this was an optimization problem. Uh, one example is, how can I be sure that we're going to a place that is affordable for everyone, is reachable, and at the same time, we have a ski rental place nearby. Things like this. I was doing a lot of research, and at some point, I was like, okay, because of these reasons, um, I thought about orchestrating some agents in order to solve this optimization problem. And, as you can see, these are the main reasons, uh, optimization challenge, uh, try to create something that is reproducible because the main problem for me was that I wanted to go ski. I don't like maybe once, twice per year. So I wanted to reuse this tool whenever I had to. And, um, most importantly, I wanted to use this for something practical, honestly. And this is what I did. So, if we look at this, uh, implementation, here I have, uh, the agents, not not all the agents that I prepared for my, that I actually implemented, because of for the sake of the of the presentation, I decided to take some, some agents out. Uh, but this is the main structure, and you will also see the output coming from this. And as you can see here, uh, we, I decided to create one, uh, agent, uh, that is, uh, in charge of finding the best location. This agent has this backstory, identified the best ski destinations, so far, so on, and, uh, is all about best location. So, it doesn't know anything else about the other agents, uh, and we don't wanna spoil anything about what's happening, uh, inside the other agents, or the other tasks. Then I have one, these are all coming from my needs, by the way. Then I have one agent for best hotel, so I wanna find the best hotel in the place where we want to go. And then I have the most convenient ski shop. In this case, um, I'm basically saying, okay, provide information where I can find the best ski shop. Um, so I can rent my equipment. And, um, I also needed a manager. That's why, um, I told you before that in some cases, you want to have a different process to deal with the orchestration. In this case, I needed a manager because I had a very strong requirement, which is budget. And imagine if I let these agents do the job for me, and they will come up with something that costs 10k for three days. They will probably say, okay, this is, uh, what you were asking for. We provided a solution, but it's not feasible. Since it's an optimization problem, we do have constraints. This is one of those, so we have a manager that's going to make sure that we are within the budget that I have in mind. And what happens is that if something goes wrong, the manager tells the agent to go back, look for another answer, another answer to the question, and then recreate this output until, um, you find something that is feasible. Another reason why, um, working with agent in this case, is a good option, is because if you work with LLMs, what happens is that, as you probably know, LLMs will always provide an answer. And in this case, it's not what I want to do. I'm working on an optimization problem. So I want to be also in the situation where if I say, okay, one of my friend leaves in China, the application will probably say, hey, I didn't find anything that is kind of working for every of you for for all of you, because your friend will probably pay 10k more than you. So I also want to end up in those situations if things are going in the in the wrong direction. So I don't want to have an answer at any cost, as we usually do with LLMs. So, now we move to the tasks. The tasks are really simple here. Uh, let's start with these two. The destination finder, I'm basically giving, uh, all the information that I need to the to the agent in the end for the destination. And then the constraints. This is what I'm going to give to the manager. This is one of the most important because here I'm basically saying, hey, I have a budget and let's try to stick to the budget. Um, final step, we assemble we assemble the crew. Here, I'm basically putting together all the things that we have seen, easy. Um, and of course, I'm using as a process hierarchical because there is a hierarchy. There is a manager that is telling the agents what to do. And this is the final output. This is the exact output of what we have seen before, um, and, uh, that's actually my destination. I did go to Chamonix this year, uh, because of this application. So it did work pretty well. It was a very high risk tell my friends, hey, let's go there because an application told us to do so. Uh, but they, actually, I have, um, they trusted me. I don't know why, but yeah, this is our ski planner from now on. And what can we say about this? Um, first of all, we had a lot of fun looking at this nonsense Python code, and, um, what I really like about this approach is that it's modular. For me, it's really important. As I said, I work as a data scientist, but I do a lot of software engineering as many of you, and if it's not modular, if it's not scalable, it's something that I cannot really pitch to my to my to my clients, to the business units I work for. It's really complicated if I go to the to them and say, hey, uh, this is the prompt. Let's see what happens. No, I need something that I can refactor, I can maintain, it's scalable. Uh, and if we have to change something, we know how to do it. Working with prompts, it can be problematic. Um, it's community driven. I really love that CrewAI now, if you, if you're gonna check it out is actually, uh, in every job listing. So, it's quite famous. Um, and I really like how you can manage the memory. If you want to go deep into the library, if you want to do something kind of exotic with the memory, you can do it. You have freedom, uh, in in that sense, and that's something that I really like. Um, there are also some some some other problems, which are not just about CrewAI. I'm talking about problems that we have with frameworks in general, and these problems are about, first of all, learning something new because you need to every every time you learn a new Python library, it looks like another, like a new life, it looks like you have to start another chapter of your life, and I get it. Uh, there is a lot of hidden complexity. We have seen, we were looking into how the memory is managed, but of course, um, if you don't wanna check how the package works, um, it's okay, but then it it will be, it will be like you have to trust the output. It it will be like a black box. Um, so in in in some ways, you're kind of accepting the framework way. Um, and another problem is that, uh, you need to be aware that it's not always customizable, and you might have integration problems. This is what happened to me also that, uh, depending on what you're what you're going to use, maybe it will not be, uh, fully integrated with whatever you're using, with your database connector, with your memory, something. So sometimes it happens, and CrewAI sometimes is one of those packages that cannot be fully integrated because it's a new package. And, um, there are also some alternatives, um, which I don't like, of course, because I like CrewAI. Uh, but this is, uh, just just to be on the safe side, I'm also showing some of the alternatives. I do did use some of them. Um, LangChain, LangGraph is definitely interesting, but, uh, I think it's too complicated for me. I'm not really as good as you think in the other science, so I, I prefer to go with the easy easy one. Um, and some other stuff. I also really like, uh, Haystack is also interesting, but, uh, I prefer to work with CrewAI when it's about the agents. But yeah, check also the alternatives. And, um, yeah, that's pretty much it. Now, I will ask questions. I'm just kidding. But if you have questions, feel free to ask now, or maybe later, uh, but that's it. Uh, I thank you all. Thank you.

Need another transcript?

Paste any YouTube URL to get a clean transcript in seconds.

Get a Transcript