Close Menu
    Trending
    • How to Access NASA’s Climate Data — And How It’s Powering the Fight Against Climate Change Pt. 1
    • From Training to Drift Monitoring: End-to-End Fraud Detection in Python | by Aakash Chavan Ravindranath, Ph.D | Jul, 2025
    • Using Graph Databases to Model Patient Journeys and Clinical Relationships
    • Cuba’s Energy Crisis: A Systemic Breakdown
    • AI Startup TML From Ex-OpenAI Exec Mira Murati Pays $500,000
    • STOP Building Useless ML Projects – What Actually Works
    • Credit Risk Scoring for BNPL Customers at Bati Bank | by Sumeya sirmula | Jul, 2025
    • The New Career Crisis: AI Is Breaking the Entry-Level Path for Gen Z
    AIBS News
    • Home
    • Artificial Intelligence
    • Machine Learning
    • AI Technology
    • Data Science
    • More
      • Technology
      • Business
    AIBS News
    Home»Artificial Intelligence»Creating an AI Agent to Write Blog Posts with CrewAI
    Artificial Intelligence

    Creating an AI Agent to Write Blog Posts with CrewAI

    Team_AIBS NewsBy Team_AIBS NewsApril 4, 2025No Comments13 Mins Read
    Share Facebook Twitter Pinterest LinkedIn Tumblr Reddit Telegram Email
    Share
    Facebook Twitter LinkedIn Pinterest Email


    I like writing. Chances are you’ll discover that in the event you observe me or my weblog. For that motive, I’m continually producing new content material and speaking about Knowledge Science and Synthetic Intelligence.

    I found this ardour a few years in the past after I was simply beginning my path in Knowledge Science, studying and evolving my abilities. At the moment, I heard some extra skilled professionals within the space saying {that a} good examine method was training new abilities and writing about it someplace, educating no matter you realized.

    As well as, I had simply moved to the US, and no one knew me right here. So I needed to begin someplace, creating my skilled picture on this aggressive market. I bear in mind I talked to my cousin, who’s additionally within the Tech trade, and he informed me: write weblog posts about your experiences. Inform folks what you might be doing. And so I did. 

    And I by no means stopped.

    Quick ahead to 2025, now I’ve nearly 200 printed articles, a lot of them with In the direction of Knowledge Science, a broadcast Ebook, and a great viewers. 

    Writing helped me a lot within the Knowledge Science space.

    Most not too long ago, certainly one of my pursuits has been the superb Pure Language Processing and Giant Language Fashions topics. Studying about how these fashionable fashions work is fascinating. 

    That curiosity led me to experiment with Agentic Ai as nicely. So, I realized about CrewAI, a simple and open-source bundle that helps us construct AI brokers in a enjoyable and straightforward approach, with little code. I made a decision to check it by making a crew of brokers to put in writing a weblog put up, after which see how that goes.

    On this put up, we’ll learn to create these brokers and make them work collectively to supply a easy weblog put up.

    Let’s try this.

    What’s a Crew?

    A crew of AI brokers is a mixture of two or extra brokers, every of them performing a process in the direction of a remaining objective.

    On this case examine, we’ll create a crew that may work collectively to supply a small weblog put up a couple of given subject that we are going to present.

    Crew of Brokers workflow. Picture by the creator

    The stream works like this:

    1. We select a given subject for the brokers to put in writing about.
    2. As soon as the crew is began, it can go to the information base, learn a few of my beforehand written articles, and attempt to mimic my writing fashion. Then, it generates a set of pointers and passes it to the following agent.
    3. Subsequent, the Planner agent takes over and searches the Web in search of good content material in regards to the subject. It creates a plan of content material and sends it to the following agent.
    4. The Author agent receives the writing plan and executes it in line with the context and knowledge obtained.
    5. Lastly, the content material is handed to the final agent, the Editor, who opinions the content material and returns the ultimate doc because the output.

    Within the following part, we’ll see how this may be created.

    Code

    CrewAI is a good Python bundle as a result of it simplifies the code for us. So, let’s start by putting in the 2 wanted packages.

    pip set up crewai crewai-tools

    Subsequent, if you need, you’ll be able to observe the directions on their Quickstart web page and have a full undertaking construction created for you with simply a few instructions on a terminal. Mainly, it can set up some dependencies, generate the folder construction prompt for CrewAI initiatives, in addition to generate some .yaml and .py information. 

    I personally choose to create these myself, however it’s as much as you. The web page is listed within the References part.

    Folder Construction

    So, right here we go.

    We are going to create these folders:

    And these information:

    • Within the config folder: create the information brokers.yaml and duties.yaml
    • Within the information folder, that’s the place I’ll add the information with my writing fashion.
    • Within the undertaking root: create crew.py and fundamental.py.
    Folders construction. Picture by the creator.

    Ensure that to create the folders with the names talked about, as CrewAI appears to be like for brokers and duties contained in the config folder and for the information base inside a information folder.

    Subsequent, allow us to set our brokers. 

    Brokers

    The brokers are composed of:

    • Identify of the agent: writer_style
    • Function: LLMs are good function gamers, so right here you’ll be able to inform them which function to play.
    • Objective: inform the mannequin what the objective of that agent is.
    • Backstory: Describe the story behind this agent, who it’s, what it does. 
    writer_style:
      function: >
        Writing Type Analyst
      objective: >
        Completely learn the information base and be taught the traits of the crew, 
        similar to tone, fashion, vocabulary, temper, and grammar.
      backstory: >
        You're an skilled ghost author who can mimic any writing fashion.
        You know the way to determine the tone and elegance of the unique author and mimic 
        their writing fashion.
        Your work is the premise for the Content material Author to put in writing an article on this subject.

    I gained’t bore you with all of the brokers created for this crew. I consider you bought the thought. It’s a set of prompts explaining to every agent what they’re going to do. All of the brokers directions are saved within the brokers.yaml file.

    Consider it as in the event you had been a supervisor hiring folks to create a group. Take into consideration what sorts of execs you would want, and what abilities are wanted.

    We’d like 4 professionals who will work in the direction of the ultimate objective of manufacturing written content material: (1) a Author Stylist, (2) a Planner, (3) a Author, and (4) an Editor. 

    If you wish to see the setup for them, simply verify the complete code within the GitHub repository.

    Duties

    Now, again to the analogy of the supervisor hiring folks, as soon as we “employed” our total crew, it’s time to separate the duties. We all know that we need to produce a weblog put up, now we have 4 brokers, however what every of them will do.

    Nicely, that can be configured within the file duties.yaml.

    For example, let me present you the code for the Author agent. As soon as once more, these are the elements wanted for the immediate:

    • Identify of the duty: write
    • Description: The outline is like telling the skilled the way you need that process to be carried out, similar to we might inform a brand new rent learn how to carry out their new job. Give exact directions to get one of the best end result doable.
    • Anticipated output: That is how we need to see the output. Discover that I give directions like the scale of the weblog put up, the amount of paragraphs, and different info that helps my agent to provide me the anticipated output. 
    • Agent to carry out it: Right here, we’re indicating the agent who will carry out this process, utilizing the identical identify set within the brokers.yaml file.
    • Output file: Now all the time relevant, but when so, that is the argument to make use of. We requested for a markdown file as output.
    write:
      description: >
        1. Use the content material plan to craft a compelling weblog put up on {subject}.
        2. Incorporate website positioning key phrases naturally.
        3. Sections/Subtitles are correctly named in an attractive method. Ensure that 
        so as to add Introduction, Downside Assertion, Code, Earlier than You Go, References.
        4. Add a summarizing conclusion - That is the "Earlier than You Go" part.
        5. Proofread for grammatical errors and alignment with the author's fashion.
        6. Use analogies to make the article extra participating and complicated ideas simpler
        to know.
      expected_output: >
        A well-written weblog put up in markdown format, prepared for publication.
        The article should be inside a 7 to 12 minutes learn.
        Every part will need to have at the least 3 paragraphs.
        When writing code, you'll write a snippet of code and clarify what it does. 
        Watch out to not add an enormous snippet at a time. Break it in cheap chunks.
        Within the examples, create a pattern dataset for the code.
        Within the Earlier than You Go part, you'll write a conclusion that's participating
        and factually correct.
      agent: content_writer
      output_file: blog_post.md

    After the brokers and duties are outlined, it’s time to create our crew stream.

    Coding the Crew

    Now we’ll create the file crew.py, the place we’ll translate the beforehand offered stream to Python code.

    We start by importing the wanted modules.

    #Imports
    import os
    from crewai import Agent, Job, Course of, Crew, LLM
    from crewai.undertaking import CrewBase, agent, crew, process
    from crewai.information.supply.pdf_knowledge_source import PDFKnowledgeSource
    from crewai_tools import SerperDevTool

    We are going to use the essential Agent, Job, Crew, Course of and LLM to create our stream. PDFKnowledgeSource will assist the primary agent studying my writing fashion, and SerperDevTool is the software to go looking the web. For that one, ensure that to get your API key at https://serper.dev/signup.

    A greatest apply in software program improvement is to maintain your API keys and configuration settings separate out of your code. We’ll use a .env file for this, offering a safe place to retailer these values. Right here’s the command to load them into the environment.

    from dotenv import load_dotenv
    load_dotenv()

    Then, we’ll use the PDFKnowledgeSource to indicate the Crew the place to seek for the author’s fashion. By default, that software appears to be like on the information folder of your undertaking, thus the significance of the identify being the identical.

    # Information sources
    
    pdfs = PDFKnowledgeSource(
        file_paths=['article1.pdf',
                    'article2.pdf',
                    'article3.pdf'
                    ]
    )

    Now we will arrange the LLM we need to use for the Crew. It may be any of them. I examined a bunch of them, and people I favored essentially the most had been qwen-qwq-32b and gpt-4o. In case you select OpenAI’s, you have to an API Key as nicely. For Qwen-QWQ, simply uncomment the code and remark out the OpenAI’s strains.. You want an API key from Groq. 

    # LLMs
    
    llm = LLM(
        # mannequin="groq/qwen-qwq-32b",
        # api_key= os.environ.get("GROQ_API_KEY"),
        mannequin= "gpt-4o",
        api_key= os.environ.get("OPENAI_API_KEY"),
        temperature=0.4
    )

    Now now we have to create a Crew Base, exhibiting the place CrewAI can discover the brokers and duties configuration information.

    # Creating the crew: base exhibits the place the brokers and duties are outlined
    
    @CrewBase
    class BlogWriter():
        """Crew to put in writing a weblog put up"""
        agents_config = "config/brokers.yaml"
        tasks_config = "config/duties.yaml"

    Brokers Capabilities

    And we’re able to create the code for every agent. They’re composed of a decorator @agent to indicate that the next operate is an agent. We then use the category Agent and point out the identify of the agent within the config file, the extent of verbosity, being 1 low, 2 excessive. You can even use a Boolean worth, similar to true or false.

    Lastly, we specify if the agent makes use of any software, and what mannequin it can use.

    # Configuring the brokers
        @agent
        def writer_style(self) -> Agent:
            return Agent(
                    config=self.agents_config['writer_style'],
                    verbose=1,
                    knowledge_sources=[pdfs]
                    )
    
        @agent
        def planner(self) -> Agent:
            return Agent(
            config=self.agents_config['planner'],
            verbose=True,
            instruments=[SerperDevTool()],
            llm=llm
            )
    
        @agent
        def content_writer(self) -> Agent:
            return Agent(
            config=self.agents_config['content_writer'],
            verbose=1
            )
    
        @agent
        def editor(self) -> Agent:
            return Agent(
            config=self.agents_config['editor'],
            verbose=1
            )

    Duties Capabilities

    The following step is creating the duties. Equally to the brokers, we’ll create a operate and enhance it with @process. We use the category Job to inherit CrewAI’s functionalities after which level to the duty for use from our duties.yaml file for use for every process created. If any output file is predicted, use the output_file argument.

    # Configuring the duties    
    
        @process
        def fashion(self) -> Job:
            return Job(
            config=self.tasks_config['mystyle'],
            )
    
        @process
        def plan(self) -> Job:
            return Job(
            config=self.tasks_config['plan'],
            )
    
        @process
        def write(self) -> Job:
            return Job(
            config=self.tasks_config['write'],
            output_file='output/blog_post.md' # That is the file that can be include the ultimate weblog put up.
            )
    
        @process
        def edit(self) -> Job:
            return Job(
            config=self.tasks_config['edit']
            )

    Crew

    To connect the whole lot collectively, we now create a operate and enhance it with the @crew decorator. That operate will line up the brokers and the duties within the order to be carried out, for the reason that course of chosen right here is the best: sequential. In different phrases, the whole lot runs in sequence, from begin to end.

    @crew
    
        def crew(self) -> Crew:
            """Creates the Weblog Publish crew"""
    
            return Crew(
                brokers= [self.writer_style(), self.planner(), self.content_writer(), self.editor(), self.illustrator()],
                duties= [self.style(), self.plan(), self.write(), self.edit(), self.illustrate()],
                course of=Course of.sequential,
                verbose=True
            )

    Operating the Crew

    Operating the crew could be very easy. We create the fundamental.py file and import the Crew Base BlogWriter created. Then we simply use the features crew().kickoff(inputs) to run it, passing a dictionary with the inputs for use to generate the weblog put up.

    # Script to run the weblog author undertaking
    
    # Warning management
    import warnings
    warnings.filterwarnings('ignore')
    from crew import BlogWriter
    
    
    def write_blog_post(subject: str):
        # Instantiate the crew
        my_writer = BlogWriter()
        # Run
        end result = (my_writer
                  .crew()
                  .kickoff(inputs = {
                      'subject': subject
                      })
        )
    
        return end result
    
    if __name__ == "__main__":
    
        write_blog_post("Value Optimization with Python")

    There it’s. The result’s a pleasant weblog put up created by the LLM. See under.

    Ensuing weblog put up. GIF by the creator.

    That’s so good!

    Earlier than You Go

    Earlier than you go, know that this weblog put up was 100% created by me. This crew I created was an experiment I needed to do to be taught extra about learn how to create AI brokers and make them work collectively. And, like I mentioned, I like writing, so that is one thing I’d have the ability to learn and assess the standard.

    My opinion is that this crew nonetheless didn’t do an excellent job. They had been in a position to full the duties efficiently, however they gave me a really shallow put up and code. I’d not publish this, however at the least it might be a begin, possibly. 

    From right here, I encourage you to be taught extra about CrewAI. I took their free course the place João de Moura, the creator of the bundle, exhibits us learn how to create completely different sorts of crews. It’s actually attention-grabbing.

    GitHub Repository

    https://github.com/gurezende/Crew_Writer

    About Me

    If you wish to be taught extra about my work, or observe my weblog (it’s actually me!), listed here are my contacts and portfolio.

    https://gustavorsantos.me

    References

    [Quickstart CrewAI](https://docs.crewai.com/quickstart)

    [CrewAI Documentation](https://docs.crewai.com/introduction)

    [GROQ](https://groq.com/)

    [OpenAI](https://openai.com)

    [CrewAI Free Course](https://learn.crewai.com/)



    Source link

    Share. Facebook Twitter Pinterest LinkedIn Tumblr Email
    Previous Articlemnbv
    Next Article Kevin O’Leary: Most Overlooked Startup Opportunity Right Now
    Team_AIBS News
    • Website

    Related Posts

    Artificial Intelligence

    How to Access NASA’s Climate Data — And How It’s Powering the Fight Against Climate Change Pt. 1

    July 1, 2025
    Artificial Intelligence

    STOP Building Useless ML Projects – What Actually Works

    July 1, 2025
    Artificial Intelligence

    Implementing IBCS rules in Power BI

    July 1, 2025
    Add A Comment
    Leave A Reply Cancel Reply

    Top Posts

    How to Access NASA’s Climate Data — And How It’s Powering the Fight Against Climate Change Pt. 1

    July 1, 2025

    I Tried Buying a Car Through Amazon: Here Are the Pros, Cons

    December 10, 2024

    Amazon and eBay to pay ‘fair share’ for e-waste recycling

    December 10, 2024

    Artificial Intelligence Concerns & Predictions For 2025

    December 10, 2024

    Barbara Corcoran: Entrepreneurs Must ‘Embrace Change’

    December 10, 2024
    Categories
    • AI Technology
    • Artificial Intelligence
    • Business
    • Data Science
    • Machine Learning
    • Technology
    Most Popular

    Why Your ML Model Might Be Lying to You | by Lalit Sharma | Apr, 2025

    April 21, 2025

    The Invisible Revolution: How Vectors Are (Re)defining Business Success

    April 10, 2025

    3 Unconventional Productivity Tips to Stimulate Creative Thinking

    December 16, 2024
    Our Picks

    How to Access NASA’s Climate Data — And How It’s Powering the Fight Against Climate Change Pt. 1

    July 1, 2025

    From Training to Drift Monitoring: End-to-End Fraud Detection in Python | by Aakash Chavan Ravindranath, Ph.D | Jul, 2025

    July 1, 2025

    Using Graph Databases to Model Patient Journeys and Clinical Relationships

    July 1, 2025
    Categories
    • AI Technology
    • Artificial Intelligence
    • Business
    • Data Science
    • Machine Learning
    • Technology
    • Privacy Policy
    • Disclaimer
    • Terms and Conditions
    • About us
    • Contact us
    Copyright © 2024 Aibsnews.comAll Rights Reserved.

    Type above and press Enter to search. Press Esc to cancel.