Crew AI Full Tutorial For Beginners - Build Your Own AI Agents | Tyler AI

21.8k views9781 WordsCopy TextShare
Tyler AI
This is the full Crew AI Beginner Course! In this course I will show you how to create Crew AI Agen...
Video Transcript:
hey and welcome to my full crew AI beginner tutorial by the end of this video you're going to be assemble your own crew of AI agents to solve any task that you need now we're going to do that by understanding what the crew AI framework is then we're going to dive right into our first project then we'll take a step back understand the main Concepts briefly and have a few projects for us including creating our own custom tool for our agents we'll use AMA so that we can use a local AI model and you won't
have to worry about an open AI key and will use a PDF rag tool that's built in with custom crew AI tools all the code and resources that I'm using for this tutorial will be in a link in the description well let's go ahead and get started and understand what the crew aai framework is all right well what is crew aai well crew aai is an agentic framework that allows us to create agents to help us solve simple or complex tasks AI agents will assume roles they'll share goals and they'll operate in a cohesive unit
much like a crew and will give each of these agents a task such as developing a game creating a blog post or planning a whole 7-day trip together which leads me into the first example that we're going to look at is the trip planner crew and how it works is it's going to ask you a few questions whenever you run it the trip planner crew I'm saying that I want to be traveling from Miami I want to go to Paris in one week in August and tell me more about food and entertainment and what it's
going to do is actually go out to the web search for everything we need to know including hotel prices U restaurants flight pric prices what we can actually do there in weather among other things right so if we scroll all the way down here it's doing a lot of work right here right it it's really doing a lot of work but if we scroll all the way down it gives us a 7-Day itinerary for Paris for the first week in August you know it's going through everything such as uh what the average weather temperature is
seasonal events and attractions and it actually starts the web to get all its information and make it into a nice readable format for for us so we didn't have to do any work it did all of this for us so if we scroll all the way down then it gives us a full budget summary includ including the flights food and total estimated cost amazing stuff I also executed a game builder crew that gave me all of this python code to create a tic tac toe game so I ran it and it works you know and
they made sure they the agents make sure that the code works you know the whole crew works together and then it's an actual playable tic-tac-toe game and this is amazing this is what the power of an agent framework can do for us so let's get started and create our first crew all right well let's create our first project so I'm going to use pycharm as my IDE or integrated development environment you're more than welcome to use whatever you like I know a lot of people like vs code I just like py charm the Community Edition
which is the free version makes it simple uh so I'm going to open it up and choose to create a new project I'm going to name my crew AI course for the environment I'm going to choose cond because whenever I've used virtual environment I've actually they had issues installing crew AI because of the chroma DB Library I spent some time on it spent too much time on it trying fixing fixing it so I just switched over to cond and it worked or just fine right I'm going to use 3.11 version and that's all you need
to do and I'll have a link in the description to download uh cond uh it's really simple to download so then after you're done click create okay now it's done whatever IDE you're using open up your terminal so in pides F it's in the bottom left here so I'm open this up and I'm going to type in PIP install crew Ai and this could take a minute there's quite a few libraries especially um as this framework evolves it's going to add more things so just give it a minute and we'll be back okay we're done
you can type in clear to get uh rid of everything that's in your terminal well actually doesn't get rid of it it just hides it um because you scroll up you can see everything so on Mac it's a command K it might be control K and that actually gets uh rid of all of the dialogue um and kind of re refreshes your uh terminal so we can go ahead and minimize this and create our first uh python file so right click on crew AI course go down to python file just call it main whatever you
want to name it and we can begin now there's three major components to this uh to this first project that we're going to create and that is the agent the task and the crew okay and then we kick off the crew and it does everything for us um we'll get you tools later but first we need to have our Imports so we need to import OS and then from crew AI we can import the agent the task and the crew class and then we are going to get to AMA in a little bit where you
can use a local AI model you don't have to then you don't even have to worry about open AI but for now we're going to work with open AI so what we need are the environment variables so environment os. environment and then we need to say open aior API _ key and I'll show you in just a second how we get our key and then we also need to set the a uh the model for open so open AI model name and then I want to use your use whatever one you want right you can
use 3.5 turbo that's probably the cheapest one uh but I'm going to use 40 as it's not much more expensive okay so let's go ahead and get our API key now so if you go to platform. open.com uh you if you haven't logged in already go ahead and create account or you know log in whatever you need to do but after you log in if you go to your settings here uh and then you on the left hand side you go to billing you know you can see how much money you have left if you
don't have anything you know for this course you will need you will need a couple dollars um so go ahead and put some money in here just for a little bit we are going to switch to AMA like I said um but then once you're done with that or if you already have money in there go to your dashboard go to API keys on the left hand side and then create a new secret key so for this one I'm just going to say crew Ai and then you're going to copy the API key it gives
you go back to your project and then just fill this in and of course this will be deleted by the time you guys see this video uh but now we are ready to create our crew so the first thing is we need to create our agent okay so we're going to say info we're going to call it info _ agent and then we just say agent we instantiate the agent and now we have to give it there are three parameters of the agent class that we have to give in order for this to run all
right that is well actually you can come into the agent real quick and we'll go over these um soon after we finish this uh little project and then I'll kind of go a little bit more in depth into each of them uh we'll see a little bit more but uh what you need are the role the goal and the backstory okay so the role is kind of like the name the goal is what you want this agent to do like what's the objective what sorry about that the the objective like what do you want this
agent to execute or perform for you and then the back story is to kind of give a little more context to the model about this agent so if we go back here so we know we need the role and I'm just going to say INF information agent and then for the goal we have to give compelling information about a certain topic and I'll go ahead and paste in the backstory as well okay so you love to know information you win most of the quizzes at your local pub you may know some people like that I
certainly do I'm not one of them uh but so that's what this agent is so now we're done with the agent okay there are more primers you can give we'll get to you later but for now this is all you need okay so the next thing is we need the task and the task is what we want to give to the agent to perform so we're going to say task one is equal to task and then we again need a couple parameters here that we have to have for this to run so the first one
is the description or what is the actual task so this one is to tell me all about the blue ringed octopus so if you don't know anything about it you're about to find out and then a kind of a new it was an optional parameter but we now need the expected output so expected output um and what this is going to do is say Hey whenever you're done with when you have this information how do you want to present it and this is kind of what we want to tell it so I'm going to say
give uh me a quick quick summary and then also uh give me let's say seven bullet points describing describing all right and then the last thing is we need to assign this task to an agent so we can say agent equals info agent and we're done we have created our agent and our task all right and then the last thing is we need to assemble our crew so we're going to say crew is equal to crew and then we need to assign the agents so you say agents is equal to and even though we only
have one agent you still need to assign it as a list so we're going to say agent or info agent uh comma and then we need to say task equals and then also as an array you can say task one again I know we only have one task but it needs to be in a list format then I'm also going to add verbose and what this is going to do is as we run this you can kind of see a little bit more of the output of what's Happening behind the scenes as after we instantiate
the crew or kick off the crew so that leads me to the last thing we need is we're going to say result is equal to crew do kickoff and that's it and that's all you really need um you can you see a lot in the examples they'll have like U let see they'll have like a bunch of these right and then you can say print result you just print result okay so when we run this now okay if everything if I've shown you and everything has been correct we have the uh API key the model
we want to use and that's going to go ahead and be injected as the environment variable and the agents are going to know to pick that up and use that as the model what we can do now is just run this so we can right click on Main go to run or open up your terminal and we're already in the course right so we can say Python main.py and go ahead and run this okay so I ran this and what we have is the debug this info this is because verbos is set to two we
see more information and so I'm actually showing you this error because I used 40 but it didn't like that um if we scroll down a little bit in this a it said the model produced in valid content so I'm not going to we look into that much deeper so I just Chang this to four and then after I ran it again this is where we see this is where I can explain now U so we have the working agent so it's the information agent this is um this is the start of the crew so then
the starting task is tell me all about the blue ringed octopus okay so now the output is this right here so it has The quick summary of the blue ringed octopus which if you didn't know was one of the world's most venomous um animals and then also gave seven key points about it and the reason it did a quick summary in seven key points was because if we look um at the task here the expected output I said give me a quick summary and then also give me seven bullet points describing it I mean I
know they're not bullet points um but still it's it's really close to exactly what I asked for um and then we we have the print then we just have the two print statements here so you don't actually need these but if you have if you don't have verbos to something besides zero then you will need this because we only see um o sorry we only see the what's in green here from the information agent because we kind of have it set to see um what's happening in the background okay so we just coded our first
crew awesome job you if you stuck with me great okay just pause in a couple sections if you didn't quite get there yet but that's okay this is I know this is a very simple crew we're going to get to a little more complicated things but now what I want to do is uh after you've seen it work you coded something let's take a quick step back and just look at the agent task and crew and also the tools really quick then get back into coding some other things now that we've seen code for a
simple crew in the crew AI framework let's go over the five Core Concepts and these aren't very hard to understand but we need to go over them and we've already actually coded three of them the first one is the agent now an agent you can think of as just a member of a team or in this case a member of crew and they have a particular job to do and it has a bunch of attributes that we can assign to it to kind of help guide on what that job is and this leads us into
the next concept which is a task now in the crew AI framework a task is just something to be completed by the agent we can give a description of the task and then the agent will know what to accomplish and then the task has a bunch of attributes that help guide what the task is going to be the third concept and I think is also an important concept that we are going to to go over in the next coding tutorial is a tool a tool is just what helps an agent perform various actions a tool
can be something as simple hey I want to search the web or give me a summary of this PDF in my local directory and crew AI makes it really nice to integrate tools not just custom ones or ones that are already in crew but others such as Lang chain Lang chain already has a ton of tools that we can choose from and we can easily import these in to our crew AI framework to use but cre AI also offers its own tools and some of these are rag tools such as a directory search or like
I mentioned the PDF search the fourth concept is pretty simple and this is called the process and this is just how we orchestrate the execution of the task by the agents there are currently two ways to have processes right now and it's either sequential or hierarchical by default you will be using sequential but you also have the other option we'll see how to change this when we build the next crew which brings us to the fifth Concept in the last one is the actual crew and all a crew represents is a collaborative group of Agents
working together to achieve a task and a crew also has its own set of attributes but essentially we just give the crew we assign all the tasks and the Agents needed for This Crew okay well let's go ahead and create our new crew and this time we are going to have a Custom Tool and we're going to add some more attributes to the crew as a whole so you can kind of see what they do and we'll end up saving the result to a local file so in your course directory go ahead and create a
new python file we will call this tools example name it whatever you'd like uh let's go ahead and have our import so we'll say import OS and then from crew AI we need to import the agent the task we also need to import the crew and then we're also going to have the process okay and we'll get to the tool in a few minutes and I'll show you how the process works when we assemble the crew at the end now instead of if you go back to our main python file we do need the API
key name and the model name but instead of just copying paste pasting this right here which you certainly can do a little better way so we can abstract the actual property values we're can create a new file so in the project directory go to new go to file and name ITV okay and what we can do here is actually just copy and paste the same but this is going to allow us to have a separate file with the values for the key and the model okay so then if you need to change anything you can
just come here and change them you you can change them here and you don't Al also have to when you push to GitHub you can just get ignore the EnV file but we'll still have the logic in the tools- example to actually retrieve these and now how to retrieve them from ourv file that we just just created we do need to import another library and so what we're going to do is import or from EnV import load. EnV and then we can say load. EnV so we can call the function from there okay and what
this is going to do is load the property values from the EnV file and then instead of having the hardcoded key and the hardcoded model we can say os. getet environment so we can get the key for open aior API key and we can do the same thing for the model name so if you if that was that's kind of a lot at first all this is doing is we're going to separate um you know keys or secret keys that you know we should that shouldn't be exposed to aemv file and then in the main
file that you're actually working on you can call and get those property values like this now because this is going to be kind of a math example and we're going to create a tool to do this I do want in the terminal when we run this for somebody to give us a math equation so in order to make that happen I'm going to create a couple or create a print statement so we're going to say welcome to the math whz and then we can say math uncore input equals and then input what is your math
equation ah what what happened there okay and then what's this going to do is whenever you input this we're going to do something with this variable which we'll get to all right now the next thing that we need is we need a first agent and for this agent we're going to call this mathor agent equals agent so now we've instantiated the agent class we need to give it the attributes like we did previously well the first one is the RO right this is the name of the agent so we're going to say math magician and
then we need to give this agent a goal what do we want it to do so we're going to say goal is equal to you are able to evaluate any math expression okay and then we also the last attribute that you absolutely need to have is the backstory and so we're going to say back story is equal to you are a math wiiz and if it's in all caps it has to be true and then another one we're going to add is verbose equals to True um this is just allows us to see more what's
happening in the background all right you this is by default false um so you don't have to do anything with this but I'm doing this here just uh as the core so you can see what's going on and then the last one which is going to be new is going to be the tools attribute and then this is also a list because you can add you can give more than one tool to an agent but we're going to call this calculate so this is the tool that we're going to create in just a minute and
we're going to pass it into this agent okay so in order to create this if you've done a past crew aai tutorial you you typically created a class and then you use the link chain tool and then you created a function with The Decorator and you know or maybe you haven't at all right but it's been updated so what I'm going to do is I'm not going to create a class I'm going to create a file and then just basically have a function okay and we can call that function uh from this python file and
use it so what we need to do let's just let's just go an example right let's just do it so create a new python file let's call this calculator tool and we do need One Import from here so we're going to say from Lang chain community. tools import tool now if you're using uh like I said if you're using a previous one Lan chain score Community you'll get like some deprecation air if you try to run this and you're not using this and that's fine it'll still run but this is kind of like the updated
version and then like I mentioned you don't actually need to create a class which you still can do I have done it in examples but we're going to I'm going to make it a little less verbose so we're going to say at so you need still need the tool decorator so at tool and then give it a name and now we can go and create the function so we say Define uh calculate CU that's what we named it and then we'll pass in some equation right and you also need a dock strings to kind of
give the uh the AI agent or the llm really a little more Direction on what this function is supposed to do so we're say useful for solving math equations okay and then we can go ahead and just have a simple return statement we can say this Returns the eval which is eval math evaluation function the equation so we'll just pass in the equation here okay and this is I mean this is very simple I know you could I would add like some sort of like try catch um so that you can maybe some syntax ER
or some other typee of error that you could give right maybe you're not giving any numbers but um I would do that but for now this is just for this course example we're going to make this simple so we're going to say return eval equation and that's it you've just created your first tool now if we go back to the tools- example our python file let's just go ahead and we can now import this so from calculator tool import calculate and there you go we have now uh given the calculate tool the math agent so
that it can use whenever we go to run this all right I just want to create the next agent so we don't have to go through all the boring stuff again you so you can pause this and go ahead and code this yourself or it'll be in my GitHub uh but I just created a writer agent that's basically going to um take whatever the result was from the math agent and we're going to end up making it sound really nice on how we solved it we went over two concepts here again went over the agents
and then the tools the next one is the task that we need to give to these agents so what we're going to do first is say task go ahead and give some space say task one equals task and again we need a couple attributes so we're going to say description is equal to and then we're going to say f for format then quotes and what we're going to do now is this math input whatever we give in the terminal I want to give here as a variable and then this will be what will end up
be going to the math agent to solve and then the expected output again if you were using a previous tutorial on crew aai this was not necessary this was was just optional but now it's not optional we need to have it so we're going to say expected output and this is just give full details in bullet points you can make this however you want a summary bullet points um a list of something else whatever it is and then finally we need to assign this to agents so we're going to say agent equals math agent okay
so for the next task which is going to be for the writer agent we had the description and we had the expected output and then we have a new one called output unor file and what this is going to do is save the result that the writer the writer agent gets into this math. markdown file and what I've noticed is if you in the expected output if you say you specifically save it in the and the the extension that you want to so just mark down then also say that here and then what it will
do is add triple tick marks um at the top in the beginning and that'll be kind of like the code output even though this isn't code but this will be like the output put in markdown don't add those it'll kind of mess up with the formatting which isn't a big deal you can just delete it uh from the actual file but this will just help you out okay so we now have our task for the agents what we need to do now is assemble the crew and tell it what process that we want it to
do so we're going to say crew is equal to crew then to assemble our crew we need to give it the agents this is going to be a list so we're going to say mathcore agent and then also the writer and then for the task we need to give it both tasks also as a list so task one and task two now what we didn't do last time is there's another parameter called process and this is where you can give it the type of process whether it's sequential which is that that's what the default one
is or hierarchical which um we're not going to get into uh right now but that's just a separate one and but like I said by default it is sequential but just so you can see what it is so say process. sequential okay just so you can understand that and then again we're going to say verb boast equals 2 so we can see everything that's going on and then we are almost done we we just need to kick off the crew so we're going to say result equals crew. kickoff and then let's go and print this
out as well so print result okay now what we can do is run it and see what we get okay so I've ran it it's asking what is the math equation let's do like what those like Facebook ones where it's like + 4 - 2 uh time -2 / 4 let's let's see what it gives us all right so the the working agent is the math uh math magician the task you know we just gave it the input so this is just the input that we had and now it what we're doing here uh is
saying this is a straightforward arithmetic problem okay well I wouldn't tell Facebook that and the action is calculate right so this is the tool that we're going to use and the equation is this that we're going to pass in to the tool so it's saying the result is 23 I don't know we'll see um but then so the final answer is 23 so it finished that part of the chain now the next working agent is the writer so what it's doing is it says need to understand how the expression was evaluated to reach the result
of three so they're saying they're going to out delegate the task to the math math magician who can explain step by step okay so it's basically looks like what it's doing is it's taking uh it's saying the first step is giving like step by step right so the first step was to take 2 * 9 it uses the calculate tool again to do this and it kind of breaks down the whole equation step by step on how it got there until finally you got to 23 right so it said I have calculated the addition operation
22 + 1 to get 23 okay great so the final answer is the are these bullet points on how that happened so this is the this is the result of how we got there and then the uh the writer is going to say now that he has a he's going to give a detailed explanation of this evaluation so this is the final answer so the writer the output is the mathematical journey of this whole expression comes all the way down here right and then this is the output and if you noticed there is let me
minimize this there is a math uh markdown file here so if we click this when we open this up here is uh so I'm sorry on the right hand on the right hand side is the like the actual markdown as like we would want to look at it so it's saying here's the whole journey pmas probably the only thing here I really remember um but it goes through how it solved the equation and so we just had the agents um tell us you know in detail it solved by itself using the custom tool that we
created and you know that's pretty amazing right this is kind of a small step into what agents are really capable of okay so for the next section I'm going to show you how to use a local AI model using olama I'm going to show you where ol is or how you even get these models it's pretty simple and straightforward and then we'll integrate that in with another crew well the first thing we're going to do is in our course directory let's just copy the main.py function and then paste it inside of our directory and then
let's just rename this main dasol Lama local AI okay so now we have a copy of the main python file this is the very first one that we did okay now there are a couple different things we need to do here and the first thing we're going to do is go to ol. the website and I want to show you how to download AMA okay once you're at ama.com you'll see this big just well not big it's kind of small button but it's pretty minimal website so you just click the download button it'll download the
software for you and it should auto run if not just go ahead and doubleclick the executable or whatever machine you're on to start up AMA and for instance on my Mac up at the top of the screen you can see a little llama symbol and that means that I have a local AMA server running now the next thing we need to do is uh download a model using AMA so we can run that with our crew so what you can do is while you're in the website you can come up to the top and search
for models I'm going to just go ahead and search for 53 or you you can even just click U the models tab here so you can they kind of have like the updated ones or the more popular ones u in the front so they have llama3 quen 2 and 53 now I'm going to use a smaller model so I'm going to use 53 so what we're going to do is just click on 53 going to come up to the page with the models and we have the 3.8 billion parameter version and the 14 billion parameter
version I'm going to use the 3.8 uh for my machine so it can actually handle this so what we need to do is actually pull this model onto our system and we download it and then we can use it so back so back in intellig or whatever ID you're at open up your terminal and we're in the we're in the crew AI course now you're going to say oama pull and then you're going to go and pull the name of the actual model so in my case I'm just going to say 53 or you can
specifically um tell hey I want the 3.8 version so I'm going to copy this I'm going to say AMA pull and then just paste that here going to press enter and I actually already downloaded it and tested this but it this will take a few minutes and it's downloading all the everything necessary for this model to run on your local computer now what's happening is this is already running we already have a server running and all we need to do now is just give a couple properties to the crew and we're good to go but
first we need to import one more thing and I'll explain why we're going to do this so we're going to say from L chain laying chain open aai import chat open Ai and this object is going to we're going to give a couple of parameters to this object and then we'll use that and inject it into our agent and how we're going to do that is we'll say we'll just create a variable we'll say llm is equal to chat open Ai and we're going to pass in two things here we're going to pass in the
model say model equals and this is going to be just the model name that we pulled right so you're just going to this the same model name that we pulled so you're going to just copy and paste that here as well and the next thing we need is the base URL so we can connect to our local server and in ama's case you know if you're using like LM Studio or some other local server that that this URL will change but for AMA it's HTTP localhost 11434 slv1 and then next thing we do is we
can get rid of this model name we don't need that anymore we still need to have some dummy open AI key here so we can just type SK produ 111 it doesn't matter you don't actually need a key we just need to have some placeholder and then the last thing we need to do is we have an agent right so now we need to tell this agent cuz right now it's going to look at the try to use the open a key and we don't even have a model an open AI model name anymore so
it's going to fail all right even if we had the model name it's going to fail because it doesn't recognize um this key here this is an invalid key so there is another attribute inside the agent class so if we add a comma at the end of backstory you can say llm equals llm okay and this is the reason why I created a separate object for this particular llm and that's because let's say I wanted to copy this I say lm2 but I wanted to use the 14 billion parameter model this time so I would
go ahead and download the 14 billion 14 billion parameter model and now I could have if I had another agent I could instead have one agent with the 3.8 billion parameter model and then another one with a 14 billion parameter model but we're not going to get to that right now just going to show you how to run this locally and you know what instead of having the blue rink octopus let's pick another Marine let's do the Box the box jellyfish let's do that and the last thing is you could do this a couple different
ways but I'm just going to show you this way is we need to have the open AI key before the chat open AI model so that it knows to just get our uh OS in environment variable even though it's a dummy key this will be given to the chat open AI so it has a placeholder if not you'll get an error so this line just has to be before we instantiate the chat open AI object and now we are good to go so we're going to go ahead and run this and the thing about it's
really nice to have local AI models the problem is is if you don't have the hardware to back it up and this is why I'm using a 3.8 billion perameter model and this is still going to take a little bit of time on my machine is if you don't have the hardware to really be able to run these things then it's going to take a while and it could be a little frustrating which is why a lot of times when I test things I just want to use a 3.5 turbo model because it is so
cheap and it's also quick I don't have to worry you if I you know mess something up I don't have to wait 5 minutes or more sometimes depending on the muddle um to get the response and then change something again so that just keep that in mind if you have a good enough computer or if you have a decent computer I would use a smaller model if you have a much better computer um then you know you can use some of the larger models if you want okay so it finished uh I think that took
yeah it took like about two and a half minutes um to complete uh but so the same thing here we have the working agent we only have one it's the information agent and I want to tell me all about the box jellyfish so it gave me a summary and then it gave me seven bullet points uh more bullet points about it and so then we just also printed out the same output and great so now what we've done is we just used a local AI model paid nothing and I know a lot of people worried
about that we paid nothing and we still got a good result now of course the results will depend on these models right not all the local models that you use especially if you use the smaller ones they might not give you the best results but again it is free okay great so from now on you know how to use Lama to use any local AI model that you want there are other uh there are other pieces of software such as like LM Studio or text gen webui that you can use I'm not going to cover
them because I I do like o Lama it's simple it's easy to use and you know that did take very long but what I'm going to do now for this next crew that we're going to build is we're actually going to use one of crew ai's built-in tools for Rag and we're just going to use the PDF Search tool okay well what we're going to do right before we create our new PDF rag crew I want to make this easier on ourselves and the way we're going to do that is there's actually a crew AI
examples repository it's a separate one from the same guy and inside of here there is a starter template project and what this basically does is it gets rid of all the boiler plate code that you have to write every time whenever you're creating the agents the task um if you need any custom tools Etc right I don't think it actually has the custom tools um but whenever you create your environment uh properties you know all of that stuff and then you kick off your crew it has a template here for you so what I'm going
to do is I'm going to put this into uh the crew AI course on my GitHub update because there are a couple things that aren't updated that you will need or it won't run properly and then we're going to use that as our starting point for the PDF rag okay and here we are we have the starter template now in this course project so this time what we're going to do is just start from here and let me just go over really quick and explain what everything does right so we have an agents and a
task python file they kind of do what they say this is where we create our agents and then the task. py is where we create our task so for instance if we go in the agents here we can see that we have a class we can actually def actually already defines a GPT 3.5 turbo a four and an O llama using the open Hermes model and then you can use this on any of the agents down here right so instead of uh the 3 .5 you know I could use four here Etc right or you
can Define your own this is just a starter template and when we go to the task this is kind of the same thing right we it returns a task object and it has the description and the agent and I'm going to update this so it has the expected output which is what you will need also um and this isn't updated for that or else it won't run right but what this does is we can just modify the info in these classes and then we don't really have to do much else right besides refactoring names and
other things like that but we don't have to write the Border plate code and then in the main python file you know we won't need all of this information either right this is just a template but uh in this run function you know we retrieve all the agents we retrieve all the tasks you know we can get the uh Define the agents here we can Define the task here we create the crew just like we've done and then we say crew. kickoff and then return the result and then down here is just kind of you
know some print statements on um actually you know running this that has couple inputs you don't need these again this is just a template but what this does now is you don't need to worry about um all that boilerplate stuff anymore we can just start from here which is what we are going to do okay so all I've done so far is not much I've went ahead and you know you you'll have this in my GitHub repository as well or you can pause this and you know make up some some agents which I do recommend
doing right you don't have to copy me verbatim you can make up some of the stuff yourself see what you get but uh these two agents that are here you know I just made one as a PDF analyst um I gave it a backstory this DM just takes care of I think it take care of whites space or um the trailing and leading spaces um but so don't worry about don't worry about that too much um but I gave it a backstory a goal the tools which we're about to do the PDF tool um the
llm I'm going to let this one use GP pt4 and the writer agent I'm just going to let it use 3.5 turbo and this is a good example of being able to use two different models right you don't have to use the same one for every agent and what what we have here is we again we do need a tool for the PDF agent but we haven't create this yet but we're about to is the PDF tool right so how we do that okay so the first thing in order to even get the PDF or
all these other rag tools or other tools in general that are a part of crew AI already we actually need to install them so we're going to go to your terminal and you're going to type in PIP install and then crew AI tools when you press enter this is then going to install the other things that we need uh to make this work you know most of the um most of everything the requirements are already satisfied but we are going to need a couple more things right especially for the rag part you are going to
need to deal with a chroma DB which is what I believe they use okay so when that's done we can now import the PDF rag tool so at the top let's go from crew aore tools import and then you can see there are actually going to be a bunch of them right even here's the serer dev tool and the scrape website tool but we just need the PDF Search tool okay now we just need to instantiate it to be able to um use it as our tool so now we can come down here inside actually
I think just inside this function is fine we can say PDF _ tool equals and then we just need to instant initiate the PDF Search tool and now it recognizes it recognizes the PDF tool and that's all we need to do right this is an internal crew a AI tool and that's it and I can go ahead and get rid of just some things up here so it makes it a little little neater okay but now we can go to the task and I'm going to go ahead and fill this out and you can maybe
fill this out too if you'd like okay so now for the Tas all I've done is I've just kind of come in here renamed the task to PDF task and let's say writer task and then in descriptions I said I want exactly what I need to know from the rag tool we'll use we'll pass in the var1 and this will probably be an input whenever we go to run this from our terminal and then basically I've added the expected output for both of them which again is what we need and that's it right the these
functions are we're going to call from the main python file and then the agent that we pass into each task will be given here and then the last thing we need to do well there's a couple more things we need to go to our main python file we don't need we can if you're using py charm you can kind of highlight over the Imports and you can say optimize Imports and I'll kind of take care of all that for you I don't need duck ducko I I don't need that at all I know that we
don't need the opening organization um get rid of that I don't need the second variable we're only using one um the we need to change now the agents. PDF agent and then agents. writer agent in the custom task one we can say task task. PDF task we don't need the second variable and then for this one we can say the writer task okay and we just need to pass in the agent right and these agents are what will get passed into the task so it knows which one to assign to so let's go ahead and
make let's go ahead and just change these as well so it kind of makes a little more sense so writer um agent I know they're kind of the same name but it'll just help uh clear things up a little bit okay so the PDF task here okay and I'm not really worried about the the task task one task two uh we can just rename these as well and then task two okay and then we are pretty much done oh I don't we also don't need var2 we only have one and you know that's pretty much
it the last thing we need to do is actually set up our uh API keys and that's it so let's go ahead and do that right there's an there's a _ example we don't need that we're actually going actually what we're going to do is create another EnV file that's just the example but I can take this and then let's call this say equals and then I just need to give in my API key which I already have right I have that from a previous uh crew so let me just copy this put this in
here and then let's let's see if this runs okay I don't think I think this decouple I I think I've already tried this tried this before and let me just see if this runs uh I know it's saying it's an air and I don't have that but uh might be you know actually let's just go ahead and install this package I think it's uh pip install python uh decouple I think this is probably the last package that we need and well I forgot one really important thing is that we need a PDF so let me
go find a PDF I'll add it to the project and then let's run it all right well I've downloaded the gp4 archive paper it's about 100 pages long and then uh I think what we really need to do I I think we can do this as is you don't need to actually give anything to the PDF Search tool but uh what we can do is give it the exact location of the PDF in the name so I'm going to just right uh see refactor rename copy that and then I'm just going to put this here
okay now we can finally run this so go to your main uh main python file and try to run it okay so what I've done is so I've ran it it you know enter the first variable and I asked can you tell me about contamination on professional and academic exams and that sounds very specific and that's because it is and on about page 29 of the paper um here is a small section about it and I just kind of want to see if it can give me something about that okay so as you can see
it's inserting batches into chroma DB so here we have our DB that's now created right and now we had a c senior PDF analyst um you know we're asking it can you basically tell me about the contamination whatever I'm talking about here right I I don't really know but um so the relevant content so what we're doing now is it's trying to find a similarity search so it's getting relevant content based on um hopefully what we find in the uh PDF so let's look here okay so what I okay so I I kind of did
some scanning of the relevant content here and it didn't get everything from this section it kind of took uh part of these last three sections it took it took all of this um and then it took it took some you know it took some information from this table which was on page 3130 it took some from this one too so basically what I noticed is it took some of this information here uh I think it took all of this and some from a couple of from this section and then it went to this these tables
and tried to find relevant information as well might not have been super accurate but that's okay right it did give me some information right um and so the it has the comprehensive analysis this is the task and you know we had the final answer right it detail covers various aspects blah blah blah it's this kind of a full analysis like we asked it to okay so now the senior PDF analyst is done it has the task output and now we start with the writer so take the input from task one and write a compelling compelling
narrative about it well in this input right has uh from the previous analyst the task is to summarize um you know this was the task to summarize the rag tool PDF and the context is from the previous agent right the the senior PDF analyst so now the the writer is going to have the context that we got from the PDF inless and we're going to go here it's going to it already you know search and found um this information and the writer then has the final answer so we have the title which we asked it
to it gave us a summary it gave us bullet points and then the TLD drr okay and now uh oh so here is the here's actually the result right the title summary um the bullet points and the TLD drr okay so we got it to work we got the rag PDF to fully give us everything that we need and it did um generally give us simil similarity search in the PDF and it was 100 page PDF right so it wasn't necessarily small PDF I know they're bigger ones hey and thank you for making it to
the end and I hope you are able to create your own cruise this is not the only AI agent framework I actually have two more courses one of them on autogen you can check that out here and all the things that you need for this course will be in a link in the description deson join my Discord if you have any issues and let me know what you've created thank you for watching I'll see you next video
Copyright © 2024. Made with ♥ in London by YTScribe.com