CrewAI Multi-Agent System for Writing Article from YouTube Movies

Introduction

Within the period of an evolving digital world, automation redefines how people strategy on a regular basis duties, together with analysis, content material creation and rather more. A brand new and thrilling instrument rising on this subject is CrewAI, which permits a number of AI brokers to work collectively, fixing advanced issues with enhanced creativity and decision-making by prioritising collaborative intelligence.

On this article, we’ll dive deep into understanding the entire CrewAI multi-agent system and the way this method operates whereas creating a venture to put in writing articles from YouTube movies. This hands-on venture will provide help to acquire helpful insights and leverage AI to generate and streamline content material creation whereas sustaining a human contact. Let’s get began.

CrewAI Multi-Agent System for Writing Article from YouTube Movies

Desk of contents

  • Steadily Requested Questions
  • Mission Goal

    Image this: You’re a part of Analytics Vidhya, a platform identified for its in depth library of articles on Knowledge Science, Machine Studying, AI, and extra. When you’re seemingly aware of these sources, Analytics Vidhya additionally produces a spread of YouTube content material: informative movies, podcasts with AI leaders, information updates, and extra. Isn’t it an amazing concept to have articles summarising the content material from these movies as properly? Nonetheless, the method of manually writing such articles is resource-intensive and complicated. It requires a site knowledgeable first to observe and validate the movies, adopted by a content material author to construction and draft the articles. Think about scaling this course of for 1000’s of movies: communication breakdowns, delays, and potential errors develop into inevitable.

    Crew AI

    To beat this, AI brokers can streamline the complete workflow. These brokers can effectively analyze video content material, validate it, and generate articles—quick, dependable, and with minimal human intervention. Let’s discover how this may be completed utilizing AI!

    Additionally learn: Construct an AI Analysis Assistant Utilizing CrewAI and Composio

    What’s an AI Agent?

    An agent is a software program system that understands its atmosphere, processes knowledge and takes actions to attain its aims. It doesn’t at all times must be clever; for example, a movement sensor mild acts as an agent by robotically turning on when it detects motion.

    Then again, an AI Agent is a extra superior type of an agent that includes Synthetic intelligence particularly designed to automate duties, enabling it to function with out direct human intervention. The AI Agent additionally capabilities by observing its atmosphere, processing the acquired data, and executing actions or making choices based mostly on predefined aims. Nonetheless, it additionally learns from its atmosphere and improves its decision-making over time. AI Brokers are engineered to duplicate human-like decision-making and deal with extra advanced duties by studying from knowledge, figuring out patterns, and deriving insights or making predictions to perform assigned duties effectively.

    You possibly can understand it as an clever assistant on which you don’t have to have fixed supervision. For instance, an AI agent can course of massive quantities of knowledge, deal with buyer queries, do analysis duties, write blogs, and create content material. Essentially the most fascinating factor about these brokers is that they’ll work repeatedly with none breaks, analyze bigger quantities of knowledge than people, and simply adapt to altering environments and conditions based mostly on the outlined guidelines or ML algorithms they’re designed with. By combining a number of AI brokers, as we’ll do on this article, the system’s collective intelligence will increase considerably, permitting it to deal with much more advanced duties easily and successfully.

    If you wish to know concerning the Agentic AI design sample then discover this: 4 Agentic AI design sample

    What’s CrewAI?

    CrewAI is a brand new, rising, and modern platform designed to allow the collaboration of a number of AI brokers effectively and seamlessly (CrewAI Multi-Agent System). With its framework, it permits customers to make use of the facility of collective intelligence, permitting AI brokers to work collectively on advanced duties, which could possibly be difficult and costly for a single agent to deal with. With CrewAI you may create your system with specialised brokers, every with its personal experience, to carry out numerous duties. This collaborative strategy enhances decision-making and creativity and likewise streamlines workflows, making it simpler to attain desired outcomes.

    CrewAI

    Additionally learn: Constructing an Agentic Workflow with CrewAI and Groq

    How are we utilizing Agent for this Mission?

    The core idea of this venture includes choosing a YouTube video, extracting all related content material from it, processing that data, and writing a structured article based mostly on the perceived content material.

    To create a a number of AI-Agent system, we typically divide it into three parts: Brokers, Duties, and Instruments.

    • Brokers: Clever entities designed to carry out particular roles throughout the system. Every agent possesses distinctive capabilities, permitting for environment friendly dealing with of varied elements of the venture.
    • Duties: Clearly outlined aims assigned to brokers. These duties make sure that every agent understands its obligations, optimizing workflow and productiveness.
    • Instruments: Sources and applied sciences that help brokers in finishing their duties. These could embody software program purposes, knowledge sources, APIs, and custom-designed options geared toward enhancing the brokers’ effectivity, effectiveness, and workflow.

    On this system, we’ll implement two brokers: one will function a site knowledgeable agent, tasked with researching the YouTube video and amassing content material utilizing an assigned instrument, whereas the opposite agent will operate as an article content material author, liable for making a structured article based mostly on the data offered by the area knowledgeable agent. This knowledge move from one agent to a different is known as a sequential course of. Whereas we’ll deal with this strategy, different processes, resembling hierarchical processes, shall be mentioned in a later article.

    Circulate of the Mission

    Beneath is the entire move for the venture:

    Flow for the project

    Additionally learn: Learn how to Construct an AI Pair Programmer with CrewAI?

    Let’s Begin Writing Article from YouTube Movies

    To construct CrewAI Multi-Agent System, set up Python in your system. It’s beneficial that you simply use Anaconda or Miniconda to handle environments. 

    I’m creating this on a Linux system, utilizing Visible Studio Code (VS Code) as my IDE. VS Code is light-weight and versatile, helps a number of programming languages, and its built-in terminal simplifies growth. It’s additionally a most well-liked alternative for a lot of builders—and actually, I feel it simply seems to be fairly cool. 

    Now that you’ve all the required instruments let’s dive into the article and get began!

    Step 01: Setup the Atmosphere and Necessities

    On this step, we’ll begin by creating the necessities.txt file to specify all of the libraries essential for the venture. After that, we’ll arrange the .env file, which is able to maintain atmosphere variables resembling API keys and different confidential data. Lastly, we’ll create a digital atmosphere. It is a greatest apply in growth as a result of it locks the variations of the libraries and applied sciences used, stopping future errors because of model mismatches.

    1. Create a Folder
    Create a folder anyplace in your system, for instance, title it Multi_AI_Agent_Article_Project.

    2. Open in VS Code
    Open VS Code, then open the folder you simply created within the VS Code Explorer.

    3. Create necessities.txt
    Contained in the folder, create a file named necessities.txt and paste the next textual content inside it, then save the file:

    crewai
    crewai_tools
    load_dotenv
    langchain-huggingface

    4. Generate OpenAI API Key
    For this venture, we’ll use an LLM from OpenAI, so you must generate an OpenAI API Key. You possibly can comply with the hyperlink: Learn how to get your individual OpenAI API Key to get directions. The price of executing this venture is round $0.04, making it fairly cheap. If you have already got an API key, be happy to proceed to the subsequent step.

    5. Create .env File
    Create one other file named .env and save your OpenAI API key on this format, then save the file:

    OPENAI_API_KEY= paste_your_api_key_here

    6. Create Digital Atmosphere
    Open the terminal in VS Code, guaranteeing it’s opened contained in the Multi_AI_Agent_Article_Project folder. Then kind the next command to create a digital atmosphere:

    conda create -p venv python=3.10

    This command will create a Conda digital atmosphere within the venv listing throughout the venture folder as a substitute of the default Conda listing. The -p flag specifies the trail the place the atmosphere shall be created (on this case, the venv folder) and the Python model is ready to three.10.

    7. Activate Digital Atmosphere
    Use this command to activate the digital atmosphere:

    conda activate venv/

    8. Set up Required Libraries
    To put in all the required libraries from the necessities.txt file, run the next command:

    pip set up -r necessities.txt

    As soon as all of the steps above are full, you’re able to proceed with constructing the precise Multi AI Agent system!

    Step 02: Create Instruments

    Create a file named instruments.py and paste the code beneath, then save the file:

    from crewai_tools import YoutubeChannelSearchTool

    Code Clarification:

    Right here, we’re importing the YoutubeChannelSearchTool from CrewAI. This instrument permits an AI agent to look and collect video knowledge, titles, descriptions, and metadata from a specified YouTube channel, enabling environment friendly content material analysis and evaluation.

    #Initialize the instrument with a selected YouTube channel deal with to focus on your search
    yt_channel_tool = YoutubeChannelSearchTool(youtube_channel_handle="@SystemDesignSchool")

    Code Clarification:

    Subsequent, we initialize an object for the instrument and supply the YouTube deal with for the channel SystemDesignSchool. We’re utilizing this channel as a result of it has solely 6 movies, which helps save time and sources when the system processes the movies.

    You possibly can study extra about this instrument from the next hyperlink.

    Step 03: Create Brokers

    Now, create one other file named brokers.py and paste the next code into it, then save the file:

    from crewai import Agent, LLM
    from instruments import yt_channel_tool
    import os
    
    from dotenv import load_dotenv
    load_dotenv() # Load atmosphere variables from the .env file
    
    #Organising atmosphere variables for OpenAI API entry
    os.environ["OPENAI_API_KEY"] = os.getenv("OPENAI_API_KEY")
    os.environ["OPENAI_MODEL_NAME"] = "gpt-4-0125-preview"
    

    Code Clarification:

    Right here, we import the required modules to create AI brokers and configure atmosphere variables. We use dotenv to load the OPENAI_API_KEY from the .env file we created earlier. We additionally set the mannequin title to gpt-0125-preview.

    # Creating the Area Skilled Agent, specialised in extracting related content material from YouTube movies
    domain_expert = Agent(
    	position="Area Skilled content material researcher from Youtube Movies",
    	objective="To get all of the related Content material from the Youtube Video for the subject: {matter}",
    	verbose=True,
    	reminiscence=True,
    	backstory=(
        	'Area Skilled in understanding and greedy movies from Youtube that are about Synthetic Intelligence,'
        	'Knowledge Science, Machine Studying, Deep Studying, and Generative AI and offering content material.'
    	),
    	instrument = [yt_channel_tool],
    	allow_delegation=True
    )
    
    # Creating the Content material Author Agent, liable for writing a technical article based mostly on YouTube video content material
    content_writer = Agent(
    	position="Article Author",
    	objective="Write a structured and informative technical article concerning the Youtube Video matter: {matter}",
    	verbose=True,
    	reminiscence=True,
    	backstory=(
        	'Expert at breaking down advanced technical content material into clear, participating tales that educate readers, whereas presenting discoveries in an accessible and easy-to-understand format.'
    	),
    	instrument = [yt_channel_tool],
    	allow_delegation=False
    )

    Code Clarification:

    Right here, we create two brokers. The Area Skilled agent is designed to extract related content material from YouTube movies on subjects like AI and Machine Studying utilizing the yt_channel_tool. The Content material Author agent focuses on writing structured, technical articles based mostly on the offered content material.

    Each brokers have reminiscence=True, permitting them to retain data and recollect it when wanted. verbose=True permits detailed logging to assist perceive the agent’s actions. allow_delegation=True for the Area Skilled agent permits process delegation, whereas it’s set to False for the Content material Author agent, as the author doesn’t have to delegate duties. Defining their roles, targets, and backstory ensures that the brokers deal with their particular duties effectively.

    You possibly can study extra about brokers from the next hyperlink.

    Step 04: Create Duties

    Create one other file named duties.py and paste the next code into it, then save the file:

    from crewai import Process
    from instruments import yt_channel_tool
    from brokers import domain_expert, content_writer

    Code Clarification:

    This code imports the Process class from CrewAI for creating duties, the yt_channel_tool from the instruments.py file, and the domain_expert and content_writer brokers from the brokers.py file, which is able to carry out particular roles within the duties.

    # Area Skilled - ReseaAIrch Process
    research_task = Process(
    	description=(
        	"Get and establish the Youtube Video {matter}."
        	"Get a totally detailed, knowledgeable stage content material/details about the video from the channel."
    	),
    	expected_output="An in depth 6 paragraphs lengthy structured report based mostly on the {matter} of video content material.",
    	instruments = [yt_channel_tool],
    	agent=domain_expert
    )
    
    
    # Content material Author - Article Writing Process
    article_writing_task = Process(
    	description=(
        	"Get content material/data from the Youtube Channel's Video on the subject: {matter}."
    	),
    	expected_output="Summarize the content material type the Youtube Channel and write an in depth lengthy structured Article from the Youtube Chanel Video based mostly on the {matter}",
    	instruments = [yt_channel_tool],
    	agent=content_writer,
    	async_execution=False,
    	output_file="new-article.md"
    )
    

    Code Clarification:

    This part defines two duties: the area knowledgeable analysis process and the content material author’s article writing process. The analysis process focuses on figuring out a YouTube video on the required matter from the given channel and gathering detailed data to create a structured report. The article writing process summarizes the video’s content material and creates a structured article based mostly on that data. Each brokers are assigned the yt_channel_tool to entry YouTube knowledge. Within the article_writing_task, async_execution=False ensures that the duty is accomplished totally earlier than transferring to the subsequent step, stopping parallel execution of duties, and the output shall be saved within the “new-article.md” file.

    You possibly can study extra about duties from the next hyperlink.

    Step 05: Execution of the Code

    Now, as the ultimate step, create one other file named crew.py and paste the next code into it, then save the file:

    from crewai import Crew,Course of
    from brokers import domain_expert, content_writer
    from duties import research_task, article_writing_task
    

    Code Clarification:

    This code imports the Crew and Course of lessons from crewai to handle a number of brokers together with the outlined brokers and their duties created in earlier steps, enabling them to work collectively on the venture.

    # Making a Crew occasion with specified brokers, duties, and configuration
    crew = Crew(
    	brokers=[domain_expert, content_writer],
    	duties=[research_task, article_writing_task],
    	course of=Course of.sequential,
    	reminiscence=True,
    	cache=True,
    	max_rpm=100,
    	share_crew=True
    )
    
    # Kicking Off the Process
    end result = crew.kickoff(inputs={'matter': 'File Storage VS Object Storage'})
    print(end result)
    

    Code Clarification:

    This code creates a Crew occasion that mixes the 2 brokers, the Area Skilled and the Content material Author, with their particular duties. We’ve outlined the method as sequential, which means the duties will run one after the opposite. The reminiscence and cache settings are each set to True to recollect previous data and enhance effectivity. The max_rpm parameter units the utmost variety of requests the crew can deal with per minute, guaranteeing environment friendly processing with out overwhelming the system. The share_crew possibility permits the crew to be shared for collaboration or reuse, permitting different processes or customers to entry and make the most of the identical crew configuration for various duties.

    The crew is then initiated with the required matter, which the brokers will seek for on the YouTube channel, carry out their duties, and print the end result.

    You possibly can study extra from the next hyperlink.

    Ultimate Output

    Screenshot of the output file “new-article.md”:

    To study extra about What brokers are, go to the next Article: AI Agent.

    Conclusion

    Utilizing CrewAI Multi-Agent system considerably improves the effectivity and high quality of content material technology from YouTube movies. We optimize the workflow of the venture by breaking it into brokers, instruments and duties which considerably reduces the effort and time required to create high-quality articles. The Area Skilled agent gathers key data from the YouTube movies, whereas the Content material Author processes this data and writes well-organized articles.

    This collaborative strategy reduces the necessity for handbook effort whereas guaranteeing constant outcomes that keep the core message of the unique content material. As automation applied sciences progress, embracing these instruments permits content material creators to focus extra on strategic and artistic elements of their work.

    To remain forward on this evolving subject of Agentic AI, enroll in our Agentic AI Pioneer Program immediately!

    Key Takeaways

    • The Multi-Agent system divides duties amongst specialised brokers, streamlining content material technology and lowering the time required to supply articles.
    • The Area Skilled agent swiftly gathers helpful insights from YouTube movies, permitting for fast evaluation and understanding of content material.
    • The Content material Author agent transforms extracted data into well-structured articles, guaranteeing readability and coherence within the last output.
    • Leveraging automation applied sciences like CrewAI permits content material creators to focus extra on strategic and artistic elements of their work, lowering repetitive duties.

    Steadily Requested Questions

    Q1. What’s a Multi-Agent system?

    Ans. A Multi-Agent system makes use of specialised brokers to carry out completely different duties in a venture, bettering effectivity and output high quality.

    Q2. How does the Area Skilled agent work?

    Ans. The Area Skilled agent extracts helpful insights and data from YouTube movies, serving to to investigate and summarize content material successfully.

    Q3. What position does the Content material Author agent play?

    Ans. The Content material Author agent takes the insights gathered by the Area Skilled and crafts them into clear, structured articles.

    This fall. Why ought to I take advantage of automation utilizing brokers in content material creation?

    Ans. In content material creation, brokers can automate repetitive duties, dashing up the method and permitting you to deal with creativity and technique.

    I am an Synthetic Intelligence fanatic, at the moment employed as an Affiliate Knowledge Scientist. I am enthusiastic about sharing information with the neighborhood, specializing in project-based articles. #AI #DataScience #Initiatives #Group