automated YouTube channels are huge these days in this video I'll guide you through the steps to automate your YouTube channel using crew AI our tutorial starts with a quick overview of the AI agent we'll be working on followed by a step-by-step tutorial to build an AI agent that can automate YouTube video production using crew AI don't worry you won't need any prerequisites with crew AI to follow along I'll be explaining every piece of the code thoroughly and run the AI agent that we've built together we'll analyze the system built with crew AI discussing how it operates and what makes it work by the end of this video I'll share my honest opinions on the pros and cons of using crew AI for your automation needs I'll also suggest on what it takes to step up to more advanced Enterprise level production the method in this tutorial will help you automate around 70% of the V video production work that way you can easily start an automated YouTube channel as a side project for an additional income stream without further Ado let's get started let's get into the structure of the AI agent that we're building today when we talk about an AI agent we're referring to a system with some level of autonomy that can accomplish clearly defined goals on behalf of the users AI agents these days often involve several large language models or llms like chat GPT or claw collaborating with each other to attain the predefined goals our goal today is clear we want to automate the video production process to make our life a lot easier so what would the AI agent for this job look like first we have a Content researcher that collects the information needed for our video content and uses the data to craft a Content outline with section and key points for the video this content outline will then be passed on to the AI script writer to create a script for the video then we pass the script to the AI planner to plan the scenes of our video now we have an AI researcher that does keyword research using some tools to look for well performing YouTube videos on the desired keyword finally we have an AI writer that generates a suitable title and the description for our new YouTube video based on the script and the keyword search results if you like to explore different AI agent structures from crew AI I highly recommend checking out the examples they offer in their GitHub repo I'll put the link in the description below for you before proceeding to the project code let me explain some basics of crew Ai and how it will help us create the AI agent we just described earlier as the the name suggests the idea behind crew AI is to build a crew that collaborates to achieve predefined goals think of it like assembling a team where each member has a specific role and purpose within the crew we have the specialized agents each agent is tailored for different tasks working together to achieve our project goals they can function in a sequential process meaning the next agent relies on the output of the previous one Al these agents can operate in a hierarchical setup where a manager agent delegates tasks to other agents within a lower hierarchy once we set up the structure the agents execute tasks accordingly using the tools we provide if necessary now one thing to note is that when I refer to agents here I'm talking about the agent function from crew AI this is different from the AI agents that we talked about earlier AI agents generally refers to the entire AI system that collaborates as a whole to meet the objectives defined by the users when we get into crew AI later in this video I'll mention AI systems instead of AI agents to avoid confusion with the crew AI agent function if You' like to learn more about crew AI I recommend their short course on deeplearning. ai I'll put the course Link in the description below all right let's look at the project structure which is pretty simple and intuitive within the project folder we have main. py which is a file that runs our main crew AI setup next we have the agents.
pi file which defines all the agents at work within our AI system then we have the tasks. py file here we specify the tasks that our agents will execute this is where we clarify what exactly each agent needs to do in order to achieve our goal and last but not least we have tools. piy this file contains all custom tools will Define for agents to use if necessary don't worry if all this doesn't make sense to you right now I completely understand that it might be overwhelming especially if you're new to this we'll go through every piece of the code step by step breaking it down into portions that are easy for you to understand let's talk about the setup and the packages you need for this project here are the packages we need in the requirements file to get started the do M package to load your API keys and credentials into the environment pandas package to work with data frame crew AI with tools agent Ops for monitoring to keep track of the performance of our AI agent Google API python client for YouTube data extraction install all packages under your virtual environment okay let's move on to obtaining the required API keys for the llms in this tutorial we need an open AI API key first create an open AI account once you sign up log in at platform.
open. com new users get a $5 free credit which expires in about 3 months after that navigate to the dashboard then API key section create a new Secret key and copy it into the M file you created and please if you're using GitHub never never push your n file credentials into the repository you'll have to put m in the gig ignore file next we get the agent Ops API key head over to agent ops. a and create your account then sign in at app.
agent ops. go to API Keys create a new project and copy the API key into your dend file and now for the YouTube data API key if you don't already have a Google Cloud platform you'll need to create one at cloud. google.
com upon sign up you'll receive a $300 free credit create a new project ensure that your console is set to this new project oh and make sure to activate your free trial to a full account there's a banner at the top of your page for that go to API and services enable the YouTube data API after that navigate to credentials create credentials and select API key finally copy that into yourn file and name it accordingly all right now that we have set up our project we're ready to move on before we create the desired AI system let me explain briefly on the concepts of a agent and task in crew AI according to the crew AI document agents perform tasks make decisions and communicate with each other agents can have different roles and contribute to the overall goal of the entire crew the tasks in crew AI are specific assignments completed by agents they provide all necessary details for agent execution tasks can also work collaboratively with multiple agents involved let's look at the agents. P file we create a class named Video Creator agents within this class we provide the topic in which we prefer to create a video and the llm that our agents will be using later in this tutorial we'll create all the necessary crew AI agents in this class for a crew AI agent there are a few arguments we must define the role that each agent will take on the goal they're looking to achieve and the backstory to provide more information around that role and goal these three are required and the remaining arguments are optional we'll look further into some of the optional arguments when we focus on the specific agents later on you can check out the crew AI documentation that explains all the attributes now move on to the tasks. pile create the class Video Creator tasks with within this class we specify our topic of Interest as well as the output directory where all the results will be stored later in this tutorial we create all the necessary crew AI tasks associated with each agent for each task we Define a few arguments we provide a detailed description that explains how exactly the corresponding agent should work we specify which agent will execute the task and the expected output so that the agent knows what a successful completion stage looks like and when to stop even better if you provide a template for the output that gives more detailed stopping instruction to the agent we also specify the context to provide a list of tasks in which their outputs will be fed as the context of this task finally even though output file is optional I always prefer to have the generat response saved in the file for easier viewing and debugging it saves a lot of headaches later on now now with all that set up we're ready to dive into the central elements of the AI system we'll go through each element together explaining every single part of the code let's kick things off with the first crew AI agent for video content research in the agents.
pi file we create the content researcher agent within the class Video Creator agents the role of this agent is straightforward that's the video content researcher then we have the main goal which is to write a Content outline based on its research on a given topic we also need the backstory for this agent this is where we set up the agent as an expert in research for video content then give it a little bit more detail on collecting information that are valuable and interesting to create a YouTube video on the given topic ask the agent to put the collected information into key points for our content outline we also make it clear that its output will be passed on to another agent in our crew this helps the agent understand the sequential order of execution next specify the llm we're using and we'll give it to this agent class later in the main do P file we set weos true that will print out the execution process when we run it later on we set allow delegation to false since we don't need the agents to delegate tasks among themselves set max iteration to five so that the agent doesn't fall into a repeated Loop when generating output we'll explain more on this when analyzing the crew AI run later in this video okay let's move on to creating the task for our content researcher this is where we give further details on how the agent should do its work we provide a detailed description on the important things that should be included in its output and emphasize that other agents will be using the content it generated for their works we elaborate on the key areas the content researcher should prioritize thanks to consider when creating the content outline and important sections to include we also want the agent to incorporate SEO keywords and relevant sources for citation when it comes to expected output we wanted to produce a video content plan that is up to our standard ask it to Output in the specific format that we prefer explicitly state that the agent should strictly follow the template and no extra stuff should be generated after all llms can get quite chatty sometimes here we give a clear template that the agent should follow within the triple back takes when generating its response for the content outline give it some exact examples on how the output should look like for instance here you write section one followed by the section name key Point number one should be here followed by Point number two and point number three same goes for section two the section name first key point for the section then the second point third key point and so on you can stop the example of sections here but I usually give it another one more just to be sure the key points for this section and remaining sections we also want the SEO keywords to be included and the relevant source citation next we have the agent that is responsible for this task it'll be provided to the task later in the main. py file finally save the generated content out outline in an output file at the desired part we're done with the content researcher part now let's get to the second element which is script writing this agent is dedicated to writing scripts for our video we set the role as video script writer and the goal is to write a script for our YouTube video in the desired topic for the backstory we tell the agent that it's an expert in script writing and be explicit that we want a video script that is interesting enough to retain viewers attention we specify that it should perform tasks based on the content outline provided by the previous agent which is the content researcher the agent should also annotate clearly if it is providing its own opinion on the topic tell the script writing agent that its output will be fed to the next agent in our workflow put the llm argument here and the exact llm will be given to the agent later in the main. py file set verbosity to true for print outs allow delegation to false since we don't need to delegate tasks to other agents again set max iteration to five now let's create the task associated with this agent in the description we emphasize that other agents will be using the script that it generates for their work then we give a detailed explanation on how the agent should do script writing we should use the outline generated by the content researcher agent to write a script on the given topic the script should be written in a specific way and tone that aligns with our needs we also require the agent to include data sources for any factual statements made throughout the scripts to build up credibility and trust with our audience the script writer should also come up with good section titles to ensure the script flows well and is easy to follow additionally we specify the desired structure for the video script we also State the importance of producing a script that is free of Errors for the expected output we wanted to produce a video script that is up to our standard as usual the expected output argument will have a template for the agent to follow we ask it to Output in a specific format that we prefer tell the agent to strictly follow the template and no extra stuff should be generated we give a clear template that the agent should follow within the triple back takes when generating its response for the video script give it some examples on how the output should look here we write section one followed by the section name sentence number one of the video should be here followed by sentence two and sentence three same goes for section two we have the section name first sentence of this video section then the second sentence third sentence and so on again you can stop the example of sections here but I usually give it another one more just to be sure put the sentence for section three and the remaining sections we need an argument for the agent and we'll specify which agent is associated with this task later in the main.
py file we also need an argument for the context to provide a list of tasks in which their outputs will be fed as the context of this task the context will be specified later in the main. py file finally save the generated video script in an output file at the desired path all right let's move on to the next piece in the puzzle the third element in this AI system scene planning we set the role as video scene planner and the goal is to focus on designing the scenes for our video on the given topic for the backstory we set the llm to be an expert in scene planning and be explicit that we want a scene plan that is interesting enough to retain viewers attention just like before we specify to this agent that it should perform tasks based on the video script provided by the script writer agent the scene planning agent develops a detailed shooting plan for each scene in The Script this ensures we have clear guidelines for both shooting and post production place the llm argument here and the exact llm will be given to the agent later in the main. pi file set verbosity to true for print outs allow delegation to fall since we don't need to delegate tasks to other agents again set max iteration to five now let's create the TP pass for the scene planning agent in the description we ask the agent to develop a detailed plan for each sentence in the script so that we have clear guidelines for both shooting and post production create scenes in the desired style that can retain audience and make good use of various effects this plan must include Essential Elements like the type of Graphics sound and video effects to be used in each scene make sure that the flow between scenes are natural for the expected output we want the agent to produce a scene plan that is up to our production standard as usual the expected output argu will have a template for the agent to follow to keep everything structured the output from this task should be formatted as a CSV file with the following columns the scene number which helps us keep track of the video Parts the audio column that specifies the sentence of the scene that is from the video script generated by the script writer agent and the visual column that explains how the scene should look and sound providing clear instructions for the production team and editors we give a clear CSV template that the agent should follow within the triple back takes when generating its response for the scene plan tell the agent to strictly follow the template and no additional things should be included the desired CSV output columns are Cene number audio and visual give it some examples on the roles of the scene plan CSV file and the remaining rows for all the scenes of our video we need an argument for the agent associated with this task which will be specified later in the main.
py file we also need an argument for the context to provide a list of tasks in which their outputs will be fed as the context of this task again the context will be specified later in the main. py file let's save the generated video scene plan in an output CSV at the desired path next up we introduce our keyword research agent the role is of course video keyword researcher and the goal is to do a YouTube keyword search on the desired topic using a tool that we'll Define later it'll use the YouTube data API to gather details about the top 20 ranking videos in the YouTube search for the specified topic keyword this agent is important in optimizing our content for searchability on YouTube for backstory we Define the agent to be an expert in keyword research and instruct the agent to use the Custom Tool will provide later to identify the top 20 ranking YouTube videos on the desired keyword topic search we also specify that this extracted information will be used by another agent in the workflow put the llm argument here and we specify the llm to the agent later in the main. py file set verbosity to true for printouts allow delegation to false set max iteration to five and provide the Custom Tool over here to do keyword search on YouTube now we Define this Custom Tool called YouTube keyword Search tool in the tools.
piy file let's take a quick look to tools. piy and see how we should create this custom crew AI tool import all the necessary packages and Define the class YouTube keyword Search tool based on the crew AI documentation the format we need is pretty clear we need to Define our tool as a class with name description and then underscore run function name the tool give it a clear title that conveys its purpose the description of the tool is very important make sure it's written in a way that the agent can easily understand how and when to use this tool and we explain the arguments for the underscore run function for the tool query refers to the keyword will be searching for using the YouTube data API which is the topic we give to our agents Max results is the number of video results we like the API to return before we create the underscore run function let's go to the YouTube data API document to learn how to use this API since we're doing a keyword search go to search then list look at list by keyword open up the API Explorer this example is using Mex results 25 and query queue is surfing and take open authorization since we don't need it for keyword search execute go to the python Tab and look at the code to build the API connection create the API request and execute it now let's get back to our tools. P file and create the underscore run function create the connection to the API client by providing the YouTube API key then create the search request by following the example code in the API document execute the request and get the desired items from the search response we extract the details we need such as the rank and video title we also need the video ID to make another API call for statistics related to each video append the video search result into a list of lists before putting it into a pandas data frame let's make another API call to get information such as the number of comments likes and views for each video create the search request executed and get the desired items from the search response we extract the details on the number of comments likes and views for each video append the video search result into a list of lists and put it into a pandas data frame now we merge the two pandas data frames together and convert the merge data frame into a CSV format which makes it easy for the agent to read and process great we've done all the heavy lifting in creating our Custom Tool now let's get back to the tasks.
py file to create keyword search task here we write a description that clearly mention the arguments like 20 Max results on the topic keyword that the agent should use to run the tool with created as usual the expected output argument will have a template for the agent to follow the output from this task should be formatted as a CSV file with the following columns rank for the video ranking of the YouTube search result video ID the uniquely identified ID of each YouTube video video title which is the ti tile of each YouTube video commment count that shows the number of comments for each YouTube video like count showing the number of likes that each video obtained view count which is the number of views the video has acquired since published we give a clear CSV template that the agent should follow within the triple back takes when generating its response for the keyword research tell the agent to strictly follow the template and no additional things should be included the desired CSV output columns are rank video ID video title comment count like count and view count give us some examples on the roles of the top ranking video CSV file and the remaining rows for the rest of the ranking videos now you might be wondering why are we still explicitly showing how the CSV columns should look like in the expected output even though our tools already generating the desired format here's why if you don't articulate the CSV format explicitly in the expected output the agent may go into a lengthy Loop of repetitions in attempt to arrive at the expected output since it might be thinking that the output State isn't achieved yet when this happens it triggers repeated thoughts action and observations which quickly takes up your budget with unnecessary llm calls so it's better to be clear up front to avoid this we'll explain more on the thought action and observation process later when we analyze the crew AI run we need an argument for the agent associated with this task which will be specified later in the main. file we also need an argument for the context to provide a list of tasks in which their outputs will be fed as the context of this task again the context will be specified later in the main. py file we save the top ranking videos in an output CSV file at the desired path let's introduce element number five title and description generator the final piece of our puzzle this is where we create an agent to generate engaging titles and descriptions for our new video put video title and description writer as the role and the goal is to create titles and descriptions for new YouTube video on the desired topic for the backstory we Define the agent to be an expert in creating video titles and descript we let the agent know that it should generate titles and descriptions based on two important pieces of information the video script provided by the script writer agent and the high ranking video details gathered by the keyword research agent why is this important because we want our new video to rank high in YouTube searches we also want the title and description to be able to attract High clickthrough rate these are key factors in growing your audience and channel subscription we have the llm argument here and we'll specify the llm to the agent later in the main.
py file set verocity to true for print outs AOW delegation to false since we don't need to delegate tasks to other agents and set max iteration to five let's move to the tasks. py file for the title description writer task we provide a task flow that the agent should follow when generating video titles and descriptions first we emphasized on using the video script and keyword search result to generate five catchy titles and descriptions for our new video on the desired topic this variety gives us option to choose from and select the best feed for our content we specify the character limit of of 100 for the video title and ask the agent to generate titles with high clickthrough rate then for each video title generate a description that can make our video rank high in the relevant YouTube keyword search specify the character limit of 5,000 for the video description to keep our output concise and within the stand expected by the YouTube platform we ask the agent to generate titles and descriptions in a way that maximizes the potential for our video to rank high in keyword searches we emphasize on using the video script prided by the script writer agent to ensure that the generated titles and descriptions are well tailored for video for the expected output we give a clear template that the agent should follow within the triple back takes when generating its response for the titles and descriptions we ask it to Output in a specific format that we prefer tell the agent to strictly follow the template and no extra stuff should be generated give it some examples on how the output should look like here we write the first generated title followed by its corresponding description then the second generated title and the corresponding description the generated title with description and the remaining titles and descriptions we need an argument for the agent and we'll specify which agent is associated with this task later in the main. py file we also need an argument for the context to provide a Leist of tasks in which their outputs will be fed as the context of this task the context will be specified later in the main.
py file finally save the generated titles and descriptions in an output file at the desired path now it's time to put everything together in the main. py file We Begin by loading the dot and file to access our keys and credentials next we initialize agent Ops for monitoring this tool will help us analyze our agent's performance later then we create an output folder for the Run this is where all the results from our agents will be stored now let's initialize our llm in this project we're using GPT Forum mini to generate responses and we provide the open AI API key here next up Define all the agents that we previously established provide the agent class with the select the topic and the GPT foral mini llm then call the individual agents content researcher script writer scene planner keyword researcher and the title description writer Define all the tasks that we created provide the task class with the selected topic and set the output directory as the Run folder we created call the individual tasks for Content researcher script writer scene planner keyword researcher and title description writer notice how we specify the task outputs that should be used as the context for each task the context dependency is similar to our AI system workflow we feed the content research task output as the context of the script writing task the script writing task output as the context of the scene planning task the keyword research task is an exception it actually doesn't need any context but we feed something relevant to it anyway because if we leave the context empty cre AI will automatically assign the previous task output as its context and we don't really need the SE plans to do keyword research isn't it finally we feed the outputs from both script writing and keyword research tasks as the context of the title and description writing task now we Define the crew itself since our process is sequential we should feed the agent and task list in a similar sequential order to avoid confusion especially if you're not specifying the context set the process as quential ask the crew to save the Run slot file at the desired path and set verbosity to true and off you go the crew is ready to kick off but don't forget to end the agent op session to make sure everything concludes properly we demonstrate our cruel run on the topic artificial intelligence in marketing feel feel free to change it to any topic you like wow what a long journey if you've made it all the way here you should be incredibly proud of yourself let's run the code it'll take some time for the run to complete we'll get back once it's done okay we're back now let's take a look at the results from the code run at first glance it's a bit daunting with such a long print out but don't worry we'll look at it together let's head over to the agent Ops dashboard and analyze our crew AI run from there you can access the dashboard through the session link that was provided to you during the Run once you're in the dashboard you'll be able to see all the session data you'll find information such as the total cost of llm calls the tokens used and the overall run [Music] time you can also see the exact prompts that crew AI sent to the llms one of the coolest features is to view the session replay the session begins with a call to the content researcher agent followed by the script writer the scene planner the keyword researcher and then the title description generator let's dive a bit deeper into how crew AI prompts the LMS take the script writer for example it starts by clearly stating the role you specified for the agent then it gives the backstory and goal that you provided to the agent now what happens here is that crew AI has a thought action observation process this is telling the llm that when it declares I now can give a great answer then it has arrived at the best final answer and is ready to stop otherwise the thought action observation process will be repeated now when it comes to the format this is where your task specifics come in to play If you recall on the script writer task we created this is the task description we wrote this is the expected output with the template we provided in the script writer task we also specified in the main. py file that this script writing agent should use the output from the content researcher as its context then the corresponding llm returns a response remember that you can also view the final outputs in the Run folder based on the result our video automation goal looks pretty straightforward for the AI System since it got to The Final Answer without many repeated thoughts actions and observations it's all coming together nicely let's dive into the pros and cons of using crew AI in particular whether it's ready for Enterprise level production one of the major advantages of crew AI is that it provides a very good starting point for those looking to learn how to build their own AI agents the learning curve is not steep you don't need any extensive knowledge of llms just knowing a little bit of python will do this makes it an excellent choice for beginners on AI agents to learn prompting skills with crew Ai and understand how they structure and interact with their l LS within an AI system however there are some challenges to consider if you're looking to further customize the workflow of your crew like controlling the exact prompts sent to the underlying llms it may become difficult for those interested in customizing promps I recommend checking on their documentation at the link below I wonder why this important details are not included in the howto guide section on the site panel though currently crew AI supports crew setup in either sequential or hierarchical forms only Enterprise level Solutions often involve multi-level hierarchical setups which is significantly more complex if your crew AI agent setup starts getting too complicated well good luck with that even with a single hierarchical setup it tends to use more tokens than necessary compared to the sequence itial setup this inefficiency is due to the manager agent that uses additional llm calls to delegate tasks effectively what's even worse is when the manager llm struggles to assign tasks properly it could end up making repeated llm calls until it finally figures it out that's definitely not encouraged for Enterprise level production if you're thinking of deploying an AI agent in a business context you will need to conrete cost management plan in place plus a reliable system guaranteeing quality output with a low fail rate ideally within 1 to 5% for those willing to experiment you can try out the hierarchical setup in main.