I Automated My YouTube Channel With CrewAI [Free Source Code Included]

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hey guys in this video I'm going to show you how I've automated my entire YouTube video creation process using crew AI to make my life 10 times easier and by the end of this video you're going to learn how to set up a crew that can do some market research on YouTube to find related videos it'll be able to create titles descriptions and also prepare an email that can get sent out to all of your email subscribers you'll also learn how to create some custom tools that crew AI can use and you'll also learn how to set up some human in the loop feedback and you'll also finally learn some of the new updated crew AI features that have just come out in the past few days so we got a lot to cover and don't worry if that seems like a lot we're going to cover everything step by step and I'm also going to be giving away all the source code for this video completely for free all you have to do is just click that source code link down in the description below and before we dive into the rest of the video I have a huge announcement that I'm excited to share with you I'm launching a free school Community for all of my viewers and in this community you'll be able to meet like-minded developers you'll be able to post about bug that you're having so that everyone can work together together to solve them and you'll also be able to hop on weekly coaching calls that I do with the group so I get to meet you guys and we get to solve problems that y'all are having so I'm super excited to launch this community it's completely for free all you have to do is click that link down the description below and I'll be able to see you over in the school but enough of that let's go ahead and dive into our crew YouTube AI so now it's time to dive into automating my current YouTube process and to help this all makes sense here are the three steps we're going to follow first I'm going to quickly cover my current YouTube process that's a manual second I'm going to show you the final output that I want my AI crew to generate just so you can see the final output that we're shooting for third what we're going to do then is hop over to visual studio code where we're actually going to start building out the crew to actually automate the entire process so let's go ahead and dive into the first step and cover my manual YouTube creation process so now it's time to dive into my current YouTube creation process and I'm going to cover all the manual tasks that we're about to automate so whenever I have have an idea that I want to make a video on the first thing I'll do is go on YouTube and see how this video topic is performing out in the wild eventually after I keep researching what I'll find are a few very well performing videos and what I'll do is I'll look at the view count of the video compared to the subscriber count of the channel and what you'll notice is that there are 20 times the views compared to the subscriber count which tells me that this is a viral video topic and I'll keep continuing my search just to make sure this isn't a fluke and I'll find videos like this as well which is a phenomenal definitely recommend checking out after this video of course and but what you'll notice is this one has around 260,000 views and her channel has around 213,000 subscribers which once again means you know more views than subscribers mean that this is a viral video topic okay cool once I have figured out the video topic I'll you know I'll go off and code it and I'll go off and record the video and all that fun stuff and then when I'm finally done doing all of that what I'll do is I need to you know upload my video to YouTube and then I need to do a few more manual things first I need to come up with a title and this is actually very hard but we need to automate it cuz it's you know chpt could do this I'll also come up with a description just like this once again this takes a little bit to figure out what to do and then finally what I'll do is if it's a video that I think will really appeal to a lot of my subscribers is I'll come up with a basically newsletter blast that I could send out as an update of like hey guys I have a great new tutorial that I think you guys should check out so as you can see I need to come up with a subject line and a body content that I could put inside of this email blast Okay cool so that's my current manual process so let's go ahead and into what I want my AI output to be to simplify my life and you know take down this process that currently takes hours to just a few minutes so let me quickly cover the final output that we want our crew AI to Output after we've kind of told it that hey I'm interested in making a video on this topic it should output this document right here so let's run through it real fast so the first thing is we want to be able to see how similar videos are performing in the same category so this is a quick way just to you know run that check that I was showing you earlier like hey you know how's the view count compared to the channel Channel subscriber count and how long has this video been out and you know we're going to be using some YouTube searching custom tools to do this and prepare it for us so after I've kind of seeing how videos are doing on this topic it's going to help me generate 10 potential you know High clickthrough rate titles so these are you know some honestly pretty good titles they're all under 70 characters they're going to look good on YouTube and then from there it's going to generate a YouTube description for me that I can paste in over into YouTube to make my life easier you know just tweak a few things but this honestly looks awesome it even has some links and everything and then finally what this is going to do is go ahead and do an email announcement to basically you know hey here's a recap of this latest video which is you know automating task using crew aai it's going to allow me to put like a insert to the video link so it's going to look exactly like the emails that I've been sending out but this is all automated this took about 4 minutes to run where normally that takes me you know honestly hours of previous manual research typing and so forth and so forth so I super excited for you guys to actually see how we build a crew that automates all of this and saves basically a ton of time so let's go ahead and head over to a new instance of Visual Studio code and start building out our own crew aai solution I am so pumped for you guys let's go ahead and dive in all right guys now it's time for us to dive into the fun stuff where we're going to start coding up our crew and just to paint a road map of what we're about to do next first we're going to create a new folder where we're going to store our project and then we're going to go ahead and create these seven key files that we need to run our crew so let's go ahead and start working on that first step so what we're going to do is make a new folder called automate YouTube with crew Ai and what we're going to do is open up that folder inside a visual studio code fantastic and what we're going to do next let me make it a little bit bigger for you guys so yall can see it so I'm going to go ahead and start working on the and basically creating the seven key files that we need to run our crew so the first file that we need to work on inside of our project is going to be called a pi project. tomomo file and what this file does is it basically stores the information about our project and all of the dependencies that we're going to need to install to basically run it the next file that we need to work on is going to be our main.py file and this main.py file is going to store all of the logic and connect all of our agents and task together and basically run the crew the next file that we're going to work on is going to be our agents. py file and this is going to be where we store store all the Logics for running our agents you know the goal of the agents the backstory and everything like that the next file that we're going to start working on is going to be our task. py file and this is where we actually specifically Define the task that we need to execute in order for us to actually create that output file that you saw in the previous portion of the video fantastic the next thing that we're going to do is we actually need to set up a EnV file and this is where we're going to store all of our environment variables specifically our open AI key and also our YouTube API key more on that later and then what we need to do next is actually create a folder where we're going to store our tools and what we're going to do in here is we need to work on creating two different different tools the first tool that we're going to create is going to be called our vide details. tools Pi sorry tool. p and this is where we're going to be able to actually look up all the information for specific YouTube such as like the last date it was published it's like count it's view count and everything like that the other file that we're going to start working on is going to be called our YouTube video search tool and this is how we can actually type in a you know specific basically topic that we want to learn more about and go off and find 10 or 15 different videos on that subject so these are the key files that we're going to be working on inside of our project so let's go ahead and start diving into our PI project. tommo and this is where we're like I said going to go ahead and start defining all of our dependencies for our project all right so let's quickly go ahead and knock out this file and what I'm going to do is just actually go ahead and paste in the final result and the reason I'm doing this is because I just want to save us time so we can actually move on to the fun stuff we're actually building out our crew but let's walk through this super quickly what we're doing oh and real fast I do want to mention as a reminder you can actually just downlo download this file I have a link to the source code so you can actually just go ahead and download and copy and paste this into your own environment so you don't have to spend all the time typing it up but okay let's finish walking through this line by line well right out the gate what you'll notice is we are going to be using a tool called poetry and what we're going to be doing inside of poetry is actually creating a virtual environment for us that's you know if you've been using python for a little bit you'll notice as you work with different projects you create different python environments that each have their own dependencies that are specialized for that specific project so that's exactly what poetry is going to be doing for us and it's up to us to go ahead and give poetry all the information it needs to create that virtual environment for us so as you can see we are going to be creating a environment called you know automate YouTube with crew AI pass in some extra metadata and then we're going to define the dependencies that we want to use inside of this virtual environment now here are the important parts that you need to know about these dependencies specifically crew AI we are going to be using version 0.19.0 for this tutorial if you actually run into a bunch of bugs when you're using crew aai I would definitely check out to make sure you're also using this version of crew AI cuz this dependency is getting updated religiously just a few weeks ago we are on version 11 now we're on version 19 and there's a ton of you know improvements but also some breaking changes that were made along the way and this is actually the perfect time to go ahead and mention some of the improvements that were added in version 19 what you'll notice in this tweet is the efficiency of using tools is up over 1,000% we're also slashing error rates by 67% so this tool is becoming more and more reliable and I'm just pumped that you know we're able to start using this kind of technology so okay enough of that let's go ahead and actually start diving into setting up this tool and setting up our dependencies and creating an environment so we can start you know go off and doing the fun stuff and start coding so what you need to do is go ahead and open up your terminal and once you're in here what you're going to do is if I type in the word poetry mine will actually go ahead and you know recognize that this is a command line interface and then I've already set up poetry if you need help setting up poetry I would definitely recommend checking out my crew AI crash course for beginners and I walk you through how to set up poetry on your own computer but enough of that let's go ahead and actually dive into setting up this virtual environment so so all you need to do is just type in poetry install D- no root and what this is going to do is go off and install all those dependencies that we just mentioned right here so that's going to take a few seconds but what it's going to do as you can see it just finished what you can do now is Type in poetry shell and what this will do is actually go ahead and open up and activate that python environment that we just created so you can see yep we are spawning a shell and now in my terminal you'll notice that I am using the environment that we just created so that's super easy it's way easier than setting up requirements files and all that stuff so I'm a huge fan of this but what you'll notice is whenever we go over to another python file what it'll do normally on your code probably in your Visual Studio code it'll have you know just a random python version down here just like this well what we can do is actually tell Visual Studio code as we go forward and start coding up our python project that we want to use this environment when it comes to like doing all our linting and other fun stuff just to make sure and this will make more sense once we hop into the code but I just want to go ahead and get us all the setup knocked out of the way before we move forward so what you're going to do to set up visual studio code to work and integrate with this new environment you just created you're just going to click down here and you're going to click enter interpreter path and you're going to paste in that shell URL right there so I'm just going to paste it fantastic and now you'll notice that my visual studio code is set up to use this virtual environment so okay cool we're officially out of the setup phase so what we're going to do next is go ahead and outline our main. python. file so you can see the overlay of the project and then we're going to start actually populating everything one by one such as creating our agents our task our tools and so forth so let's go ahead and start you know putting all of our todos in here and then hop into coding up some python so let's go ahead and paint a road map of what we're going to do next and the order that we're going to do it well first what we're going to do is go off and create our agents next what we're going to do is create our task which are going to be used by our agents and then finally one of the other major things that we're going to do is create our different tools that we want our agents to use and all of this information is actually going to be put inside of our main file but we'll build this out as we go so let's go ahead and clear all this out and start working on our agents. py file so the first thing we're going to do inside of our agents. py file is go ahead and create a class which we're going to call YouTube automation agents and what this is going to do is actually just go ahead and house all of our different agents that we want to create so here are the list of the different agents that we want to create it's also important to mention that what I like to do is basically create a agent per task and if you remember in our final output what we went to do is have a YouTube researcher cuz that's how we're going to like analyze what's happening in the market then we're going to create some titles for our potential YouTube video create a description and then finally we're going to create an email so that's exactly what we're going to be doing so first off what I want to do is create a research manager and this person is going to go off and like I said research our you know what's going on in YouTube and we'll Implement these in a second I just want to you know go ahead and like paint a picture before we actually dive into doing it okay let just copy and paste the next one we want to do is do a tile itle Creator and this is going to be the agent who's responsible for you know creating our titles then we're going to have a description Creator and then make another to-do for that and then finally what we're going to do is have an email creator So Def email creator okay so like I said pretty straight forward and the other thing that I like to do just to make sure that all of this gets orchestrated properly is I like to define a basically a manager of some sort so I'm just going to call this a YouTube manager and what this agent is going to be responsible for is basically making sure that we do the research first then we go off and create the titles then the description and then we go off and create the emails so like I said this is going to be the agent who's responsible for orchestrating everything now what I'm going to do to help speed up this process a little bit is I'm actually going to paste in the agent that we're creating each one of these sections but I'm going to walk you through why I put in the information that I did in each one of these so that when you're off creating your own agent you'll have some context of like oh yeah I need to be thinking about this so let's go ahead and start start knocking these out one by one so the first thing that we're going to do for our YouTube manager like I just mentioned this is going to be the person who oversees the entire process I like to think of this as the manager who is orchestrating the whole process so what you'll notice is we'd say that hey you are methodical methodical and detailed oriented manager and you are responsible for overseeing the preparation I'm going to zoom out just so you guys can see the whole thing but you're responsible for overseeing the preparation of the YouTube video now we have to put on our manager hats and think about well how do we want our different agents to work together well that's where we Define it right here we say it is up to you to go off and do these tasks in this specific order so one of the things that I like to run as a test whenever I'm creating agents is I should be able to hand off these instructions to a middle schooler and on their own they should be able to go off and execute what I tell them the more constraints and the more processes and the more like basically simplistic the instructions are the more likely the crew is going to go off and generate the exact results that you're looking for so let's go ahead and actually walk through this so I say hey at first it's up to you to go off and search YouTube videos I want a minimum of 15 videos on the same topic that we're creating a YouTube video about once you've done that I want you to go off and create a list of titles and I give some instructions for what makes a great YouTube title and then from there what we do is say hey go make a description and then finally write an email now that we have like defined the process that this agent needs to follow here are a few other important things that I think you should know about this we are allowing delegation and the reason we do this is because we want our you to manager to go off and hire our research manager or our title Creator or basically any of the other agents and then also you'll notice I set up verbos to tr so we can get some good logs okay all right let's speed through and actually start working on the next agent so the next agent we're going to work on is our research manager now if you remember this is going to be the manager who goes off and researches our YouTube videos so I should be able to say hey for a given topic and description I want you to go off and find 15 High performing videos on the same topic and it's up to you to populate a research table which we'll talk about more in just a minute but in this research table I want you to go off and basically find all the information that you need to for a specific video and what you'll notice in just a few minutes when we go off and research the videos you'll notice that we're going to be researching just like searching on YouTube to go off and find videos and then for each video that we find we're going to go off and actually do some additional digging to find you know the view count the subscriber count and so forth and so forth all right now here are a few other things that you need to know about this basically this agent the other thing is that we're going to be using tools now we haven't defined these tools yet but this is where like I said we're going to go off and search YouTube and then we're going to go off and search specific video details per each video and these are going to be some custom tools that you and I make so I'm super excited to dive into that in just a few minutes all right cool now what we're going to do next is go off and start creating our titles now this one is going to be like I said super super straightforward basically just like hey you are a title Creator create 10 titles and you know it's going to be up to the task to like really Define what goes into making a great title and the rest of the agents like I said they're also pretty straightforward too when it comes to our description Creator basically look identical to our title Creator except you are now creating a description all right and then we're going to move on to our final one which is just going to be our email agent and what you'll notice for this one is what we're going to do is say hey go off you know it is up to your job to make an email that we can use to promote the new YouTube video and what we also do is give it some additional instructions because we want this email creator to check in with us to make sure that we are happy with the email before we send it out the reason I did this is cuz a I wanted to Showcase some of the new crew AI tools and I also just wanted to show you guys that like hey if you're not always happy with the outputs that you're getting from crew AI you can just throw yourself as a human in the loop to provide some feedback and actually say like hey that email was good but you know maybe tone it down over here oh you also need to talk about this subject so this is a great way to actually do that so I'm going to comment this out for now cuz we haven't set it up yet and yeah everything looks great what you will notice is we're getting some yellow or some green squigglies so what you need to do is just hit command period if you're on a Mac and it'll provide some uh usually provide some some code options but if it doesn't no biggie what we're going to do is just go ahead and actually import that agent so what we can do is just say from crew AI import agent just like that and that should get rid of everything yep fantastic so this file is done and what we're going to do is go off next and start working on our task and once we've knocked out our task we'll start actually connecting everything together and actually what we're going to also do real fast just go ahead and start checking off our progress list we're going to go ahead and actually import our agents so what we can do is say agents are equal to our YouTube automation agents and now we need to import that fantastic great and then what we can do is actually go ahead and create our agents here as well so what we're going to do is just say hey we're going to make a YouTube manager and this is going to be come from our agents file and we're just going to go ahead and do the rest of our agents as well just like this fantastic all right give yourself a pet on the back you just knocked out the first part where we set up our agents and now we're going to go ahead and like I said and move on to task let's go and open up that that file and then start adding all of our task and this is actually like the meat and potatoes to the task if your task aren't set up properly everything's going to you know go go a r so this is where we're going to spend most of our attention so let's go ahead and dive in so the first thing I like to do when creating my task file is to create the class that's going to store all of my task so I'm just going to call this my YouTube automation task class and then what I'm going to do next is actually Define all the different task in here and to help me out what I like to do is actually open up my agents file and for each one of my agents I like to give them a single task that they need to work on so what we're going to do is actually Define a task for YouTube manager research manager and so forth and so forth so let's go ahead and start working on this first one and what I'd like to do like I said is actually just kind of like make sure the name of the task reflects or what the agent is going to be doing so in our case for our YouTube manager we want them to manage our YouTube video creation and like I said we'll go later on and actually Implement them but for right now let's go ahead and just paint out all the different tasks we need to work on and the next one that we're going to start working on is going going to be our you know our manage YouTube video research and that's going to be done by our research manager and then after that what we have next is going to be our title creation this one is super straightforward we just want to go off and create our YouTube titles so go ahead and do that and then finally what we're going to do next is create our YouTube video description is going to be the next task for our descriptor Creator and then finally what we're going to do next is we're going to have our email creator and this one is just going to be a def create email announcement fantastic all right so now what we're going to do next now that we know all the different tasks that we need to create we're going to work on the basically the manage YouTube video creation task first cuz it's the biggest one a little bit complex but it Paints the road map for exactly what we need to be doing inside of each one of these other tasks so I'm going to go ahead and actually just like I said I'm going to paste the final result and I'm going to walk you through this line by line so it makes sense so that when you're creating your own task you'll know exactly what to do okay so let's go ahead and paste this in close this out and like I said I'm going to walk you through this line by line and you know um we'll probably run into a few bugs so it'll actually be super helpful to see this being debugged in real time too okay so what are we doing inside of this task well it's up to us whenever we're creating a task to define the description of the task itself outside of that we have to define the agent that we want to execute the task another thing that we're going to do which is a newer update and version version 17 is we can actually Define an output file now so whenever this task is done executing what it's going to do is actually go off and save the report to our output folder and it's actually going to name the final report our YouTube video creation report and this is going to be super helpful so we're not you know having to like copy and paste stuff out of our command line we can actually just go open up this text file and the other thing is we need to actually now Define an expected output in the past this was an optional parameter or property for your task but now it's required so if you're running into a few issues of like hey pedantic saying that you don't have an expected output that's why it's because it's required now so hopefully that helps especially if you're running into a few bugs okay so what we want to do now is actually just kind of walk through what's happening in each one of these properties and I'm actually going to go ahead and import some of our missing dependencies as you know we're going line by line so first off we're creating a task so we need to actually go ahead and import that from crew AI we want to import our task fantastic and what you're noticing is I'm creating a super long description so anytime you're creating a super long description you can actually use dent and this is actually comes from like a built-in library in Python so if you just do from text strap import Dent what it allows you to do is do some string interpolation so this is how we can actually pass in you know a video topic and video details so um what you'll notice is these are squiggly so it's up to us in our task creation to pass in the video topic and the video details and then also the agent which we're calling down here all right cool so now that we've gotten all the squigglies out of the way let's actually walk through what I'm doing so we want this task to oversee the preparation of the YouTube video and we need to tell it what it's going to do so it's going to do some market research title ideation description creation and email creation and the ultimate goal for this task is to create a research report and one of the things that I like to do whenever I'm creating my task is to actually provide an example report so that our task knows what it's ultimately trying to achieve so that's what I went ahead and did down here I provided an example report showing like hey for video one I want you to show me the title view count day since published like this is the exact information you need to be providing to me in your final report I've noticed you know like I said going back to the sixth grader test if I was to pass along this description to a sixth grader they could go off and be like oh yeah like I could go on to YouTube and find some similar videos and yeah you I just you know I need to populate the title The View count like this is very clearcut of what my expectations are for the final report and then like I said this is just you know part one for research I'm also saying this is what you know titles need to look like here's what an example video description needs to look like and then finally down here hey this is what the email announcement needs to look like and that's that's exactly if you remember what the final output looks like from earlier when I showed it to you okay cool just a few other things that I like to do whenever I'm creating bigger tasks like this is I also like to provide context because sometimes crew AI will be like oh this is your example report I'll just give you back your example report so that's why it's up to you to like hey here's what's actually important you know I only provided two videos you need to give me 15 oh I only provided three here you actually need to give me 10 so just these are a few things that you know as you're going off and building your own task and you don't get the exact results you need you just need to provide a few more clarifications to your agents you know they're so smart and yet so dumb at the same time so it's up to us to be super explicitly clear with what we want all right cool so now that we've knocked out that first task where we Define what we want and in our description we now let's just go down to the end where we're actually defining our expected output which is now a required field so basically I just do a recap of what was mentioned earlier you need to make a report that's formatted exactly like the example report from earlier make sure it contains the exact quantities of everything I want want and also this is another place to where you can actually paste the more errors that you've gotten in the past so in my case I had some issues with the crew not always giving valid URLs so I just explicitly say you need to have valid URLs okay cool now that we got done with that task let's go ahead and move on to our next task where we're going to be describing basically the YouTube video research process so this one is also going to be pretty straightforward and let me walk you through this line by line again just so you can do this on your own too so basically for a given video topic I want you to First go off and search the internet or search YouTube to find 15 High performing videos on the same topic now what we're telling our agent to do is you know once you found those videos you need to go off and research the video details so that you can actually find all of the like counts subscriber counts and everything else and you'll notice that I keep referring to this you know research outline and research report well once again we need to be super explicit so that's why I tell the task like hey this is the exact information you need to populate and I even give it some specific Specific Instructions on what the CSV file that generates what it needs to look like and once again anytime you have an issue with a crew not behaving as it should just you know add another important note with you know errors that you've experienced just go ahead and add it down here and like I said it's kind of a trial by error process all right um and what we're going to do finally is let's go ahead and actually cover our expected output so once again I kind of just say like hey this is what your CSV file should look like and I just went ahead and populated it with two example dummy videos so that it would know what to do as it's going off and Performing its research okay cool and um it is important to note right now we haven't defined any tools but once again when we go off and create our custom YouTube search tool and video detail explore that's exactly what's going to be used to populate this information that we're looking at right here so we're slowly building up to the point to where this whole crew is coming together and once again we need to provide the missing information such as our video topic that we want to explore and our video details which actually kind of defined a little bit more about like the YouTube that video that we're creating cool so now that we've imported those missing dependencies and parameters we're going to go ahead and move on to our next task which is going to be creating our YouTube titles now this one is like I said a little bit more straightforward and what I basically did is um I said hey it's up to you to go create 10 titles based on the video topic and description and then we basically pass it in and then I kind of just give it a little bit more helpful hints about what goes into creating a high click through a title first off it needs to be under 70 characters and then outside of that I went ahead and gave it a few example titles that I've done in the past just so that it knows like oh this is the style of titles that you're looking for and I went ahead and like I said use just my own video topic so the more context and the more examples you can give it the better these tasks are going to perform so once again let's pass in all the missing information video topic details and agents cool now we can keep cruising along all right so this video description one is also going to look almost identical to the title creation one and what we're going to do just say like hey it's up to you to create a description for a YouTube video based on a topic and a description and I went ahead and just gave it an example output of exactly what it needs to do and I just copied and pasted one of my previous you know descriptions that I put on a YouTube video so that it knows exactly what to do and like I said it'll just kind of change this out for you know the video that it's researching all right once again like I said by this point you're you know hopefully feeling the repetition and that's good because this is the exact same process process that you're going to be doing with like adding uh parameters in when you're creating these different task all right so let's move on to the final one which is where we're going to create our email announcement and this one's a longer one but it's not too complicated it's just a lot of content let me walk you through what we're doing in this one once again so hey I want you to create an email here's the video topic here's the video details and what I do is say like hey here are a few previous emails that you could use for inspiration so I just went ahead and copied and pasted a few example emails that I've written in the past just so that I can understand my writing style and like hey this is what a format of your email should look like as you go off and make your own so yeah that's exactly what we're doing here if you have any questions when when you're going off and creating your own task or you know if you run into any issues first off feel free to drop a comment below love to help and this is also another good time to mention that I did drop that school Community just for you guys so that you can go off and get support from other developers who are on their Journey creating their own Crews and we have I think already over a 100 different members in the community and it's super active so like I said if you have questions that's another place that I definitely recommend going to check out so that you can get more help and actually just post some progress as you're you know making your own task and your own Cruise Okay cool so the only other thing we need to do in here is go off and once again add in all of our missing information all right so give yourself a pat on the back you've completed the two hardest parts of this whole project setting up your agents and task and what we're going to do now is actually go ahead and hop back over to our main file and in here we're going to go ahead and start passing in our agents and our task to combine them so our agents know what to do so the first thing we need to do is actually import our task class that we just created so what we can do is say task is equal to our YouTube automation task now it's up to us to to actually import that class that we just created so if you hit command period it'll provide a quick fix that you can actually import very easily we'll add this to the top of our files just so everything's formatted nicely and now that we've created our task let's go ahead and start importing them so we can start you know connecting our task to our agents that we just created so the first task that we're going to import is going to be our manage YouTube video creation and what you'll notice is inside of this we need to pass in the video topic video details and an agent well up to this point we've defined agents but we haven't Define our video topic or video details so what I want to do is just provide some you know background info about YouTube video and what I'm going to do is actually just go ahead and paste in what we're trying to do here which is we want to make a video topic about automating task using crew Ai and then I just provide some details about what I'm trying to do inside of this video and basically it's actually what I'm trying to do in this video I'm showing you guys how I'm using crew aai to automate and streamline my video preparing process so that's all we need to actually go off and start plugging in to all of our different task so what we want to do is say the agent is going to be equal to the YouTube manager we want the video topic to be equal to the video topic and video details equal to the video details so that's pretty much everything that we want to do and we're just going to rinse and repeat this for each one of our other tasks and um I do want to mention that we also need to like you know this is creating a task and returning it to us so we actually need to you know get the return from this so I just copy the name of the task over here and set it just like that fantastic so now we have all the information we need to go off and start creating our other tasks so task Dot and next one is going to be video research once again we're just going to pass in our all the information we need to create this task and we're just going to rinse and repeat for the rest of them so for our manage YouTube video research we want our research manager to work on that task when it comes to our creating a video titles we want to have our you know our title Creator agent working on that when it comes to working on our video description we want to make sure that we have our descriptor Creator working on that one and then finally for our email announcements we want to make sure that our you know the proper agent of our what do we call them earlier our email creator working on that all right fantastic so we now have all of our different task and all of our different Agents set up so what we're going to move on to next is actually the part I'm most excited for in this tutorial and that's where we're going to actually go off and create oh it looks like it didn't pull in the right one let me make sure we did that right real fast uh when it came to our email announcements we had create email announcement create oh there we go that was sorry it was a wrong wrong task but the part I'm most excited for in this whole tutorial is actually showing you guys how to go off and create your own custom tools if you're able to start refining the skill I'm about to show you guys you will be able to go off and really build any creu any crew to do anything so I'm super excited to show you this so let's go ahead and actually dive into setting up our first new tool which is going to be doing YouTube video search and real quick before we go off and create our own tools I actually just want to show you the documentation that crew AI recommends for creating your own tools okay so I'll have this link down in the description below so you can read it on your own if you want to dive in deeper but when it comes to creating your own tools there's really two ways you can go about doing it option one is by using you know subclassing the base tool and I'll explain what all this means in just a minute and the other option is to go off and add the tool decorator to your functions now what I have found whenever I'm creating my own tools I've had much better results whenever I go off and do this option which is subclassing the base tool and all this really means is as you go off and create your own tools you need to provide a few specific pieces of information about the tool so that the crew knows when it's the proper time to use it so it's up to you to go in and add a name a description and potentially some argument that you need to pass into the tool okay I know that might be a little high level so let's actually hop back over to our own tool that we're about to create and start populating some of this okay so what we're going to do is go over to our YouTube vide search. py file and we're actually going to go ahead and start creating this line by line and we're going to hop back between this and the dock so you can see why we're doing everything so right out the gate what I'm going to do is Define that I want to make a YouTube video search tool and what you'll recommend or what you'll see is that we have a base tool and this actually comes from crew AI so this is basically just saying like hey you know we're uh inheriting from this class right here okay so let's go ahead and import it to Fantastic so now that we've done that it's up to us to go ahead and pass in the proper information that we want our crew to know about this tool whenever it wants to use it so in our case we're saying hey this is my YouTube search uh my search YouTube videos tool you're going to use this tool whenever you want to search YouTube videos based on a keyword and get back a list of video search results fantastic the next thing you'll notice is that we're passing in our argument schema now what this is going to do is say hey this is the type of input that I expect to come out or to go into this tool whenever we run it and this will make more sense too whenever we actually like fill out the rest of the the tool but just like hang with me this is the definitely the most complicated part and you might want to rewatch this once or twice just to really make sure that this Clicks in okay so what we're going to do first is we're going to pass in and create our basically our YouTube video search tool input and what we're doing here once again is we're basically going to provide a description of what this tool is for and then it's up to us to once again provide more information about what is going to go into this tool in our case we're going to say that hey I want to pass in a keyword as the input and this keyword is going to be a string and we provide a description of what this you know input looks like and then we also expect whenever you use this tool to pass in Max results by default we're going to say it's 10 and it's going to be an integer but you could obviously pass in your own number if you want more or less videos and we just say like hey this is the maximum number of results you want to to go off and search Okay cool so now we've done that you'll see we get a few more squiggly lines because we need to import a few different basically a few different new types into our project so the first one is we're going to import this field one so let's go ahead and import that and our base model and this is basically just you'll notice this comes from pantic and pantic is basically a tool to make sure that basically python is not strongly typed so it's kind of a workaround to make sure that we are using typed properties and I that might sound like a lot but basically just you know all that means is like we want keywords To Be Strings we want Max results to be integers and pantic just helps us enforce typings Okay cool so what we're going to do next is fix this squiggly Mark which is we don't have the proper you know type for when we're setting up our base model so we're just going to import that okay now that we have defined all the stuff to make sure that we're you know passing in the proper parameters let's go off and actually look at what the code looks like whenever we're searching YouTube so what I'm going to do is you whenever you're creating a tool you have to Define an underscore run file and why do I know to do that well if you go back to the documentation you'll notice it's exactly what they have they have an underscore run file excuse me function that's you know is what's going to run whenever this Custom Tool gets called okay so let's hop back over here and go through this line by line so it all makes sense of what we're doing so what we're doing is we are saying Hey whenever you run I want to have a keyword just like we defined earlier and I want to have a Max result just like we defined earlier and what I expect after I run this function I want to get back a list of video search results and this is one other type this is the last type that we have to Define in this class and what we're going to do in this one is actually Define what is the exact information we want to get back from this function so in our case whenever we go off and search a video I want to get back the video ID title Channel ID channel title in days since this video is published now now now like I said penic is going to make sure that this gets returned if it doesn't it's going to mark this as a failure and it's going to retry and call this tool again until it gets back the proper information it needs okay that was a ton of that was a ton of information so let's keep cruising along now that we're actually into like just normal pythonesque code okay so whenever we're running our function to to go search YouTube We're actually just going to be using the Google API which we're going to set up in just a second but what we're going to do is say hey Google I want you to go search and when you're searching I want you to look up this information I want you to look up a keyword some Max results I only want you to find videos and here is my API key so that you know that I'm making this request whenever you get back a uh whenever you make that request you're going to back a response and what we want to do is pull out all the items from that response and we want to slowly iterate through each one of these items and build up a results array or list that's populated with the specific information that we're requesting and if you remember the specific information that we're building up is going to be our video search results so if you kind of look up here you'll see video ID title and so forth and that's the exact same information that you're going to see down here so I hope this is all clicking now that you kind of see like oh yeah that's that's how you build up results and this is you know how you populate them okay cool so what we're going to do next let's go ahead and fix basically importing all of our different missing items so I'm just going to do a bulk import real fast fantastic so now we should have all the squiggly marks gone and now it's up to us to go off and actually handle creating our API key so what I'm going to do is head over to Google and show you how you can get this API key so the first thing you need to do is actually head over to console. cloud.google.com so basically we're just going to go to Google cloud and if you haven't created an account before you just need to do that real fast it's completely for free but all you need to do is just go ahead and create this account once you've created account in Google Cloud what you'll need to do is we want to go off and create a new project so once you're in your dashboard you're just going to click your projects in the top left and then you're going to click new project once this is done you're just going to go ahead and like give your title A or you give your project a name so I'm just going to call my crew aai automation Automation and then I'm going to go ahead and save that real fast so I'm going to click create this will take a few seconds to go off and create that new project so like I said I'm just going to pause real fast and then oh wait it finished it even faster so we're just going to click select project next so what you'll notice is it updated the you know the active project to crew Ai and then I'm going to type in API and uh Services I believe this is the one we want um nope we just want to type in credentials yep so once you type in credentials you're going to click the one that says credentials API and services and this will take you to a screen that looks just like this and what we're trying to do if you remember is we want to create an API key that we could eventually pass in right here so that we could start making requests to YouTube so all we need to do is like I said we're going to go ahead and just come up to the top and like I said this might be a little overwhelming if you've never used Google Cloud before but in our case all we need to do is just click create credentials in our case we're going to click API key it'll take a few seconds to do but once it's done finishing what you're going to do is actually just copy the API key that Google generates for us so like I said this is a secret key and what you want to do is actually don't share it within the world and I'm going to show you how to do that in just a second so you're going to copy this API key and you're going to come back over here and we're going to go over to our EnV file and inside of ourv file we're just going to call this our YouTube API key it's important that the key that like said this title basically matches exactly what you have set right here YouTube API key needs to be the same thing fantastic now to make sure that we don't accidentally share this with the world especially if we're going to be using GitHub is you need to create a dog ignore file and what we want to do is just add EnV in here that way whenever we go off and you know start pushing our code to get Hub we want to make sure that we don't actually paste it off to um you know and store it for everyone to see and what I'm going to do actually just to make your lives easier I'm going to make a EnV local file so whenever you come in here later and you're actually um like I said what you'll do is in your project you'll actually just copy this EnV file and you'll just rename it to instead ofv local you'll just rename it Tov so you'll you won't have to create a file you can actually just come in here and paste your code okay I hope that makes sense all right well now that we have that set up let's hop back over to our video search tool and see what we need to do next well if you look we have our YouTube API key now so this can actually go off and do everything that we need so looks yep it looks fantastic all right so now that we have set that up what we're going to do is actually go ahead and move over to our YouTube video details file and this is where we're going to go off and actually search for specific information for a specific video so we're going to walk through once more time how we can create a Custom Tool and we're going to go part by part so that all makes sense and I'm a big fan of doing something twice just so that it clicks and you start to kind of see some of the underlying basically um Trends and patterns when it comes to creating tools all right so first things first is once again we want to go off and say like hey this is the tool that we want to create and this is going to be a base tool so what we're going to do is go ahead import this from crew AI just so crew AI knows that it can use it and then what we're going to do if you remember from last time is you know this is a tool so we need to Define what this tool is going to do just just so that our basically our crew knows what it needs to when it needs to use this tool and so forth and so forth so hey this is our G video details tool this is how you're going to retrieve specific details on a specific video fantastic the next thing we need to do is Define our YouTube video tool input so this is the what inputs do we want to pass to this tool in our case well we're looking up a specific video so it would make sense for our only input to be the video ID that we want to look up I'm going to go ahead and actually just import all the different dependencies real fast just so we don't have to keep dealing with all these Squigly lines all right fantastic well now that we defined the inputs that we want to pass into this tool let's go ahead and actually once again look at the Run function that we're going to create and I'm going to walk you through this line by line don't worry but um remember you have to define a underscore run for your tool and then you're going to pass in the parameters that you want to use and these parameters need to match the input parameters up here if you get some weird pantic issues it's probably related to like something's not matching up and then finally we need to define the output of this function in our case this is going to be the video details class and let me go ahead and Define that real fast so this is just going to define the type that we want our video details to look like and in our case we want our video details to include the title of the video view count like count discount comment count and everything else and this is what we're going to use to help us you know determine what are viral videos in this Subspace because we can compare the view count over to the channel subscriber count to see if like oh yeah this is a viral video topic all right well now that we've done that let's go ahead and walk through this line by line so that you can once again see how everything's working well what we're going to do once again make a request to the Google API for a specific video and in our case we're just trying to look up the snippet and statistics for a specific video and what we're going to do we're going to make that request once we get back our response what we want to do is iterate through each one or look at the items that come back in that response and we want to pull out specific information in our case we want the you know the title view count like count and everything else that we defined up here all right so we're going to go ahead and do all that and once we've um went ahead and actually got that information we're going to go off and actually create another request and this time we're going to look up the specific information on a channel now that we have the channel URL that comes from up here like I said we're just going to make another request get that response and pull out the final information that we need which is going to be our Channel subscriber count once we have all that information what we can do is package it all up into a new video detail object that we can pass back to our tool so like I said that was a lot of information you just set set up just a recap you created new tools as you created new tools you defined you know hey this is all the information that crew AI needs to know about them then you got a little fancy because you defined some specific types and you defined what the input for this tool looks like and you also def the output for this tool to make sure that pantic knows exactly what are the inputs and outputs of your new tools okay that was a ton of work I'm super proud of you guys and now that we just finished that let's actually head back over and start updating our task and agents to start using the newly created tools that we just created so the first thing we need to do is actually head back over to our agents file because this is where we commented out some of the tools we were using earlier so if you can see down here you'll notice that I have in our research manager which is the one that's going to be responsible for going off and searching YouTube what we need to do is add back in those tools now whenever we add back in those tools you're going to get some Squigly marks cuz it's like hey we haven't reference referenced these yet so it's up to us to pass in these tools so this is the first one we need to up update the next one that we need to update is if you look down at the bottom of the file we have an email creator who is going to use some human uh basically a human tool and all that means is this is where we're going to add some human in the loop feedback now I'm going to pause real fast cuz this one's important what we're doing here is we're saying like hey you go off and create a draft email and then I want you to talk to me to provide some you know I'll provide you some feedback now what we need to do to actually use this tool is if you head to the top of your file what we're going to do is actually go ahead and Define a human tool so we're we going to say human tools is equal to and then we're just going to say load tools now this is going to come from crew Ai and then we just type in the word human now if you actually go look and actually look inside the crew AI doc this is exactly what they recommend so let's go ahead and try importing these tools and I just need to say from Lang chain. agents I want to import load tools fantastic and now what we have is our agent file has all the tools that it needs to start operating but we need to go off to our main.py file and start updating our agents that we just updated so the first one is our basically our research manager we need to start passing in our tools that we just created so we're going to do is come back up here and we're just going to have an area where we're going to say set up tools and all we're going to do inside of here is actually import the tools we just created and real fast one thing we need to do just so we can start using this tools folder that we created earlier we need to just come in here and set up in a knit. piy fantastic just to say like hey Yep this is a folder that I want you to start using stuff stuff and all we're going to do is like I said just import those two tools that we created earlier from our tools folder I want to import the YouTube video details tool call it right here and then same for our Search tool and all we need to do is back down here inside of our agents where we were creating our research manager if I hover over this now you can see we have a basically this so we can do YouTube video details tool is equal to our YouTube video details tool and uh I actually uh made a small mistake we actually need to create like if you head back over here you'll notice that this is a class well what we want to do is actually get an instance of that class and if you know I'll show you what that means actually so what we're doing is we're going to say I want to create two tools or two instances of our tools just like this so this is um this is our class this is our instance of the class and what we're going to do next is actually pass those in down here so we're going to say our YouTube video detail tool is now going to be equal to that and we're also going to pass in our YouTube search tool I'll show you how to do that we're going to say YouTube search tool is equal to our video Search tool okay fantastic let's see if there's any oh I got to put a comma but other than that things look great all right so we now have our agent set up uh let me put this up top little clean up everything real fast so we're creating our agents here that looks great we have the rest of our agents we have our search tools things are looking great so we do need to do a few other things just to get the rest of our project working we need to actually go ahead and also initialize our the fact that we're going to be using basically chat gbt throughout the rest of of our code cuz right now what we're about to do is actually go off and start setting up our crew down here at the bottom of the file so what we're going to do down here is we're just going to say setup crew so we'll set it up and then I'll update our dependencies as we do it so what we're going to do is we're going to create a new crew and we're going to say this is equal to crew and then it's up to us to Define all the agents that are going to live inside of this crew and thankfully we have auto complete so we're just going to pass in our YouTube manager research matter and so forth and so forth the next thing that we need to do is Define our task and our task basically yep it's it's just going to include all the tasks that we just defined up here and then this is where we're going to do some of the newer features that come with crew AI so the first one is we are going to define the fact that we want our process to work in a hierarchical fashion so if I type in process I actually got to import crew real fast just so it's going to do some nicer autocomplete for us so all we need to do is just at the very top of our file we need to import it real fast so we're just going to say from crew AI I want to import a crew and I also want to import a process the process is going to tell the crew how it wants to basically work together so in our case we're going to say process is equal to and I'm going to say process Dot and we have two options we have sequential and sequential means we just work on one task at another and we kind of just like orchestrate everything to work in aign whereas with hierarchical we kind of work on things in more of a manager structure I actually have a whole another video on this feature exactly what I'm talking about right now and the basically you'll see a popup card for it right now and feel free to watch that tutorial I go in a ton of detail detail with how to use this new feature and I found that whenever you work in a hierarchical structure you get a lot better results so that's what we're going to work on right here and then the final thing that we're going to do is we need to define a manager llm who's just going to you know perform all this like hierarchical structure of saying like hey YouTube manager you kick off things first and then from there basically help orchestrating everything else so we need to like I said define a manager llm well in our case what we're going to do is we just want this to be an open AI you know we're just going to use basically gp4 so right up top what we're going to do is we are going to initialize our llm llm so I'm just going to say you know open AI gp4 is equal to and this is another dependency that we need to import real fast it just going to be chat open AI there we go so chat open Ai and we just need to Define which model that we want to use so in our case what we want to do is just use gp4 and then like I said we're just going to leave it just like that and one thing I will mention every time I have been running this task that you're about to look at it cost me about 20 cent to run so if you want to get you know run run it for cheaper you can use you know GPT 3.5 turbo but I don't get as well my results don't turn out as well unless I use GPT 4 so like I said definitely recommend using this one and what we can do now that we've initialized what we want to do is we also want to actually import our open AI developer key now I'm not going to go into how you go off and create an open AI developer key just because this will you know you've probably done it a 100 other times in your other videos and you can see how I go off and create a developer key in my other videos so what you'll want to do is in your environment variables file is you'll just want to go off and paste in your open a I key and I'm just going to do that off ins side when I'm not recording okay fantastic well once you have set that up the final thing you'll need to do is um well pause real fast the reason we actually import our open AI key is because chat open aai by default if you actually look at what happens if you look at the API Key by default what it will do is actually go off and grab I'll actually just show you guys we'll look the source code if you look up at API key what you'll notice is by default it's actually just looking up for that open AI key right there so if you have it defined in your environment variables it will actually know to go grab it by default so that's why we do this right here where we say hey go load all your environment variables it sets up our open AI llm to work for Success all right enough that let's hop back down to the bottom where we were defining our manager llm and we're just going to pass in our newer open AI GPT 4 Fantastic well now that we've set up our crew and everything we can actually start kicking it off so this is the exciting part and what we're going to do is actually like I said go ahead and kick off our crew and we're actually going to use one of the newer features that just came out in version 19 which is you can actually look up the usage metrics for each one of your crew once it's done and what this will do is it'll show you how many tokens were used to you know when it's going off and generating and researching and creating content basically as all the agents are working together it keeps track of that and just spits it out so you can actually see what happened and what you'll notice is usually the more tokens you use the more expensive the job is so okay cool so now that we have all that set up what I'm going to do next is go off and actually show you guys how to actually run this crew and this is the part that I'm super excited for cuz you know this is where the magic happens our crew is going to go off and do all the work for us so all we need to do is just open up our terminal and once we're in our terminal it's important to make sure that you are working inside of your python environment and the way we were able to do that earlier was just by running python or sorry poetry shell and this will spin off this python environment and activate it for us so that's what you need to do first but once you've done that and you're in the proper environment all you need to do is just run Python main.py and what this will do is go off and kick off our crew so this is going to take about four or 5 minutes to actually execute but I want to walk you through what's happening at first and then we'll come back once it's done so it takes a few seconds to start you know kicking off the crew and figuring out what it needs to do it's going to start identifying some task and what you can see right out the gate what it's doing is it used our YouTube search tool and it's looking up automating task using crew Ai and getting back 15 results and what's super cool is like this is actually what if you were going on YouTube you actually kind of see a lot of these videos and and actually kind of like see exactly like the channel IDs you can actually see some of the videos what's funny is I think I um I think yeah so crew AI tutorial complete crash course that's actually one of my videos so it's like it's pretty cool to realize like yeah that's actually all coming from the internet so what we can do is we can just scroll down and you can see that like yep now that we found these videos what we want our next task to do is like hey go look up the video details for each one of these videos so it's just going to do that for every single video it's going to go off and actually start searching up what's going on so this is going to take a good while to actually go off and do so what I'm going to do it just come back actually when it comes to the human input part of this video if it actually asks us for it sometimes it doesn't and then what I'm going to do is at the end actually show you the final results so I'll see you guys in just a few minutes oh real fast I do want to mention that you might get a quick error whenever your crew finish is running and that's because it's trying to Output a file to the output directory but we didn't create that directory yet so all you need to do is come back over here and just create a folder called output like I said just make sure you spell it right and then I'm going to go ahead and rerun this crew just so you guys can actually see the final output of what we just built so I'm going to come back in just a few minutes and show you the final output all right so our crew just finished wrapping up running and I think you guys are going to be super excited about the output so I go and open it up real fast so you can see what the crew is able to put together for us over the course of about 5 or 6 minutes all right so what you can see right out the top we have our research table I was a little disappointed cuz if you scroll down a little bit you'll notice it only made 10 videos so that was kind of a bummer it had a lot of time basically spinning back and forth between finding new videos getting video details and a lot so I think it just kind of ran out of context space and it was only able to Output 10 but hey that's still amazing outside that it had a ton of awesome different you know titles that had some like you know followed the exact basically parameters we set up they're under 70 characters they're exactly about what we're trying to do in the video so this was a huge timesaver for me and outside that we have an awesome video description that I'll be able to post into YouTube whenever I get to that part and then finally I have an email announcement that I'll be able to you know quickly just tidy up it did actually ask me for some human input it actually asked me like what was the URL of the video and asked me for some feedback on different things but yeah I was pretty happy with it I'm going to be able to like copy and paste this and just kind of turn some things into some bulleted list but outside that I was pretty happy with the way it it turned out but yeah all around this was a ton of awesome work on your part you are now an expert at you know working with making custom tools setting of agents and task and that's right for this video guys I hope youall enjoyed it and I hope you learned a ton about automating task with crew Ai and just as a reminder you can download all the source code for this project completely for free just click that link down description below and I also just launched that school Community just for you guys so be sure to click that link as well so you can hop over and have fun with the rest of us guys and finally if you want to see any other more crew AI or AI full stack tutorials I have a ton of other content on my channel that you're going to would check out after this video so be sure to click wherever the video pops up after this and I can't wait to see you on the next one see you guys talk to you all soon [Music] [Music] bye
Info
Channel: codewithbrandon
Views: 24,658
Rating: undefined out of 5
Keywords: ai agents, crew ai, chatgpt 4, best autonomous ai agents, artificial intelligence, crew ai tutorial, crewai langchain, crew agents, crew assistant, autonomous agents, stock agent, autonomous ai agents, auto gen, autogen tutorial, autogen create ai agents, ai agent, autogen step by step guide, chatgpt prompts, llama 2, ollama tutorial, mistral ai, chatgpt automation, youtube automation tutorial, youtube automation step by step, youtube automation with ai
Id: OumQe3zotGU
Channel Id: undefined
Length: 58min 14sec (3494 seconds)
Published: Sat Mar 09 2024
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.