How To Use AI Agents To Do ALL Your Work - Full CrewAI Course for Beginners

9.7k views28531 WordsCopy TextShare
Tyler AI
👉 Join My Skool Community: https://www.skool.com/the-ai-agent-5174/about 👉 Book With Me: https://c...
Video Transcript:
I'm going to teach you the full crash course to learn crew aai and become a master by the end of this video every day I spend hours reading and replying to emails however with the power of crew aai I can limit this to under 15 minutes so to start off let's learn crew aai well crew AI is an agent framework that allows us to create these agents to help us solve simple or complex tasks AI agents can assume roles they can share goals have backgrounds and operate in a cohesive unit much like a guess what
well-oiled crew you can have many agents do different things such as develop a game create a blog post or give us a trip planner but what is an agent and what is a task in the realm of crew AI well an agent is just an autonomous unit that can perform tasks make decisions and communicate with other agents and when we go to create these agents they have many different attributes the ones that you need to have are the role goal and the backstory so the role this is just what is this agent designed to do
what task is it ready to accomplish the goal is just what is the objective of this agent and then of course there are other attributes that we will go over later but these are the important ones and here's what some simple code looks like to create an agent we import the agent from crew AI create an instance of that and then we give it a role goal and backstory in this case this agent is a data analyst and we also see that there is a tools property or attribute given to this agent and they're just
giving my tool one and my tool 2 tools are there to help the agent accomplished the task and we'll go over that later now that was kind of the previous way to create an agent and you're more than welcome to still create it that way but this is the newer way that they have given us or allowed us to create agents so in this instance we have a defined poem raiter python function that's all this is but it's returning the agent class and inside this function you can see that we say return agent and we
give it a configuration and this configuration is going to point to another file where that file has all the properties for this agent such as the goal role and backstory now a task in the crei framework just a specific assignment to be completed by the agent and much like the agents the task has all these attributes that we can give to the task object so for instance the description this is going to detail the task purpose and execution for the agent and then you have the agent attribute and we have to assign this task to
an agent again here's example code of what a task would look like we import the task we create the task object and we give it the description in the agent in expected output and also like I mentioned before that was kind of the previous way to do it which can still work but in the newer way you can see we have another python function called Define right poem and it's going to return the task object and again it's going to be pointing to a configuration file that has all those properties there defined and finally to
wrap this up we're going to go over the crew object this is what brings everything together so when we create a crew we have to give the task and the agents and the process so that it knows how to put everything together so we can kick off this crew and then run it now here I decided to give you the newer way and much like the other two for the agent in task we have a defined python function that's called crew it's going to return a crew object it also has a decorator at crew and
then when we return the crew object we have the agents and the task and the process defined here by the way if you want to join a community that's learning how to use AI agents how to develop them and use them for business Automation and to save time and money join my school you will be with likeminded people who want to use AI agents for real world purposes whether that's personal or business link is in the description look I know that was a little bit of explanation a little bit to take in especially you haven't
worked with the crew before but the best way to learn is just start coding so let's go ahead and create our first crew the first thing we need to do though is create a project so I have created a folder called Master crew AI course this is what will be in the GitHub whenever you are going through this course as well but what I want to show you first is how to actually set up your environment and if you already know how to do that or you do it your own way you can go and
skip this but if you aren't sure if you want to do it my way let me show you how I do it I like to use the cond environment so in order to download that you have to go to anaconda.com then when you come here you can see there's a free download button you click this and it looks like you may have to provide your email to download all this but you don't there's a skip registration uh that's kind they're kind of hiding it and then you come down you come to the download page and
then you'll just choose whichever one is for your machine then go ahead and download that and wait for the installation to be done and then we're going to go ahead and come back to our IDE again I am going to be using the cursor IDE I have been using it for for months now um so if you want to go ahead and use that there is a free version that you can use all right but what I'm going to do now is I need to create an environment and whenever you create this environment with cond
you can use the same environment with other folders or other projects right it's not just specific for this project you can um activate it in other projects but we need to create it first so you'll say condac create dasn for the name of it I'm going to name it Master crew aai course and I'm going to specify the python version that I want to use and I've been using for a little while so I'm saying python version 3.1.9 which is what I also have installed installed on my machine and this will take a minute to
install but once it's done you go ahead and proceed you just go ahead and say yes to proceed and then once you're done It'll ask you if you want to activate this environment so I'm going to so cond activate Master crew AI course all right now once this is activated now we can go ahead and install everything we need for this course and what we need to do is first off there's a command called clear this will clear up the terminal and you're going to type in PIP install crew aai and crew AI tools what's
with brackets tools there we go right now that's going to take also take a minute to install but now we're going to install these packages with the latest updates just on the master crew AI course or whatever you named your environment it's just going to be installed on this environment okay so whenever you create another project you can activate this environment and it'll already have these installations for you with these versions and hopefully installed all the packages correctly for you if you're using something like python virtual environment there may be issues with like chroma I
have read those before this is why I like to use cont so this is a relatively new way to create many things and what we're going to do is in the command line or in your terminal which you can access so for instance I'm using C you can go to terminal and create a new terminal then I'm going to say crew AI create crew and then we can just give this a name it doesn't actually matter what it is so AI latest latest development and then what's going to do is go ahead and give us
a couple options but then create the whole crew Force so we don't have to create the files I mean it's a little unnecessary anymore to have to do that it's what they call boiler plate code that you have to do every time and this really speeds up the process okay so then here what we can do is we actually select a provider to set up so for instance I will select one for open AI in this example we'll go over local models in a bit and then select the model I want to use for open
AI so I'm going to use the GPT 40 model so I'll select number two and then here we need to enter our open API key all right well let's go and go over these files and then we're going to run this we shouldn't really have to do anything it should just run as it is since we've already given it the API key so you know in your folder AI L development or whatever whatever you named your uh crew project we have a source folder and then it again calls it the AI latest development and then
we have a configuration a tools we have a crew and we have a main python file okay well the main thing here is the crew. py file that I created now if you have used crew several months ago this is not the exactly way that they've done this they've reorganized how they create the cruise now and personally I think this is way better so this is your first time looking at this and I know it's different and maybe a little daunting because it looks radically different but I promise you this is a much better way
so there are things called decorators that's with the at symbol above the class we have it above this researcher function and all this is doing is saying hey this class here this is basically going to be a crew okay and then any function that has the at agent is going to tell the crew hey this is an agent that we are returning this should be a part of the crew so you can see here we have this function researcher it needs to return an agent class so we're going to say return agent give it a
configuration we're going to say verbose equals true and if we had tools you know you could give the tools here and we're going to go over that in the later section but we have another agent this is called the reporting analyst we're going to create another agent object we're going to give it to configuration which we will look over and this is also verbose set to true so what we've done so far is it's created two agents A researcher and a reporting analyst now we also need to create a task for each of these so
we're going to create a research task returning a task object and then we seem to give the configuration for this task so instead of having all the properties here inside of the task object which you can certainly do you can also put everything for the agent in the task inside of what's called a yaml file which just stands for yet another markup language nothing crazy you if that's a different extension for a file don't worry about it it's just markup language okay nothing to be concerned about then we have another reporting task where we give
it the configuration all the properties needed for a task to run and then we have the output file here which you can either put the properties here or you can put some here and some in the emo file it's your choice whatever you would like to do I'll kind of mix and match so you can just see the different ways to do this so this means that the task when it's done it should save to an output file report. MD for markdown and this is really where some amazing things happen we have to create a
crew and now this is given the crew decorator right so when we go to import this into the main python file it's going to look at this crew and say hey okay this is the crew that we need to kick off and we're going to create a crew object we're going to give it all the agents all the task this is going to be given the sequential process which is there by default but we just it's just added here so you can see um that it's explicitly being given the sequential process we're going to set
the verose to true so we can see everything that's taing in the background and something that if you're not used to seeing as I had mentioned this it just says self. agents and self. task well all it has to do is look through this class see which functions have an agent decorator above them and it knows that's an agent and the same thing for the task it knows that it has a task decorator above this function and it's going to return a task and it knows that so it's going to go ahead and collect all
the agents in task for the crew without having to explicitly add them into a list for each of them the last thing that we're going to go over is the agents config and the task config right so it created these two yo files up here so let's look at the agents yl file we have the researcher so this is the name of the agent we have the role the goal and the back story the three things I said that you need to have for an agent the role for this researcher is going to be the
senior data researcher and there's also this weird thing that says topic with curly braces we'll see that in a minute then we gave it a goal and we gave it a backstory then the same thing for the reporting analyst we give it a rle a goal and a backstory and then if we go to the task we have two tasks the research task and the reporting task we have the description and the expected output and also the agent that this task is going to be assigned to so the research task which makes sense should be
assigned to the researcher agent then the reporting task is going to be assigned to the reporting analyst agent so this is a yaml property file where instead of explicitly having to put the description the expected output and the agent ins side of the crew so for the task here you know we could certainly also say that we could say agent equals and then self. reporting analyst or yeah reporting analyst that would be the name of the agent up here we could put that here or we could just Define that in the yaml property file either
way is good it doesn't really matter it's just with the property file it cleans up uh a lot of the mess here in this task and it's just kind of the way that they're preferring it and I prefer it as well so it's really to start with that now and then we have the main python file okay there are some things here there's run there's a train function a replay and a test we are not going to worry about three of these right now okay we're going to go ahead and just delete these three and
just leave the run here then underneath of here we can just call the Run function now we are about ready to go but just let's go over what this is doing real quick we're calling the AI latest development crew so if we go here this is the class this is the class of the AI latest development crew that was created to have all the agents and the task in actually defining the crew so what we're doing we're saying hey take this call the crew function and then we're going to kick off with these inputs and
these inputs as you remember we had a topic surrounded in curly braces in the task well what happens is if we give this input say AI llms that's going to be inserted into the task so if we go back to the agent for instance uh the role for the researcher was a a topic and then it said senior data researcher so the topic was assigned to AI llms so then when it goes to run this will say when we go to run it you'll see in the verbosity of it that this is going to say
a lm's senior data researcher and also for the goal it'll say uncover Cutting Edge developments in AI llms now I say that this should work however there's one thing we need to do and we need to get rid of this part before the from right so we just say from crew import AI latest development or whatever you named your project right that we don't need that there in order for this to run you can actually need to remove that in order for it to run there's actually one more thing that we need to do that
I had forgot to mention is inside of your crew. python file okay we need to actually load the environment variables such as the open aapi key or any other tool keys that we'll use later on so in the crew. python file we need to type in from. EnV import load uncore Dov then execute the load. EnV function and what it's going to do is you're going to find the EnV file then load the keys that are needed for the agents in the task in our project so you can just do that in this crew. py
file here and now let's go ahead and run this so all we've done so far is we created a crew we made a couple adjustments to make sure that it runs properly and now we can run it instead of this is so much better than creating all these files yourself and the folder structure that's needed and so forth right we don't need to do that anymore this is the way to create your crew and also don't worry about the red underlines if you want to restart your IDE they should go away so in the AI
latest development folder which is where I'm currently at I'm going to now say Python and then Source SL aore latest development slash and then type in main python file main.py now if I run this it's now going to find my API keys and it should run the whole process let's see if it works and it is working so it made sure it checked to make sure I have an open API key I do the first agent that's being running is like I mentioned it's going to be called AI lm's senior data researcher because let me
come back up here because the topic as an input that was given to the crew was called ailm so now this task now this task has been assigned to the agent so it's going to try and run this so the final answer so this is basically the output um it came up with 10 different things about AI llms then the next thing is happening is the next agent ail lm's reporting analyst so this was sequential right the first agent was the senior data researcher and then the second one is now the reporting analyst and so
then it gives the final answer because it's task is to review the context you got which basically means it got the output from the first agent is going to review that and then kind of expand that into a full section for a report now if we scroll down here this is the whole output you know expanding upon what the first agent did and if you remember in the crew python file let me minimize this terminal a little bit if we come down here the second task the last task was to save the output to a
file called report. MD and then over on the left hand side in our project pain we have one and this is now our report now if you can uh I can do the markdown preview enhan and we can actually look at this what what this would look like for the markdown I created and so as you can see it's it went through each of the topics that it got from the first agent then just expand it upon it and makes it look like a more in-depth report okay great job you just created your first crew
this is an important step which you'll see later that is kind of the basis for creating anything within the crew AI framework now what we've been using or what I will continue to use and we just used was the open AI family of models which means that you need to get an open AI API key which is fine but you know it does cost cents now now the models have gotten much cheap cheaper and better which is good for us as the consumer however not everybody wants to do that but the problem with that is
you are stuck to the open AI family of models and there are so many other AI models out there so in this next section I'm going to show you how you can use any local AI model and to do that we're going to be using a software called olum which is free let's go ahead and get into that now okay well in order to run local models my favorite way to do that is to download ol it makes it really easy to download the models and then run them locally on a server and then connect
them to crew Ai and I going to show you how to do all those things so the first thing is you can go to ol. or.com and you'll be greeted with this page now you don't have to sign in or anything you just click this download button then you'll choose uh which version for machine whatever machine you have this is what how you'll download it so go ahead and download it and install it once that is done there is a models page in the website and these are all the models you can search for them
up in you can filter them uh search for them by newest most popular however you want to do that right but you can choose a model this way and what I'm going to do is choose the Llama 3.2 model and then once you're here it has a drop down for Which models you want to choose from well let's go and set up our crew to accept this and then we'll run o Lama and then download this model to use it okay so let's go back to our crew okay well the first thing we need to
do in our crew is go to your crew. py file this is where we're going to create the new llm object and then give that to uh both of our agents so the first thing is we need to import the uh llm class so from crew aai we're going to also add the import for llm and then somewhere within the class down here like you just do it below the configuration doesn't really matter but I'm going to say AMA llm is equal to llm and then there's a couple things that we need here right we
need the model and the base URL because when we go to run olama it's going to run a local server and then we need to grab the model from that server and use it here now in order to make this work under the hood crei uses light llm and what light llm does is kind of make it easy to connect to all of the different providers and use their models and if you look on the Le hand side here which I'll have this link in the description there is one 140 llama now you're not going
to import it just like this but in order to find something that you want to use such as if you like LM Studio they don't directly support LM Studio but I do have a video where we actually have to use the open AI instance in order to get that to run but we're using olama right now let's get back to that now in order to make this to work we need to add a couple properties like I said model and the base URL so the model is going to be oama slash and then now we
need to get the name of the actual model so if we come back to the model that whatever model you're going to use get the last part of the name here we're going to copy that and add that there as the model and then we need the base URL and it's going to be the Local Host 11 434 okay when we go to run this this is the this is the port and the Local Host that's running for our Al server now we need to inject this llm because by default all the agents are using
open AI but we want to change that so you can add another property called llm to each of the agents and it'll be llm equals self. Lama llm you say self. llm because we are inside of the class and the same thing for the reporting analysts we will say llm equals self. llm and now we are not going to be using open AI we're going to be using AMA but we need to run AMA so go ahead and start AMA and you'll know it's running when you see the little olama symbol now the last thing
we need to do is actually download the model that we want to use so we already actually have the model name right so all you're going to type in your terminal is AMA pull then you're going to copy in the name of the model so I'm just using the 1 billion parameter model I already kind of had it downloaded so this is why it was so quick right that took a couple seconds but it'll take a little bit longer for you especially depending on the size of the model you're using all right so it successfully
downloaded it now all we need to do is Rerun the python file so I'm going to do the same command I did last time python Source AI lat development main.py and just to verify with you that it's actually using oama and it's still not trying to use uh the open AI API key actually went to myv file and I renamed it to SK project11 right so it's not actually getting my API key it's not using the GPT 40 model this is actually going to take a few might take a couple more minutes on my machine
just because my machine isn't the best to run because this is you know when you're running a local model is dependent on machine uh but just to let you know if you had any doubts like oh it's still showing my API key when I run this well yeah it is that's just a check in the background but don't worry it's not okay and as you can see even this is a much smaller model and so the output might not be the best but it did work and it gave me an output so if we open
up the report. MD file I'm going to view this or or preview this you can see it still worked right it had topics and then it went into a little bit more detail about those topics and created the report great and so now from now on if you do want to use a local model you now know how to okay this is going to pave the way forward so that if if you don't want to use open AI you are more than welcome to use any of these local AI models that you want from here
on forward in the rest of this course or in the projects that we are going to do now we're about to start our first project however before we do that we are going to be using tools to do this we're actually be using three different Tools in this project but before that I want to explain tools really quick and then we're going to start coding them this is really exciting cuz tools can be really powerful to help out our agents well a tool in crei is just a skill or a function that agents can utilize
to perform various actions and crew AI actually has their own toolkit and so does Lange chain and llama index but we're just going to be using crei toolkit for right now so how does this look well what we're going to do is depending on the tool that we need we're going to import these tool from CRE iore tools and then we simply instantiate these objects and then we're going to pass these in to the agent and we saw this in the very beginning but how this will work is once we create the agent there is
a tools attribute and then you give a list of the tools that we want that agent to use and then whenever well depending on the task that they're going to complete they may or may not use these tools to help them complete that action so for this project we're going to create a crew we're going to use three different tools like I mentioned One agent will do Google search on websites another agent will scrape each of these websites and then another agent will summarize everything and then we'll have another agent that's going to save this
to a file using a different tool so get your coffee ready whatever it is let's get coding all right for this new project what we're going to do is first create our new crew so we're going to say crew AI create crew then we just call it ai- news and again I'm going to use open AI GPT 40 and then I'm going to enter the same API key we did from the first project and it's going to go ahead and create the news successfully over here let's go a and do a couple things to clean
up before we get started so under the main python file under the source go ahead and get rid of the from AI news period and then also so we can get rid of the train replay and the test functions and then you can just call run and then also in the crew. py file let's go ahead and say from. EnV load. EnV and another great thing about cursor is it knows I've done this before so it thinks that's what I would do here and it was correct now we're going to have a few agents with
this project like we mentioned okay so what we can start doing is we need to start renaming things then we need to add an agent and also add another task and we're going to use a few few tools this time all right now I'm going to go over using all of these tools and how to get them set up now the goal of the first agent here is to go out and Google search to retrieve news websites and then the next agent is going to scrape those websites and then we're going to have another agent
save that to a file and they all going to use different tools so what we can do is we start renaming these things the first agent we can say retrieve news then we can also change the configuration name of the agent for retrieve news and in here for the tools we're going to be using the serer serer dev tool which means we also need to go ahead and import that as well so you'll say from crew aior tools import serer Dev tool okay and then we can go and get rid of some of the comments
here but now whenever we go to run this agent which we'll have to get the API key for this for it's going to go ahead and Google search and find websites about news that we're going to give it like the topic that we're going to give it the next agent is the website scraper so we'll say website website scraper okay and then this is going to use a different tool so we'll say tools equals this is called the scrape website tool which means that we also need to import that as well and now this one
when it is gets all of the websites that it needs or hopefully it can scrape for it's going to go ahead and scrape all of those and extract information from them but now we don't have a third agent so we need to create one and and the goal is Agent is to summarize everything that it got from the website so what we can do is we just copy and paste this cuz we only have two agents right we need a third and a fourth one actually but for this one we we can say this is
AI News writer and then we don't need the scrape website tool so that's just going to be an empty list or you can just remove this completely and then finally we I'm going to copy that again and we're going to paste this and this is going to then be the file saver uh agent so it's going to everything we get from the News writer it's going to save to a file but we're going to be a tool to do that so we're going to call this one the file writer agent and we also need to
add in the tool here again you can go to their documentation page and I know that there was one called file right so if you come up here this is called the file writer so I know this is going to be the file writer tool and then we can come back up here and we do need to import this okay good now what we have are we have our four agents the it's going to retrieve the news it's going to scrape those websites that it gets then we're going to be it's going to write we're
have an agent that writes everything kind of make it look nice and then we're going to write that to a file so it's four different agents but we only have two task okay so we need to change up these tasks as well all right so you can kind of pause this um but what I've done is I we now have four different tasks here so we have a retrieve news task with the task configuration name which we're have to change the yaml file as well we have a website scrape task and AI News writer task
then a file right task okay and then if we come down to our crew we don't need to change anything here because remember when we uh get these agents it's going to look for every function that has an at agent decorator on it and it's going to know that this is now going to be an agent and it should return an agent so that it works successfully and then the same thing for the task anything with an at task decorator above it any function it knows that that is supposed to be a task so it's
going to automatically retrieve those and put them into the crew here now with that we do need to update our configuration so we need to update the agents's conf config and the task config so over on the left hand side under the configuration folder we have the agents and the task emo file so if we go to the agents emo file okay so I've updated them so the names of the agents are correct from the crew they are added over here they each have a role the goal and the backstory they have the website scraper
the AI News writer and the file writer and I just gave them simple roles and goals and the backstory for each of them there's nothing super complex is just to give an idea what this agent is supposed to do now we need to go over to the task EML file and do the same thing okay now I have my task set up so I the retrieve news task which is going to have the description the expected output is I just want to list of the 10 websites with the most relevant information about whatever topic we're
going to give to This Crew then we have the website scrape task you know each of these I try to give an expected output like give it good direction right so at the on the AI news right task is I want a fully fledged news article with the main topics each with a full section of information formatted as markdown then the file right task you know I just want this to um be saved into a file with the date that we are going to provide it with and thenor newws article. MD so anytime we run
this it should be like a unique file and that's what I want cuz let may show you how to run this multiple times in one execution now with that we are almost done we are missing one thing and the serer dev tool does required API key however don't worry it is free to use so in ourv file we're going to say ser Dev serer API key and then let's go ahead and retrieve that now so if you go to serper dodev look it says you get 2500 free queries and I'm I assure you that this
will last you you may not actually even need to pay for an upgrade this is still lasting me for a long time okay so once you are once you sign up and you're signed in you will be greeted with this kind of page and at the top right here you can go to your API key click that button and then just copy that here so we're going to copy this and then we're going to paste that right here into your EnV file we're going to save that okay we are almost done just one thing to
note here as I did this I realize there's a couple things for the task I want you to fix and for the AI News writer task or write task change the description to say summarize information from the websites into a fully-fledged news article of course if you're just using my GitHub I already have this here and you can just copy this which is what I would recommend doing you can modify to what you want and for the expected output add a folder for it to save it in okay with all of that said now let's
go ahead and run this and see that it works okay so A lot's happening I can't actually even scroll to the top but it's started and what it's doing right now is it's trying to scrape all the each of the website right so uh it successfully scraped the content from the fourth website aera whatever that is right so the tool input was we gave the website URL so this is the URL that we are going to scrape and it's doing that right now right so it's going to scrape everything and I know I'm kind of
coming all the way down here right okay so it I think it finally finished all right so the website news scraper from each of these um uh it kind of gave like a final kind of final report from each of them the News writer is going to Summarize each of these so this is what it's doing for each of the websites that it did now the thing with about a regular Google search is right so if it Google searches and it's like a YouTube video it can't scrape that it's not I mean yes it's technically
a URL but it doesn't know how to scrape like a video format right but if you get something like a website 404 URL maybe you need to sign in or something it's just not quite working that's okay uh that will happen sometimes with just a normal Google Google search and you're trying to do a web scraper that's all right but now continuing now we have the AI news file writer and it's going to use the tool file writer tool so the file name was 2024 news article. ND in the directory news and here is the
content which is what was from the previous task which was the third test to summarize everything now if we scroll down here it says it's been successfully written to the file news blah blah blah so here's a news article news folder with everything it saved it to now if we come up here on the project pan on left- hand side there is now a brand new news folder and it has the news article that we wrote to so if we let me minimize the terminal here and then preview this and look here we now have
actually scrip sced news from the website or from the Google search and then it went through scraped each of the sites then summarized them and then added them to a file and save them as markdown and that's great right now I just did something simple called AI llms you could do specific topics which leads me to the next section which is the kickoff for each Let's test that out now with this kickoff for each this means that we can have multiple different inputs as an array and we can kick off this crew many different times
with different topics that we'll see in a second so what I'm going to do now is I'm going to add different topics here we going to create this into like a list but I also updated the date time to add in the hour minute second because if we do this it's going to keep overwriting itself with the date and I want this to be different I want to have different files so I can showcase to you the kickoff for each all right so how this works now is we actually need an array of inputs so
instead of just having a singular input you know we one input variable as a dictionary with multiple different inputs we just need to convert this into an array of them so I'm going to have three different topics now here with the date you know I can have some of them this is where I could have the date differently for each of them if I want to worry about the file name but I'm not worried about that so basically just have three different topics AI agents open Ai and hugging face now instead of the inputs being
just the singular input is the inputs are AR now instead of just kickoff it's kickoff for each and that's pretty much it now now we can go through all this different data and it'll kick off the crew for each of this set of inputs now let's run this now I'll come back to whenever this is done but I just want to let you know so the first uh Topic in this array was AI agents so we now can see that the first agent name is AI agents AI news Retriever and so it's going to keep
doing this for the rest of them'll eventually do open Ai and then hugging face so we'll come back whenever all of the news articles are printed out up here or saved up here in the project okay and it finally finished there was one little snag it's not actually a sag snag everything worked perfectly I saw it as it was happening and you know it it saved the latest news I just forgot to realize that the date time is not actually going to change so it stayed consistent throughout the whole thing so I didn't I should
have made a different way to actually save the article so I tried to copy one but the latest one you know this is about hugging face so if we go to uh if I you know this was the third input right was hugging face and then the second one I did happen to copy and change it and this was about open AI so you know it did work properly uh we just need to figure out a different way to save them uh save them as different file names when you do the kickoff for each but
either way this is to show you that this was the last one about hugging face was the third input go back to our crew let me uh get rid of this go back to our crew or go back to our main python file I apologize the first input array was AI agents then open Ai and then hugging face right there were no errors in this everything worked correctly and this is how you can have different data sets input into a crew and then without having like to do your own like while true or any looping
any anything like that okay this is a great way to show how the kickoff for each Works absolutely amazing stuff okay great job we just completed our first project and there was a lot of things going on in there especially using tools now I can't emphasize really enough how powerful tools can be to help us accomplish what we want especially if there's API there's I mean there's so many apis out there right well an agent just doesn't by default know how to use it so we can create a custom tool that can connect that agent
to the API to perform some action well now we're going to move on to the next section and this was an important feature that was released not long ago go called flows and I think flows are really important and a really powerful feature and by first understanding this let me explain it to you well let's go over what a flow is well a flow allows you to create structured event-driven workflows it provides a seamless way to connect multiple task manage State and control the flow of execution in your applications okay so we're going about to
go over a code example in just a minute but the couple of the key things here is that has State Management which you'll see it does allow for a lot more flexibility than just creating a single crew because in a flow you can execute multiple Crews and not even at the same time because flow is created based around python functions it's not created around Crews but inside those python functions you can execute a crew let's see how a flow looks okay I have a simple flow here and I know this is be probably going to
be new if especially if you haven't seen this before but there's a couple things happening I will get to this poem state in a minute what you need to do in a flow is first off you create a class so I created a class called poem flow I added a flow object so up here you import the new flow class so you add that in here as a parameter to the class and then inside of here I have the poem State now my poem state is also just another class as you can see with two
properties sentence count and poem and you add that in here as a list of the flow class okay so to recap we first off have a a class we give it a flow class as a parameter and then inside that we give it the poem State now the next thing you're going to notice is like I mentioned these are just python functions right there's actually three of them within this class okay we have we start with the generate sentence count generate poem and then save poem now this doesn't mean that they have to be executed
in this order but what we now need to realize is there are some decorators that are important to how flows actually work so this at start decorator means that this function when we kick off this flow just like you would kick off a crew when we kick off this flow it's going to start at this generate sentence count it's going to print this out and then it's going to save a random number between 1 and five to the state sentence count up here okay so it's going to give that a random number and then we
have the next uh important Decker you need to know is the at listen what that means is that this at listen well we first off have a generate poem right so it basically generates a poem and inside of here we kick off a crew so in well this at listen decorator it says at listen generate sentence count so whenever this function because this is where the whole thing starts based off The Decorator whenever this function is complete whenever the logic inside of here whenever that's done the output if there is any is going to be
sent to this function and whenever listening to that this generate sentence count to be done it then starts so then it's going to print generating a poem print out the state before the poem and then it's going to kick off the crew and this is what I meant is you can kick off Crews inside of the flows whenever you want you can have multiple Crews now this is just one so this this is actually a whole crew so on the left hand side here if we look at the poem crew we have a whole poem
cre crew with an agent a task and you know we create the crew right and it has its own configuration and everything so that's all contained within a crew and then we're just going to Simply kick that off and then we're going to Simply kick that off inside this generate poem python function so then we get the result of that then we save that result in the state. poem now you can see here we say self. state self. state sent count and self. state poem well when you say self. state it knows that the structured
state is going to be inside this poem State class with these properties so we don't have to say self. poem state. sentence count or self. poem state. poem it just knows that it's referring to this then we have another print statement and then we have this last python function called save poem it has the at listen decorator which means that whenever the generate poem function is done which is the second function in this flow whenever that's done it's going to take the output if there is any give it to the save poem function and then
it's going to do all the logic inside of it however this time time we're just writing to a file and we're going to write self. state. poem so we're going to write the state for the poem this is was saved or this was added to the state in the second function but now we're going to retrieve that in the third function this means that state is accessible throughout the whole flow just within the flow but without the throughout the whole Flow State can be um updated it can be modified it can be read whatever or
created actually it can also be created as well um and it can be just accessed anywhere within the flow so it's going to save the whole poem to poem. text and then this is going to be pretty similar to what we used with the kickoff right so down here add this main this so whenever we run this main python file it'll run this function it'll come up here it will call async do run uh run the Run flow function which is then right here so we instantiate the poem flow object and then we kick off
that flow all right so once that is done it's going to create this poem. text and I already have an example here so we can look at it and this is the poem right it's kind of cut off here but this is the simple PR that it created and also and also what you can do to see how this looks like this how this physically looks is you can run a poem flow. plot function so you create the poem flow object then you run the plot function and it creates one right here so if I
were to open this HTML file open with live server this is going to open up here you can see this is the flow of what we just created we have a generate sentence count and there is a diagram or Legend at the bottom here so this means that this is the start method when it's in Orange and then we went to the second python function which was called you know generate poem and this inside of here we had a crew and you can see that in the legend that means that this is a crew then
finally the third one was just a regular python function there was no no crew involved there actually no calls to apis or anything but that's not all there's actually more that we can do with flows and then we're going to create our own flow and we'll do more things with that like creating our Custom Tool like I had mentioned now with the flow control there is some conditional logic that you can have as well so this at listen here like I like I briefly mentioned that just because these python functions are in this order doesn't
mean that's the order that they have to be run like not it's not like necessarily sequential like you would see an acrw with the agents so the first conditional logic is this or function you know or means you can do one thing or the other so in this listen method here we had listen and then or underscore and then it has the start method and second method and these again are the names of these other two methods so what this means is this logger is going to execute when either the start method or the second
method are complete and you know whenever the start method is done which all it does does is return hello from start method it's going to then execute this logger function and then the second method will execute and there's also an and function which it is similar but it has to be done when one thing and the other thing are complete so this this at Liston has the andore logic then we give it the start method and second method again so once the start method and the second method are complete then this log or python function
will execute so how do we create flows well this is very similar to how we created a croo there is one line you I will never recommend again uh manually creating all these files you can if you want to just to get the appreciation for the command line uh command line tools but all you have to do is say create or crew AI create flow and then the name of your flow and then it creates the folder structure here so it already has the flow and a single crew created for you with all the configuration
everything that you need right and then in documentation just kind of goes over what I already did but you can also add additional crew so you can say crew AI flow add- crew and then the crew name and this will this will create another crew for you in your flow okay now with that understanding and that's a lot to take in I totally understand I kind of went over as much as I could as possible to just kind of give you the overview of exactly what a flow is well the way I love to do
things is now let's start coding one so let's create our own flow I just want to get you used to understanding the flow and then executing it so the first thing we're going to do in your command line again I'm just in the master crew AI course folder so I'm going to say crew AI create flow and then we can just uh give this flow any name so we're going to say poem poem flow as you can see that was pretty quick that took like maybe 10 seconds I think so now we have this new
directory called poem flow if we open it up we can go to the source file we have another main python file and in here we have the poem State we have the poll and flow class which is how we start off or actually kick off the whole flow we have the start method which is going to generate a sentence count between a random number of 1 to five then we have two listen decorators where we're going to generate generate the poem and then save that poem locally and then it created a cruise folder and inside
of here we have the poem crew that gets executed so we have the poem writer we have the write poem task and then the crew that's going to take care of executing all of these together I mean this is simple but we're going to get a little bit more in depth on the next project and then we have the configuration so it creates the agents yo file and the task yo file it assigns the this task to the poem writer and we have custom tools here which I didn't really talk about yet because we are
going to be creating our Custom Tool but in this instance it just gives you a way to actually create your own custom tool I'll get more into this on the very next project where we will be creating our own custom tool but uh this is how it's created this is kind of the structure of the flow when you initially create it and in the EnV file we do have to give our open API key just like we did previously so I just copied over the model and the open API key okay one more thing before
we get started is there's one a couple just fixes real quick inside the main python file here where we have the poem flow get rid of there will be a DOT here just get rid of that and then make sure from EnV import load. and then call the function then save that and I am inside the poem flow directory so while I'm here all I have to do is say python Source sloom flow and then main.py once you execute this this probably won't take too long because it's a simple flow but it's you know generating
the sentence count which was at the start method here right so it's printing out the generate sentence count then it's going to generate the poem so we have the print statement to make sure it's running so it's generating the sentence poem now it's uh making sure we have the open API key so then it says poem generated and then it gives out the actual state of the poem and then it goes to the next listener which is generate poem because uh the generate poem function is done now we want to save the poem and down
here it's saying saving poem which is the print statement from the third function and then it writes it to a file so we had the poem. txt and this is the poem it created okay great job you just created your first flow you created it and you're actually able to execute it just make sure you fix those two little mistakes and this is how it's going to run for you okay you've been doing wonderful so far and I'm really proud of you and the next thing that I really want to cover is custom tooling this
is a really important topic well I think is one of the most important topics because being able to create your own tools to do what you want to help the agent out is is I think something that's priceless and we're going to be using in the next project which means I need to teach it to you first we will be covering something else that I think is also important and that is Agent observability but we'll get to that after we create our big project well why custom tools the reason for custom tools is that not
all tools are available that can support what we need to do this is why crew aai enables us to create custom tools so in our next project for instance we will create a custom tool to create draft emails for your Gmail account and there's just no way by default that an agent knows how to do that but first we need to know actually how to create it so in creai what they have is something called a base tool and what what this means is that's going to wrap our tool in a way that agent can
digest it and use it with AI so we're going to create a class called my Custom Tool it needs two things the name and the description these are going to define the tool and then we have a single function this underscore run function needs to be there because this is what the crei is going to actually execute in the background and then you'll have all the logic inside of this and whatever that returns is what that will be given back from the agent or the tool output okay now it's time to move on to our
second project and this is going to be called meeting minutes what we're doing in this project is we're going to create a flow we're going to create a custom tool we're going to create a crew we are actually going to use different models and we're going to integrate with Gmail this is going to be the big project that we've done yet as I had mentioned but we're going to code everything together I'm going to show you every step along the way and by the end we will have this cohesive crew the biggest crew that maybe
you've created so far but you're going to really learn a lot from this session let's get to coding okay so we're going to go ahead and begin creating this project as this is going to be a fair amount of coding but there will be steps along the way where I'm just going to paste the code uh because it may not be necessarily related and it's just uh something with based on tool or whatever that may be but I will go through and explain it and as always you can get it from my GitHub as you're
moving along and copy that as well but I'll let you know when we get there the first thing is we need to create a flow so we're going to say crew crew AI create flow and then we can name this whatever you want but I will name this meeting minutes okay that is successful I'm going to minimize this now and on the project paint you can see it created a meaning meeting minutes flow now there's quite a few things we need to do uh let's look at the main python file first you so by default
it just creates this poem state so we're going to go ahead and remove some of these things uh and we are going to start creating this this meeting minutes model so the one thing that we see here is that in the poem flow again we pass in the flow and we pass in we pass in a state as a flow called poem state so let's first start just kind of renaming some things so we'll say meeting or oops meeting minutes flow and then we can go ahead and rename this meeting minutes State now a couple
things we'll need here is instead of a sentence count we will have a transcript as a string and then also I want the meeting minutes summary which will be at the end when we go to send the email we'll just use this state that will at this point have uh the whole summary of what we'll see soon and then we can just pass this into the email to send it so we'll say meeting minutes well actually we just call it meeting minutes that's fine and then we can actually delete Del these two things and we
can keep we can keep this first start we can delete this as well we will go ahead and as you can see in the kickoff it is going to modify that for me I of course I'm using cursor so it's going to recognize some things that it knows it doesn't need and it will autofill it will autofill some of this crew AI stuff because we used it in a couple of the projects already in this course so we don't need that and we're going to rename this generate sentence count which is this is going where
we start the flows this is the first thing that's going to happen and the first thing we want to do is actually generate or get the transcript from from a wave file so whenever you get from Zoom you finished a zoom call and you have it saved it saves on a certain folder on your machine well we're going to pretend that we had that wave file within our project so I'm going to give you a sample wave file so we're going to name this first method transcribe meeting and then generating transcription and we can get
rid of some of these print statements at the end but what is so going to be different about this is we don't actually need to call anything related to crew AI here we're just transcribing something which does mean we need to use a speech to text model and we can just use an open Ai call and if we go to platform. openai you can search for a bunch of different code examples and one here is speech to text and what I'm essentially going to do is just copy this so I'm going to copy this transcribe
audio I'm going to paste that within this function and here we go we have a sample transcription right here and we're going to be using their whisper one model okay but what's uh what's actually going to happen here is we need to give you can it can also be a wave file doesn't have to be an MP3 so we're going to actually use a wave file so we're going to search for the wave file and then it's going to create or make an open Ai call using their whisper one model and then give us the
text back from the speech or the MP3 wave file now let's go ahead and clean this up a little bit I'm going to move these Imports up here and then also what actually before that we are going to need to bring in the uh we're going to bring in the EnV file so from EnV import load EnV and then execute that function okay so now the API key will be in this open AI object now one problem with this is that if the audio file is too long The Whisper model only has so much context
length right you actually get an error and I know in this specific example it's about 3 minute audio file it can't transcribe the whole thing right so what we have to do is we have to kind of Chunk it out what we're going what I'm going to do is depending on doesn't matter what the size is I'm going to chunk it out so that every 60 seconds of the audio we're going to then send that to transcribe and then until we're going to keep looping until that's done and then we're going to concatenate all those
together into a transcription okay so I just had this earnings called. W which again would be my GitHub that you can download and I went ahead and just cop the code here instead of just writing this all out and trying to explain to it it' be easier if you just copy this and then I can explain it as we go so what's happening is we are getting the file path for that wave file we're using a library called pdub which we'll have to install in a minute and it's basically taking that audio from the wave
file and it's going to chunk it into 60 60 seconds or 1 minute each and then we're going to enumerate or iterate over each of those chunks of at most 60 seconds and then we're sending what we just copied from open AI is we're sending that to the whisper one model to transcribe for us and then you know there's a full transcription uh there's a full transcription variable that's going to take each time we do that it's going to concatenate it or append it it's actually not concatenate it's going to append it to the end
of what's already there in that text so that by the end of the end of this we have a full transcription and then what I'm doing here is saving this to the transcript state of the meeting minutes State up here okay and like you said like I mentioned before in the previous project that you all you have to do is call self. State and then the property of that meeting minute State class so here I'm just calling the transcript okay so now we need what we need to do now is actually install the proper libraries
to make this work and if you want to in the beginning I'll have a requirements. txt so you can just uh install that which have the instructions to do that in my GitHub but let's go ahead and do here so we can say pip install pdub now I already have it installed but we need to actually import that now so you can say from PI dub import audio segment and then we also need to pass in the make chunks and then we also need the path so from path lib import path and this will get
that'll get rid of all of those errors that we have and right before we do that there is a EnV file make sure that you paste your open AI key in here and the model or you could just move this EnV to the whole project level and we can always use the same things but you can have it per folder or per mini project so that you can maybe update this and change it for that little project but either way however we do that you just need to make sure that thatv file has your open
AI key and the model you want to use and now that everything is set up let's make sure we test out this first before we move on so make sure you're in the meeting minutes folder and then we're going to say python Source SL meting minutes you can always hit tab to u to kind of help fill this out and then Main and I hit tab I just typed in MA then I hit Tab and it knew there's only one file at with the starting out with Ma so we're going to go ahead andit enter
and what should start out is say it should print out this generating transcription because this start decorator means that we're going to start out by executing this transcribe meeting function and what we can see here is saying transcribing chunk one of three again 60 M this is 60,000 milliseconds so that's 60 seconds and it's going to make however many chunks that means so the earnings call. wve this is 2 minutes and 55 seconds long which means that there are going to be three chunks right and then it comes down here and tries to transcribe each
of those chunks and each time it's transcribing the chunk it's calling the Open Eye model for whisper one to give us the text of that and then when we save save that into the state I'm just going to print out that state and that should be the whole text of the whole wave file so this is about to be done and here you go here is the transcription so good afternoon everyone and welcome to fintech I do know that's how it starts and this is correct so we had the first part done where we actually
get the transcription from the zoom call now the next thing is we need to actually create the crew and what I can actually do here is just kind of minimize this so it's not all this code everywhere so we're going to create the meaning minutes which means there's a few things the crew are going to do it's going to have like the summary the meeting minutes and if there's any action items that are needed and we're going to create that before we send it off to the email so how do we do this well we
need to add a listen decorator onto this transcribe meeting so whenever we're done transcribing it then we can pass that transcription off to the crew because it'll also be saved up here in the state so we're going to say at listen and you know it's already already kind of started started this with cursor but this at listen we're listening to this transcribed meaning function to be done if you see this if you uh happen to see this in quotes that works as well there's that's a couple different ways to do that but we're going to
create a python function called generate meeting minutes and then we I'm going to start out printing that we're generating this well what we're going to do is actually kick off the crew and as of right now we have uh up in the project folder up here it created the poem crew by default that is this right here so we going to modify this and you can see Kur is already telling me what we need to modify it to but we need to modify this we need to add some agents add some tasks and also we
need to modify the agen am will file and the task gml file which again give all the configuration for each of the agents and the task so let's go and start doing that so we can change the name of the crew first we'll have to modify some imports as well okay so we can go ahead and call this first one let's call it meeting minutes summary summarizer that's perfect okay and then once you do that we also need to change the config to we'll modify the config to get it from here and then we need
to what I'm going to do is have a writer so we're going to create another agent which you can ALS you can kind of copy this this me what I do and this is going to be the meeting minutes writer so we're going to take this is going to have a bunch of different things that's going to take from the transcription then we want the writer to uh kind of make that and format it and make it look nicer before we send it off in an email okay so we have now we have two agents
we create another agent and now we need to create both of the task for these okay so we can change this to say meeting minutes summary task we can modify that and then you know it's already giving me the next task uh meeting minutes writing task which is perfect okay and then once you have we have see we have two agents and two tasks now these don't need to be the same number right you could have one task I could have five task and still only have two agents you can assign multiple task to an
agent just just to clarify I don't want you to think that because I have two agents I need to have two tasks I could actually add more tasks here and I could have one agent perform multiple tasks but then again with the crew we don't need to you never need to modify this anymore because this is always going to check for the decorat the agents and this is going to check for any functions with The Decorator of task and go ahead and put that here in a list so we don't need to change that we're
going to keep the sequential and then I want to I said reverse the true so that you can see what's happening okay the next thing we need to do is update the configuration for the agents and task and what I'm going to do instead of just you watching me type these out I will have these in my GitHub I'm going to show you what they are here and go over them so let's do that now now what we do is go into the crews the poem crew we can actually go ahead and rename this right
so first off it's we're going to the source meeting minutes and then Crews because we are going to have another crew here we're going to rename this to poem crew so you can just right click that rename and we're going to rename this to meeting minutes crew and then we can rename the python file that we just we just uh modified to meeting minutes crew okay now go to the configuration and we have the agents in the task emo file so for the agents we now have the meeting minutes summarizer with the role goal and
backstory and you know we can go over this but what I really want to go over right here is this agent is going to do three different things so we're going to summarize the transcript write it to a file then we're going to extract the action items from the transcript and write that to a file and then we're going to basically have like a sentiment analysis which means we're going to see what the language of it is like kind of the emotions of it and then also write that to a file as well we give
it a backstory and then for the meaning meeting it's Raider it's basically going to basically going to take all of those things from the from those files and then put them together okay that's just really what it's going to do and put them like kind of make it look nicer and then for the task we have the first task for the first agent so you know I want to summarize the I want to summarize the transcript write the summary to uh summary. text I want to write the action items to a file called action items.
text in this meeting Min directory which this will all be provided by the tool all right and then I want the action items to be in the following format which you know you can come in here and change this however you would like and then I want again I want to analyze the sentiment of the meeting transcript and write to a file called sentiment. txt and the reason I do this is we will be using tools for this agent as well the file writer tool but if you kind of give it some uh what I
noticed is that it works almost 100% of the time if in the prompt you kind of help it again by saying use the tool and make sure it's in this directory or wherever you would like to put it so then we have the expected output oh I forgot to change that I forgot to change that agent so we now want to assign this to the meeting minutes summarizer agent then we had the meeting minutes writer task you know it's supposed to take down everything from those summary action items and sentiment and put them into a
nice markdown document and there's some things here right like uh I wanted to use today's date for the meeting date and I want to use my company name use my name for the name of the organizer and create some random list of attendees and then location was Zoom okay so my expected output is just a document and then the agent this is tied to the meeting minutes writer agent okay well now that we have the agents and the task figured out if you notice in the task you know I mentioned or in the agents I
mentioned that we need to save we I want to save files from each of the summary action items and the sentiment into a file well I can tell to do this but just by itself it's not going to like execute code to do that so how do we take care of that well back in the crew for this agent we need to give it the tools to do that and cre AI like I had mentioned well before we started this has their own set of tools and we're going to go ahead and import that so
you're going to say from crew aior tools and we're going to import the file writer tool now we can do a couple things here I want to make sure that these are going to the correct uh folder and make sure that they're a specific uh like specific file name so we're going to instantiate three of them one for each of the three things that we had mentioned in the agents and task configuration so I'll say file writer tool and then call this summary is equal to file writer tool and then we can have the same
thing for the action items and the sentiment and then instead though I want the file names to be something specific so I'm going to say file name equals summary. text and then I'll let are finished out the rest so we are instantiating the file rer tool three times and that's okay right an agent can have multiple tools even if it's multiple of the same tool so we are going to add all three of these tools that come from crew aai into our agent and if you're curious how I knew this was file name and directory
if you actually go into the file writer tool you can see that in this input here which is the like kind of the arguments for the tool it's going to look for a file name directory overwrite and content well the file name this is what we gave it and the directory we also gave that um the overwrite is set to false and then the content this will be added through the AI it will take the content and add this in here as well so when it goes to actually run this it's going to take all
the arguments and it's going to fill in the content and now we just need to add it to the agent so you just add another property actually it already knows what I'm want to do so it say tools equal to and then you just going to add in each of the three tools okay great now we finished with that what we now need to do is go back to the main python file and as you can see here we have this method we just created before that we need to call this crew to kick them
off so we can say crew equals and then meeting minutes crew we haven't imported that yet so we can actually go ahead and do that now so we can go and import this now we'll say from cruise. meeting minutes crew . meting minutes crew import the actual class meeting minutes crew which basically means that we're going it's we're here in the main file we're going to go to Crews then meeting minutes crew and then the file called meeting minutes crew then import the classroom here I know that can kind of it's kind of a tongue
twister and a little bit uh a little bit kind of crazy to read but this is this is how we do it so we're importing this crew we're instantiating the crew now and then we can say meeting minutes is equal to crew. crew the function. kickoff okay now we are not quite here yet right this is this is going to work right this is going to kick it off however it doesn't have any reference for the transcript now remember how we do this in the previous project we actually have to give it inputs so we'll
say inputs is equal to and then you can say transcript and this is like you know it's like a dictionary right so we're going to assign uh to the transcript the actual transcript from above remember we saved the transcript from the transcribe meeting function into this state so for this input we are going to call that state and then we're going to pass this into the kickoff and then we want to save the result of this into the meeting minutes State up here so we have this meeting minute state which is still an empty string
we want to save the output of this there and this is how we do it you just say self. state. meeting minutes is equal to the meeting minutes okay and then we are done with this crew but we do I want to check to make sure this works say make sure you saved all the files and we're going to run this again I'm going to and raise this up a little bit so what you can see is we went ahead and did the same transcri transcription there are ways to optimize this so you can make
sure it doesn't happen again but we're not worried about I'm not worried about that right now so then it starts to generate the meeting minutes you know it's just kind of checking that I have the open API key so don't worry about that so make sure it it mapped it correctly we had the first agent which is the crew AI meeting minute summarizer this is the task that we asked it to it's going to use the tool so the first tool is so use the file writer tool and as you can see that the tool
input we had the file name that we gave it the directory the overwrite and then this is the content that it got from the transcription so this is just a simple summary and successfully save that to this directory which we'll look at in a minute and then it did it again another file writer tool for the action items and then finally did it for the sentiment all right so it it was able to actually write everything successfully here and then we have the summarizer right so this this is the summary so it's taken the summary
the action items and the sentiment analysis that we had and then it's going to write them so it's going to write them into as you can see here it's going to take all that and make it look nicer so it's filling in all the information that we had right so all the attendees these are the minutes these are the financial summary overview the sentiment action items and so forth that's exactly what we wanted so this is going to be the output that we saved to the meeting minutes State now if we go into the actual
meeting minutes directory that it created you can see let me minimize this that we have the action items the sentiment and the summary okay awesome so what this means now is that we were transcribed an audio file we created an action items sentiment and summary for it the output of that was what we just saw here so it's able to make it look nice this is really setting it up for an email and we're going to create a draft email next which means we're going to create another crew but I had to explain to you
how the Gmail API works okay so once you go to console. gooogle cloud.com make sure your or console. cloud.google.com I'll give you the link here make sure that you have your correct email address that you want to use so it says I'm working in my master crei course so I created this just for here and how I did this in the top left here you if you just doing this you won't have any projects you'll click the drop down and create new project or may have a button to create a new project if you don't
have one but either way just create a new project so I created a new one called Master crew AI course then we need to enable the Gmail API so click this quick access here for API Services I do not have Gmail yet so I'm going to click this enable API Services button at the top in the middle here I'm going to search for Gmail chose Gmail API there are two just choose the first one for actually managing managing your Gmail inbox see then you click this enable button okay awesome now it's saying that to use
this API you may need to use may you may need credentials which we absolutely do in order to do that go to the ooth consent screen here it's on the top on the left we have to fill out we have to kind of like create an app so you can choose between internal or external um for me I can only choose external which is fine so I'm going to choose create for app information I'll just say master crew AI course so you guys know this is exactly what it's for for the user support email I'm
just going to choose my email you don't need an app logo or an app domain uh you actually don't need any authorized domains but for developer contact information we do need to re-input our Gmail address so I'm going to hit save and continue okay what you see on the screen is that we don't have any Scopes and what a scope is it just means that this is what our credentials when we create them and download them this is what we're able to use such as composing emails such as removing emails managing the whole inbox and
everything so click that and on the right hand side these are the scopes for enabled API so we're going to say we're type in Gmail and what we can see here is all of the Scopes that we are allowed right so you could just basically have it do everything right you can have the read compose send and permanently delete all email recompose and send emails right these are just all things that you want to allow this API that you're going to use to do so I just want to click the one that says manage uh
drafts and emails so then once you click that one CU all we're doing is creating draft so man draft and send emails so we're going to click update as you can see we now have this Gmail scope so click save and continue uh test users you can add a user I I I don't think this matters but I always put my uh Gmail uh gmail.com address in here just to make sure and then once you add that click save and continue and for the summary we are done just go back to dashboard okay now we're
done with that then go to credentials and we need to create an ooth to client ID credential so we're going to at the top here click create credentials credentials go to ooth client ID the application type choose desktop app it doesn't matter what you name this master crew AI course and then click create okay awesome so you'll get this screen here where it says it's created so you have a client ID and a client secr so what you're going to do is click the download Json it is going to download a Json here so I'm
going to open up this folder so I'm going to rename this to credentials. Json and then we're going to do something with this in a few minutes now that we have everything set up on the Gmail side we actually need to create the Gmail crew that is going to use this okay great job so far we have the last thing we're going to do is we need to create a Gmail crew that is going to create the draft from the meeting minutes that we have created so we need to create one more listen so we're
going to say add listen this is going to be waiting for the generate meeting minutes and this is going to we can you can go ahead and do this but this is going to be called uh see create draft meeting minutes okay so we're going to create the draft meeting minutes in my email address or your Emil address now we want to create another crew and there's a simple way to do this if you go to the crew AI documentation under the flows core concept section you can scroll all the way down here well almost
all the way somewhere here it's what we can do is just add another crew to the flow without you know just creating a crew separately and then kind of like moving it so here adding additional Crews using a CLI so we're going to create another crew through but we're going to add it to the flow we already have so I'm going to copy this come back here in our terminal I'm going to copy that but of course you want the crew name to be different so I'm going to say Gmail crew hit enter and this
is going to create it should create another Gmail crew inside of this crew's folder and I believe it did so if we now drop down this crew yeah look we have a Gmail crew folder with a configuration and a Gmail crew now if we take a look at this Gmail crew we can get rid of this let me minimize this a little bit we know it does the same thing it creates the same researcher reporting analyst and so forth so we're going to go ahead and modify this crew now and in this case we only
need really One agent one task we need one agent which is going to use a custom tool that we are also going to create that allows us to create the draft email so we're going to name this one Gmail draft agent agent K that and we can keep kind of the rest of that the same I do not need this agent also don't need this second task but this is going to be the Gmail draft task perfect we don't really need to change anything else we will need to add the Custom Tool which we will
create here soon I just want to get everything else set up and then let's go ahead and look at the agents in the task emo file I went ahead and just saved it this is really simple right there's really nothing to this except just know that I have this body here so we're going to going to be taking the summary from the previous run and add that into here so the Gmail draft agent will have the body to send in the email so then in the task same thing this is really simple okay this these
these are not uh nothing crazy although I need to change this agent to Gmail draft agent okay so now back to the Gmail crew what we need to do next is actually create this Custom Tool and make sure that our credentials work and everything whenever we go to create the draft email so how are we going to do this well we're going to rightclick the Gmail crew and create a new folder called tools and then inside of here we're going to create the Gmail tool. py and then I'm going to go ahead and create another
file called Gmail utility. py okay and the reason and I named that pu that is uh not the correc uh spelling okay so the reason we have I have two separate things is you know to set up the Gmail you have to have the authentication and make sure there's credential and it kind of there's you have to set up kind of the email and before we create the draft and then execute the function for the Gmail API okay and I kind of like to separate those things out because in the Gmail tool we will just
have a simple Custom Tool here all right so let's go ahead and get started with that and actually what I'm going to do uh in the over here in the meeting minutes or not the meeting minutes crew but just the tools here that kind of came with the flow I'm going to go ahead and copy this and go back to the Gmail tool tool and paste this cuz again this is what this is what a sample looks like for a custom tool we need have everything we need we have the my Custom Tool input and
the actual my Custom Tool and this input uh will be the arguments that we're going to be giving from getting from the AI to input here we'll go over this so I'm going to change a couple things here we have the Gmail input we just have one we just have one parameter here and that's the body right and then for the description this is the body of the email to send so the AI is going to see this argument and say okay what we get from the previous function I'm going to input here and this
is what this args schema here is in the actual tool right and then in here we're going need to give this a Gmail input and this defined underscore run function as I mentioned in when we went over custom tooling is that this is what actually gets executed so the logic has to be in here to actually execute the create draft API now what I'm going to do is copy the code that I already have for the Gmail utility and then I'll go over that with you all right so I know there's a lot going on
right here and I will go over this there are some imports that I will have you have to have you know Google oo it's just the Google API stuff and the ooth stuff that we have to pip install which you know I will have that for you already in the requirements.txt but once you had that installed we need to kind of import all of that and we have the Scopes here right this is the scope that we allowed for this API so we're gon to have this scope here so that the only way only thing
that get executed here even if we tried to like create a label it will not happen because it's not a part of the scope of this API or of this credential of these credentials that we have I have an HTML template this is a string and what I'm going to be doing is inserting the body here so we're going to actually send instead of just having just plain text in the email body I want it to be like a full-on HTML so it's formatted right so I have a couple functions here I have the authenticate
Gmail function so what this is basically looking for is token. Json and then the credentials. Json file so let's go ahead and first put our credentials. Json into our tools folder so I'm just going to move that over here and great now we have that now I going say first off we're saying the credentials is equal to none so it's looking to see if there's a token. Json which this is used for like refreshing tokens okay it's created after we actually do this for the first time so it's okay if it's not there it won't
be the first time use it um so if there are no creds which initially there are not and this not valid okay which it won't be uh it's going to try and refresh the token but if the credentials path doesn't exist basically mean this credentials. Json doesn't exists then we have an error right and you need to but then we have a couple of these lines right here right this doesn't look like anything crazy but this is tries to get the your secrets like your client and your secret from the credentials and then it kind
of verifies that they are correct and then if they are it creates the uh token from the credential see it creates a token token. tojson file or B converting it to Json file and it'll create another token. Json file here for you so it's basically just making sure we have the credentials and once we do then it can successfully write and create that tokens. Json okay this is now this returning this the service is actually how we're building uh the credentials and the API to do something now the next thing that we do is we
have a function for creating the message okay so we got we have a couple a few primers in here now the problem is I had a pretty hard time well not say hard time but it took me a while to kind of format everything into an HTML until I figured out the one library that made all this easier and that was the markdown library because uh I had the second the second part of the flow formats everything into markdown so I need to convert that so what I've done is I convert that markdown into HTML
that's what this does it converts the markdown to HTML and then in the HTML template um the final email body is going to be equal to that now converted uh HTML so back up here in the HTML we see the final email body we'll be inserting this we'll inserting that HTML now into here under the body tag okay now coming back down we're creating email message we're getting you know basically having the contacts to from the subject and all of that we just have to encode that right so then we're returning that encoded message then
I have a create draft this is the actually this is actually calling the API and this is how it works we say service this is from the Gmail API instance that we created above say users. draft. create and then we're going to give it that message body to execute so it's going to to create that draft with that full HTML with the body the summarization and all that that we get right this is just a simple print statement to kind of you know make sure something make sure it worked properly if it got here then
it probably worked I know this was a lot okay especially first time looking at the API and I know this isn't this isn't the best uh probably the best code for it but this is kind of everything that you need to know to get it to work so if I were you I would just copy this from my GitHub now back at the Gmail tool we to set this up to actually use that so let's go and code this we need to import all of those functions from the Gmail utility so create draft email I
believe that's what it was called right so we have authenticate Gmail create message and then create draft okay I don't know why this says create message create draft okay so those are the correct ones and now under we need to modify the logic here within this run function so what we can say is service is equal to authentic iate Gmail right because authenticate Gmail returns a service object which is just kind of building um the API then what we need to do is I'm going to kind of hard code like the sender the two and
all that so the sender is going to be equal to that's me so Tyler read Youtube Learning gmail.com then the two is going to be uh a very old email of mine just for this is just do one for testing and then subject is equal to meeting minutes and then I want the message text equal to the body okay this is the parameter that is going to be given to us using the AI next we need to actually create the message so we can say message we so this is going to be create the actual
message to send or create the draft with then we can say draft equals create draft and you can see the user ID is me right you're expecting wait isn't there like this is a weird ID but if you say me as the user ID then it knows that I am going to be the user right my authenticated self is going to be the user so you can just put me there and I actually want to wrap all of this in a try statement right so I want to do all this and then instead and say
email sent successfully and there's an exception if not there we go that's what I want make sure that I actually return something if it was successful okay perfect this is what I want okay so now we've created a custom tool to be used by the agent now let's go ahead and add that to the agent so let's go go to our Gmail crew we need to import this so from tools. Gmail Gmail tool import the Gmail tool and then we can uncomment this as a shortcut is either control or well for me it's command slash
command forward need that comma there and we're going to add the Gmail tool as the part of this agent okay we are close to being done we are very close to being done now back in the main python file we need to flesh out this last function so we need to import from cruz. Gmail crew import. Gmail crew. import Gmail crew you can always click on this and make sure that that is correct uh I think oh it's it's asking for that to be Capital C which actually want that to be and which means that
needs to be the capital c okay we come down here now we need to instantiate This Crew so we can say crew equals Gmail crew the inputs you know this it knows we have we're looking for a body as part of the inputs so we can say actually draft crew and we're going to crew so the Gmail crew. crew. kickoff and then add the inputs here which is really just the body which ends up being the whole summary of the meeting minutes and then just for clar ification I just want to print out the draft
to make sure that we have something working properly and there's one more thing I want to show you with the flow it's just a it's a part so it's another thing that we can look at the actual flow as a diagram right so once we create the medi minutes flow you can say medium ASF flow. plot before the kickoff and it'll create HTML page for us now there are a couple ways you can test this just to make sure this works right you could comment out most of the logic like you comment comment out all
this stuff from each of these functions and then just um give it something in here you just give it something to make sure that the Gmail actually works right that is something that I would do uh instead of going through all this again now also what's going to happen is when you first go to uh use the credentials it'll probably redirect you to a web page which I will hopefully happens to me and then it makes just makes you want to authorize one time it's just one time uh but go ahead and authorize it and
then it will continue the flow it ran and now it got to the point where I need to authenticate my email for the first time so click on your email continue continue the flow has been completed we can close this box perfect and it is saying that the email was successfully sent so let's go through this real quick and then I'll actually check maybe I should have checked first before I actually get through this but so generated the plot which I will go over with you it did that right here this is the HTML file
we did the same thing it went through the whole all the transcriptions right it created the summary wrote the meeting minutes for the summary action items and the sentiment came down here to the summarizer so it went ahead and did that so this is now the meeting or sorry went to the meeting uh minutes writer so it created the meeting minutes so has the sentiment the action items and then some overall summaries just like we wanted right now it's going to create the draft meeting minutes we authenticated it and this is going to send this
is the provided body so send the email with this provided body and it we went here and okay this is the URL we went to and this is the Gmail draft agent it's using the Gmail tool for the body argument we passing in what we just saw above and it's saying that the email was sent successfully even though it should say draft was created successfully but that's okay let's go let's look at my email well first off you can see I tested this a lot uh yesterday and this morning so right now it is 9:47
this was sent at 94 or created at 9:45 so just 2 minutes ago and look at this right this is this is really awesome right it's from me to my other email and because we changed that markdown to HTML format look how pretty this is I mean I know we can maybe do more with this but you can anytime that there is an MP3 file from some meeting that is created you could just have it grab that and then go through this crew and look it automatically creates a draft and then you can send this
out to whoever you want to right this is really saving a lot of time for writing notes and summaries of actually what happened in that meeting but this is awesome and I'm really happy this worked I know that was a lot but you did great if you stuck around with me I hope something worked please you know leave me comments in the section in the comment section down below or you know you can send me an email join my Discord whatever it is join my school community that I'll also have in the description but let
me know how things went for you and I'm always here to help now the next thing we're going to go over is Agent Ops and the reason we need agent Ops or something like this there's also like link trace and arise is because we need observability and monitoring for whenever we go to run these Crews or any agents in general not even just crew AI but for any agents it's good to know like what's happening how much things are cost how many tokens were used and Etc right there's so much that we can learn and
especially if something goes wrong it would be nice to have an easier way to see or debug what happened well let me explain agent Ops and then integrate it into our meeting minutes project okay so what is Agent offs well whenever you run any agents whether it's a crew where they using well any AI agent framework lot's going on under the hood right you you may have different llm calls different tools used and you would like to know how many prompt tokens how many completion tokens what was the overall cost you know if you had
an error instead of having to Doom scroll through your terminal to find it you know there should be an easier way to do this well this is where agent Ops comes in they are one of the industry leading developer platforms to test and debug AI agents and I personally use them for a lot of my projects and as you can see they're already integrated with certain things like crew Ai and autogen that if youve been following me you are well well aware of on my channel for instance they have a session replay here so this
was an error kind of gave the start and end time and how long maybe it took for the air to come about this was a web search tool that was used the how much it cost here is an action performed by an agent that was updated database and so forth so during different stages of like in our instance would be crew AI during different agent executions and what tools they're using we can see how much cost and kind of dive in and drill down what's happening and like I mentioned they already have all these Integrations
especially with these top Frameworks also like Lane chain and llama index and here you can see for the research analyst agent that with GPT 4 it costs 59 cents for the prompt 20 cents for the completion but with anthropic it only cost 5 cents for the tokens input and 23 cents for the completion now they do have this pricing model but I've only been using the basic and I am fairly certain that's all you're going to need to use as well now to get started you can just start here click this button in the middle
the purple one that says start for free you'll click this you'll just sign up with whatever email address you have and then you are ready to go and what you'll do next is see this little projects here this little plus button inside the your projects you may not have any if this is your first time using it but as you can see uh I've done been doing some testing with this uh but you click this plus button you'll enter a new project I have another one say crew AI uh course and then I'll choose my
organization which you'll create that you know it's it's easy so you'll create your project and then once you do that it does say your API key is copied to the clipboard and you will need this uh because it is different for each project you will need this in order to run agent Ops on the code which I'm going to show you in a minute now if I go and click this new create uh crei course uh dashboard you know you're greeted to the dashboard there's nothing here yet because you haven't run anything that can be
associated with this project that's what we need to do but just to show you on left hand side you can also go down to session drill down and of course there's nothing here yet but this is going to show you everything we need about the chat here so let's go and integrate this with the meeting minutes project that we just created okay well how do we do this well first off it is a package that we need to install and again this will be my requirements whenever you get this so you won't have to really
worried about this but in case something happens you need to type in PIP install agent Ops and then it will install everything you need to do for this I already have installed so I'm going to clear this and this is really simple it's barely any code to make this happen so I'm going to import agent Ops import OS there are multiple ways you can do this but I'm going to get the environment key this way so I'm going to import agent Ops and then this is the main class for uh the meeting minutes right this
is where we kind of run everything and then we also Define the kickoff and this is where you know we're starting the whole flow where we take the weight file and then we end up with a draft of what the action items were what the summary was and everything else that's what we already went over in our in our major project so what we need to do now is again what it is is a session with agent Ops so we're going to say agent ops. initialize give it the API key which I will show you
where to put that in a minute but this will just be in the EnV file and this is going this initialize it returns see right here it returns a session object and that's important so we're going to return this session variable here and then once this is before the mini minutes flow when we uh go to kick it off right then afterwards we're going to say session. end session that same session object you're going to end it and then once this is done this is going to give us the URL to go and see everything
about uh the project that we just created and we ran what we need to do first is in your EnV file you're going to to give an agent Ops API key and you're going to paste that in here and then when we go back to main.py we are basically ready to go and that's really all there is to it actually there's one more thing I want to I want to show you is with custom tools what you can do you don't really need to but what you can do is if we uh go to our
crews and then go to Gmail crew this is where we created um in the tool we created our specific Gmail tool what you can do here is say from agent Ops import record tool okay then in our Gmail tool not the Gmail input but the Gmail tool above that we can have a decorator called at recore tool and then you can type whatever you want here right so instead of Gmail tool I can say uh this is used for Gmail drafting Gmail draft emails I don't think that's really a complete sentence but we just it
doesn't matter right then we can recognize that we know where this tool was used when we go look at the dashboard Okay so this was going to now recognize this tool it's going to give it this name so we can easily identify it when we go to see what happened uh with the whole process of this flow like I said in their agent Ops dashboard so now let's go ahead and run this so I'm in the meeting minutes folder here okay it's going to execute this and this is going to take just a bit so
I'll come back whenever this is done okay awesome so what happened in the the last part was the Gmail draft agent where it actually successfully created the draft it didn't actually send out an email that's fine that's just an on my part that'll be fixed by the time you get this but the session stats you know the duration was a minute and 41 seconds the cost was almost 6 cents there were and there were a total of seven llm calls now you see there tools one I that that's because we actually set the record um
that record decorator Tool uh onto a tool so it only shows one here but there was more than one call to the tool but what is more important is there's session replay so we can actually just click this follow this link and that'll take us to everything we need know about this session okay so now we come in here and we can see everything about this session right which is basically running that whole flow uh so we have all the versions of open AI crew AI the tools and all the libraries that were used you
know it cost almost 6 cents um here's everything about me as the host here's the number of prompt tokens the completion tokens Etc right and then we have this session replay where each you know these were all all the things in purple were in llm call all the tools were in yellow and I know it's missing like the file writer tools I'm not sure why they're not they're not included here but either way we know that they they were there uh but for instance here is this tool this is the name remember we named it
this is used for Gmail draft tools and but if we go to this first agent or the first uh for the first llm call this is where we started the crew AI meeting minutes summarizer right this is where we use a file writer tool to create the summary. text and then on the on the next call here if we come look at this this was for the action items and then if we go to the next one this is for the this was adding the sentiment and then you can keep going on and on so
we actually like if you click on the last one right this gives you everything each step will give you will give you part of it right um so if we come here this was kind of everything added together kind of getting ready to write write the email or draft the email so this is everything about the location the dates and then kind of the the the final mail right and then this tool here this is where we created the draft and so forth right but the better thing is this chat viewer right this is the
llm chat and these are all the calls between the system and the user so you can come down here and just look at the whole at like the history of the whole chat with this flow right amazing I mean this is really cool stuff cuz then at the end here uh right was the Gmail tool um this was the body which was the perimeter in the custom Gmail tool that we created and then you the final answer says email sent successfully even though it was an email draft that was created successfully but this is awesome
right this gives us everything we need to know so if there was an error you could come in here and kind of see where it aired out and it would tell you that there was an error and of course you can also do the overview and this kind of gives you a better idea of what's Happening um actually I had used a different I used a different API key I used the same one before I forgot to copy the new project API key in here so I had ran this once before so and total between
both sessions is about is about cost me about 10 cents and it gives you the average tokens used for all uh for for both sessions um here gives you the events uh per session the session cost uh the duration um you know it gives you gives you all the information that you can possibly need to know awesome now you have a better way to see what's actually happening with with your agents and let's say something cost too much or you're like who why does that cost so much or why were there so many calls well
guess what instead of just running it you can now understand why and then you can go ahead and fix it now we're going to go ahead and take a step back for a second and I want to introduce you to Rag and how that works within crew aai and this is actually going to be our third project this is going to be a simpler project we just went from one to the next I know but I like these little mini projects as well how this is going to work is we are going to use the
PDF Search tool we're going to give it a PDF and then it's going to use that same PDF when we ask the agent a question it's going to give it to the task it's going to go to that PDF Search tool run that query on the PDF and return to us relevant information and then kind of make it more digestible for us so it should give us the correct answer and with that said that leads us into our third little project called PDF rag okay like I mentioned we are going to use the PDF rag
Search tool so this is an example of how it looks on their document website but but it's not like a true example so I'm going to go over that with you now but we're just going to use a crew not a whole flow this time I know that meeting minutes was kind of a lot so we are going to do something that's a little bit less strenuous and it's kind of cool because I want you to understand how um rag works with crew AI so was create a crew so back in the I'm up in
the master crew AI course uh project level so we're going to say crew AI create crew and then we can just name this whatever but I'm going to say PDF rag go through this process again and then we'll come back okay so what we're going to do with this is we are just going to have two agents and two tasks the first one is going to use that PDF rag Search tool then the second agent is just going to Simply summarize everything that it got okay so we do need these agents but let's go ahead
and start renaming some things and then we'll also change the yl files so this is going to be PDF uh rag agent so PDF rag agent and this is going to be the PDF summary agent okay and then for the task this is going to be PDF rag task go and change that and then this one will be PDF summary task okay we do not we don't need this output file either uh but we are going to need to use the PDF frag tool so this is a crew AI tool so from crew aior tools
import PDF Search tool sorry tool it is using rag but they just call it PDF Search tool now one thing we need to do is I'm going to give you a sample PDF that is from a recent archive document I think just last week it's actually about agent Ops and then we need to create the tool with that okay so I have an agent ops. PDF which you will also have whenever you uh whenever you go to look at this on GitHub and then let's go and initialize the PDF tool so say PDF Search tool
equals PDF Search tool but let's give it the actual path to this agent Ops PDF so we can say say PDF equals do/ agent ops. PDF okay so now what we've done is we've given this uh PDF to the PDF Search tool now before we go to modify the yo files let's look into this and see what's actually happening okay so I'm not going to go super deep into into this but I kind of want you to have a little bit understanding because they kind of you know hide what's really happening under the hood which
is good because it kind of abstracts it away which is what their goal is but I don't want you to just run this and then be like okay so it added it was able to search at the same time like what's actually going on okay so the first thing is you know I had mentioned a bed chain already and actually if you go to their GitHub it goes to memz which I had already covered which I thought was interesting and what happens is so we call the PDF Search tool we have the ARG schema you
know we just created a custom one right so this PDF Search tool schema this is what we gave to the tool um in the crew right we said PDF is equal to the PDF so this is the main tool scheme that we're using right this is the mandatory PDF path you want to search now before it actually says search it is going to add it to the vector database and do the embeddings and all that if it doesn't exist already if you run this two times in a row the second time it won't need to
add it because it already exists so we have this initialized method so if PDF is not none so if the PDF does exist right it's going to add the PDF the self. add there's a good bit actually going on here right so uh there's this add function here there's super. add there's also this before right before we run it so we're going to initialize this it creates a self. adapter which again here in the model validator it says uh we're again we're in the ragor to.py this looks similar not the PDF search to the rag.
rag tool py so it creates this app right so this app here if we go into here this is like where everything is done with from using embed chain so when we initialize this app so it creates uh it lets you create a llm powered app for your unstructured data by Choosing by defining your chosen data source embedding model in Vector database so in here they have the database the embedding model uh probably how they chunk everything and cache and memory config so if we scroll down a little bit and so what they oh yeah
so right here the ietting model default embedding model is open AI embed their default Vector database is chroma is chroma DB and they use open AI for the llm but this is kind of what's happening in the background this is the Telemetry that they're using if the memory configuration is provided initialize the memory again I said they mentioned meem zero well it's instantiating a mem zero object okay so here they initialize the database so they set the collection name so they have defaults already for this so in the background you know you're not giving a
collection name you're not really you you can change the configuration but if you don't that's also okay cuz it kind of everything here is done for you right everything here is done so if we go back okay so if we go back to the PDF PDF Search tool so this is going to set the default adapter right so the default adapter is obviously going to be the PDF anded chain adapter which they have created in the background um so was creating this app so if self. config so if we do have we give it custom
configuration for like custom embedding models and so forth it will use that otherwise it's just all the defaults that I just went over so it creates this and this if we go into this PDF embed chain adapter so we have summarize and the Source right this is where the query happens so this is the actual query function after we add it to the embed chain or added to embed chain for the vector database and embeddings and all that so once you initialize it for the first time if it doesn't have it in their Vector database
it's going to create that so here's the query where you know it's going to print out you know this there's a lot of print outs right but this is basically embed chain app query so whatever we are going to give it to query to add ask about the PDF it's going to initialize this here so we have the result and the sources from that query which is like kind of the relevant information which we'll see so let's actually just go ahead and finish this finish creating our crew and some of that might make a little
bit more sense so if we go to our config so for the agent we know we just have a PDF agent the simple role goal and back story and same thing for the summary agent this is just a simple rooll goal and backstory okay will be in my GitHub so you can copy but for the task for the PDF rag task this is the goal or the description is to answer the question based on the PDF it's given and so we're going to ask it a question give that here and then it will search the
PDF hopefully it works it will work and give us a response back and then the same then what the summary task is doing is just providing it as markdown um and then give it just kind of digesting that and making it you know into more like like a section report okay that's all the configuration is doing and I'm sorry I moved the agent ops. PDF into the main it I put it in the tools by accident uh because we don't actually have a custom tool for this this is a crew AI tool now if we
go to the crew we are pretty much done except we need to give this PDF Search tool to this agent so in here tools you can just say PDF Search tool now you might be thinking why didn't I do PDF Search tool and then put the parentheses there so it's kind of like executing a function inside of here you don't need to do that it doesn't matter you can do either or because I had already initiated it up initialized it up here with this PDF you know you can just you just add the variable here
okay now on our main python file let's go ahead and remove this I'm going to if Main and execute the Run function okay and so when we go and now what I did is just update this so that when we go to run it we're just I'm able to input a question into the terminal and it's going to send that uh as an input to the PDF Rag and with that said there is one more thing in something that kind of happens and I keep forgetting to do this is that whenever you're searching for a
PDF file or some file within your project it doesn't always work consistently especially when working across like two different computers so what I recommend doing is importing from math lib import path you can name this whatever you want right but what this does uh this basically gets the directory where the script is located and then the path is you get that directory and then the agent ops. PDF file so it's going to say oh I'm in this directory here for Source PDF Rag and then I'm going to locate the file in here so then I
pass that into the PDF Search tool okay that makes it more consistent whenever you go to run this so now what now let's go ahead and run this um make sure that you know everything is set up your task and configurations they're all named correctly uh the input is in there correctly I will say that so for the main.py python file remember this input is crew or the yeah this is the name of the input so whenever you go to your configuration your task make sure when you ask a question here is the question make
sure that is called input if not you will get an error and just make sure you update that with that said let's go ahead I already cleared this let's go ahead and run this and what it's going to do whenever this starts it's going to create a database folder up here SQL light database F folder for the long-term memory like it is right here so it's inserting the batches into chroma DB like mentioned that's what embed chain is using as their default Vector database so let's go and answer a question like what is Agent Ops
so now it's going to okay awesome it it worked I know it worked because it's using the Tool uh for the PDF tool the input the query is basically you know agent Ops what is Agent Ops but it's Gathering relevant content from the PDF so it didn't gather everything right it's just the relevant content and now the PDF rag agent you know this um is kind of the what it retrieved from there and then oh wow this is pretty long but the summary agent um is going to take that and write a comprehensive you know
summary of that okay so that's awesome and that worked right now what you're going to see next is if I were to rerun this let's clear this let's go and rerun this it's going to try to insert the uh back into the vector database again but you see nothing comes up because it knows that it already exists and it doesn't need to so this is the actual PDF right so let me scroll down uh how many pages is 19 Pages let's go somewhere around the middle page 10 let's ask um let's ask a question somewhere
here can you give me oh ask me what is guard rails okay let's do this so I'm going to say what is guard rails so what it should do is it should give me some it should get the relevant information from here I'm hoping anyways so this is going to run and we're hoping that it gives the correct relevant content so here is here is the relevant content guard rails okay so uh constraint let's see I think what did oh you know what uh let me see if there's something else in here for example uh
what can we do here what can we do here guard rail targets rules configuring okay so I think it does actually um uh guard rails by setting targets rules and corresponding actions C figure five okay yeah so what I think what happened is there's there's there's something about guard rails in the beginning of the text as well but I know it right here said like C figure five right here is figure five about guard rails and then it's uh oh and yeah by setting targets rules and corresponding actions that is right here so it is
getting so it's trying to find relevant information based on just the simple guard rails and then it went through the next agent and summarized it so that it looks nice and you can do more with this like saving it to a file you know you know how to send an or create a draft now maybe you try sending this to an email by having it go through maybe all of you can have it go through all of yesterday's archive uh archive PDFs and do this for each one but this is you know this is what
I wanted right we want to be able to search through a PDF using basic rag agents what I want to show you is how to use code execution with an agent now I'm going to go over a couple different ways because it's a little bit nuanced and it's not all told to you the whole stor not told to you in the documentation so I'm going to go over that let's see how that works there are a couple things about code execution with crew aai and I'm going to go over those the easiest way to do
this is in your agent that you want to have execute code is you simply have this property called allow code execution and you set that to true now by default this is false so you have to set this to true and whenever you do that based on you know the task that's given it will create code and then execute that now the thing to know is you do have to have Docker running this relies on Docker because that's it'll create a container it'll execute code inside of that container is not going to run it on
your local machine and that's a good thing generally that's that's a really good thing however the example that I'm going to go over with you requires that we have a file that it's going to I'm going to give it Parts about the CSV file like some of the column names and what I want to do with it it's going to create code to give me whatever I want to analyze about that file so with that you can't just directly do that this way because you know dock your Docker container doesn't have doesn't know or have
access about your file path or your local machine to get that file path you have to mount a volume and then you can copy that file to there however whenever you allow this code execution you know a lot of what's happening is done in the background with Docker so without actually modifying you know modifying the code and the background for this you know it just is what it is so there is actually a second way to do that and if we use the code interpreter tool it says here right this is actually what's really being
used whenever they go to allow execute execution of code on that agent is it's using this tool and you can see the requirements for this is Docker however that's not entirely true you actually don't need to have Docker and so we're not going to be using it this way we're going to be giving it this tool but there is a parameter that I'm going to show you in the code that we can use so that we can run this on our local machine and it can recognize a file that I wanted to analyze okay so
that is what we're going to do now now I'll have the CSV file ready for you that you can use or maybe I just give you the link to download it but what this is is the county health rankings rankings in the United States so this is like a 25 megabyte file right so it has mean it has a lot of data here and what I really care about is like there's a column F this is called measure name so it's going to measure different things let's just such as violent crime rate there's like diabetes
um you know screenings for different things medically we scroll down here children and poverty you know I haven't seen some of these yet but physical inactivity like there's just so many uh there's so much data here but all I really want to know is the most violent counties in the United States um I want to give I just want to really return the top 10 so I going to have an agent with a task to create code to based on whatever I give it from the CSV and then execute that and then return back to
me the analytics of whatever I'm about to show you so this is pretty simple it will be under the code execution folder actually just created a crew through the CLI you know through the terminal where we use the command to create a crew I just did that and I just modifi it there's actually only one agent and one task and this County Health rankings you know you can either use it um I'm not using the one that's in the project uh because I was trying to do some things but uh I also have in my
downloads folder on my machine so I'm just giving it the full file path and then I'm going to give that as the input so that it it has this in order to do the analytics with right is I'm not using rag it's just it's going to look at this um probably through the Panda's library and then it's going to create the code to give me what I want okay now in our crew AI this is where we just have a single agent and a single task so I just have a coding agent and a data
analyst analysis task so we it first imported from crei _ tools which we have done before in this course we have the code interpreter tool now I give that tool to the coding agent and then in the property here so if we go inside of this this unsafe mode basically if we go if we scroll down to where it's being used okay so when it actually goes to run this tool it's going to check if true this means it's going to run code in like unsafe that basically just means on your machine or if it
where it's by default false it's going to run in Docker where you have to have Docker running and it creates the container there um whenever it goes to run this so it takes it takes just a little bit more time so I create the container and then execute it but I want to run in unsafe mode so that I can use a file on my machine and do some data analytics on it so if we go back here I set I now set uh unsafe mode equal to true because I just want want use locally
and then everything else is kind of the same right I don't have I commented out they allow execution uh allow code execution to true and then for the data analyst task I just have getting the configuration from whatever I have from the configure from the config folder so for the agents in the task Amo file this is pretty simple you'll have this um you know I'm having it as saying use the file from the file path which will be given you can update that you'll have to update that to wherever it is located on your
machine but then in the task gam file is I wanted to analyze the given data set and calculate the top 10 counties with violent crime rate here's the full file path um the col these are the columns that I want to look at and you know I just want basically give me the result of the code execution of the analysis all right there's no extra tools I'm giving it and that's basically it so now let's go ahead and run this and see what happens okay so here we are I ran the main python file um
I know it looks a little different I just right click the main python file and R it in the terminal but for the data data analyst agent you know we only have one agent has the one task so this is the task here now it says the requirements are already satisfied and that's because when it went to execute the code you know it's using pandas uh numpy um you know is using these different libraries and needs to make sure that they are installed on my local machine probably well in this in my environment before it
can execute it right because it can come up with the code but when it tries to execute if I don't have the libraries it's just going to fail right so that's fine and then of course you can see here is the code that was created by the code interpreter tool by the data analyst agent and then if we scroll on down here it gives us the final answer so it gives us the top 10 over the years right doesn't have to be it's not each year in a specific year it's over a span of years
what were in in those years the top uh the top 10 worst uh counties in the United States as far as violent crime rates go looks like New Mexico I believe is Missouri CU St Louis St Louis is in there and then Arkansas so it looks like they hold the actually it's just like three different counties too each time wow anyways I don't I didn't I just got the information online I don't uh know how they got this raw value for the crime rates you know this is just a way to show you that you
can take a CSV um as a as a file you can take a CSV and then interpret the data by having it create the code for you then executing it and then getting an output awesome stuff and now I want to get into to the last portion which is the no code version of crew Ai and what they've done recently is create something called crew AI Enterprise and you can join for free and try this out as I'm going to show you but this is a way to use no code to create your whole crew
let me show you how to do this okay so let's begin with crew AI Enterprise now the first thing you need to do is sign up if you haven't already it's free and as soon as you sign up you'll be able to go ahead and start right away there's no waiting for them to contact you like they're used that there was when it first came out you'll be able to start right away so on the sidebar here there's you know a good bit going on if this is your first time looking at it but the
main one is the cruise this is where you will have all the crews that you generate uh this is where you can deploy them and you can run them but the first thing we need to do is there is an LM connections we need to go here and we need to actually create a connection so how do we do this is the first thing is we need to have a connection name now this can be uh on the right hand side you can select a provider these are all the providers that they allow in crew
Enterprise right now you know I'm sure this will be expanded as you know as this matures but for right now let's just go ahead and select open AI let's choose uh let's choose one of these see GPT 4 let's just do GPT 40 and I can just going to name this master crew AI course okay just so that you know that this is what I'm using right now then in the environment variables right here we need to actually add the environment variable for this and we know that as as we have been uh using this
in our code it's openi _ aior key and then you're going to pass in the uh your plat your openi platform key or API key right here so go ahead and do that and we'll come back all right I pasted here so then you're going to choose add connection and now I have the master crew AI course connection right here then in the environment variables uh this is used if it's like you know within the code you may not necessarily need to do this but this is with your crew will'll come back to here but
this is like if you need anything like a serer API key right if you need to search the web you need a serer API key if you're using that or if you're using firra whatever that may be you need to put that environment variable here just like you would use in the EnV file in your code but what we need to do now is Select our default our default llm connection so if you go to settings and you can see here you're under members roles defaults and billing go to uh go to defaults then you
know this is my organization name um and then the llm default so the default the LM default for agents the LM connection is I'm just going to go ahead and choose master uh C cor select gp40 but then there's also a default for the crew Studio which we're about to go which you're about to see I'm going to choose master crei course and then the model I'm going to choose is GPT 40 you can select more than one model per llm connection but for now this is I'm just going to use 40 and go ahead
and click save settings okay settings have been updated successfully now for the most powerful tool in my opinion of this whole CA Enterprise is crew Studio this is where we can talk to an assistant just like you would any any like chat program and then we can ask it to create a crew whatever we want it's going to build out a plan for us we can modify it and then we can go ahead and deploy the crew from here so let me go ahead and do that now all right so make this simple I want
to search online for the latest Google Trends to AI then compile them together and save into a file you just simply hit send and you know it's thinking depending on what you're doing it may not take super long but it's going to come back with a plan for how we want to create this so here we are the automation plan is to compile the latest Google Trends way to Ai and save them into a file so there are tools that are being selected here we have the serer dev tool and the file read tool and
the file read tools for saving the compiled Trends into a specified file it's giving us two agents the trend search agent and a file save agent but there's three tasks right that's okay you can have three tasks you can have more than one task assigned to an agent and that's okay so the trend search agent actually has two tasks and you know I can it says does this play Aline with your expectations let me know if any addal requirements or adjustments are needed so I'm just going to say yeah I like this go ahead with
the plan all right then I'm going to hit send and then it you know it says like oh you know there's probably nothing else you need to modify so now it's going to give me a grid of all the agents and task and descriptions and then we can actually go ahead and modify that well let's go well actually it makes sure that there's nothing else that need to be done I'm going to generate crew plan and now it's going to give us um this grid where we can modify anything we want about these agents and
the task and and description like I mentioned right here oh okay and here it is we have the agents so at the end of the after it looked at it again it actually created three separate agents so a trend research specialist list content compilation file management and then here are the task for them and we can come into each of these right like the expected output for the um for the latest Google Trends I can modify this to whatever I want and then it's going to generate the crew based on whatever I modified so then
the agents are assigned of the task are assigned to each agent and we are good to go I'm not going to modify any of this but you can if you want to so I'm just going to say generate crew what's going to happen now is it's going to B it's basically creating the code for this um it's going to create that as a crew that we can deploy within crew crew AI Enterprise and you're not actually going to run this locally so here you can actually download the code so if I click download code this
may take a second but there's going to be a zip file of the crew right so right here it says AI Trends compilation let me open this let me bring this to the center a little bit you know if I unzip this so if I kind of open this up I mean this is going to look exactly like youve seen right like uh here's the configuration for the task the task in the agent emo file here's the crew file the main file here's the custom tools pack I mean all of this is here right that
you need and then this is also this is also like a a node-based way of looking at it and you can you can actually modify where each of these go where uh this goes if you still want to like if I had a reason to you can but now I don't really want to do anything with this the crew is called AI Google Trends compilation I just wanted to deploy This Crew so and the actions I'm going to click deploy crew this is going to it take it does take a few minutes for it to
deploy um online so that we can run this but it's going to first deploy and it can take up to 10 minutes um the one thing that we need to do is we know that it uses serer right we know that it uses serer and actually already have it set up but in your environment variable you need to cre create the Ser serer API key environment variable and then go to serper doev which I have already mentioned in this course and then you create your key or copy the key that you've already used and then
you just put that here right so you can uh you'll put server Dev or server API key here and then your key and then hit save variables and then it will be listed here so it can be used within the crew so we come back to crew and while we're waiting let me just go over a couple quick things in the sidewall here so you understand or at least can see them so in the templates here what you can do is these are kind of geared towards marketing and sales but this is like a private
repo of templates of cruise right so this Enterprise content marketing this is something that you can either download the code for or you can deploy it within crew I crew AI Enterprise here's a sales offer generator job change monitoring crew Prospect analysis I mean any of these that you can use right here's even a zenes integration so you would need to have a zenes account get your API token email all this stuff right it kind of hints at that um inside of this inside of this each template but this is pretty cool place to start
if you're not really sure what to do you can just come come down here here's a meeting preparation you can download this use it locally or this can be your first one that you use here in the crew when you deploy it it'll come back to the cruise sidebar menu there's also Integrations right now there's only three so I've already integrated my HubSpot account but you can also integrate slack and zapier and you can mention when you create a crew that would like to create a crew that maybe just retrieves all my all the contacts
I have in all their emails and then you know maybe you can save them to an air table or save them into Google Sheets and then you can maybe prepare an email to send to those what what whatever that may be right but you can also uh integrate these into your Crews just by connecting your accounts and there'll be adding more like more things to this as it goes on as this is still like relatively new but this is just kind of showing the power of what you can do with crew ai's Enterprise okay now
that it's done you may need to refresh the browser to show this uh but I can go to manage and then I'm just going to Simply click trigger crew and what this is is kind of like a combon board right so I'm going to click trigger crew I didn't really have any inputs uh for this so it's just waiting execution and then this will eventually move to running uh you know whatever it's started sometimes you may need to refresh which they have up here here now it's actually running the crew and then whenever it get
to the completed stage we'll actually have the output for me right sometimes it takes a few uh depending on what your crew is it could you know it could take a little bit to run everything right it's got a in this one in particular it's got to search online for Google Trends and that's going of compile them together and make them into a nice format for me all all right it is now in the completed board so if I click on this you know it gives you some metrics right the total tokens that were used
between the prompt and the completion uh think get to over like about 7 llm calls in total uh this is the output right this is the structured documental AI Trends and this is kind of giving me a full in-depth analysis and even gives me the references of where it got these Trends from like you know that's this is amazing right this is actually like the markdown of uh the output and you can simply copy it um here at the task right you can come in here and see the task also as they're being completed you
can see if there's an error which one was completed and so forth right but this is you know that was amazing right I took you know I went to crew Studio there was no code involved I didn't do anything code related it created the crew for me I simply ran it and I got this output you know this uh this like whole idea of uh having like a no code component to complete something especially if you're not familiar or you don't really care too much about coding things you know this is the way to go
now if you want to have a lot of Crews of course you have to do you have to pay for a bigger plan you know the free plan let you do so much right but this is to get your feet wet and I highly recommend trying this out thank you so much for watching this course and I hope you got a lot of value out of this if you have any questions at all you can leave them in the comment section down below email me join the Discord and ask me there like people do or
also join my school Community either way I know if you watch this you'll be able to do more with AI agents thank you for watching I'll see you next video
Copyright © 2024. Made with ♥ in London by YTScribe.com