Automationscribe.com
  • Home
  • AI Scribe
  • AI Tools
  • Artificial Intelligence
  • Contact Us
No Result
View All Result
Automation Scribe
  • Home
  • AI Scribe
  • AI Tools
  • Artificial Intelligence
  • Contact Us
No Result
View All Result
Automationscribe.com
No Result
View All Result

Creating an AI Agent to Write Weblog Posts with CrewAI

admin by admin
April 5, 2025
in Artificial Intelligence
0
Creating an AI Agent to Write Weblog Posts with CrewAI
399
SHARES
2.3k
VIEWS
Share on FacebookShare on Twitter


I like writing. You could discover that for those who comply with me or my weblog. For that purpose, I’m continually producing new content material and speaking about Information Science and Synthetic Intelligence.

I found this ardour a few years in the past after I was simply beginning my path in Information 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 practising new abilities and writing about it someplace, educating no matter you discovered.

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 keep in mind I talked to my cousin, who’s additionally within the Tech business, and he instructed me: write weblog posts about your experiences. Inform individuals what you might be doing. And so I did. 

And I by no means stopped.

Quick ahead to 2025, now I’ve virtually 2 hundred printed articles, lots of them with In direction of Information Science, a printed Ebook, and a great viewers. 

Writing helped me a lot within the Information Science space.

Most just lately, one in every of my pursuits has been the superb Pure Language Processing and Massive Language Fashions topics. Studying about how these trendy fashions work is fascinating. 

That curiosity led me to experiment with Agentic Ai as effectively. So, I discovered about CrewAI, a simple and open-source package deal 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 jot down a weblog submit, after which see how that goes.

On this submit, we are going to discover ways to create these brokers and make them work collectively to supply a easy weblog submit.

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 job in the direction of a remaining aim.

On this case examine, we are going to create a crew that may work collectively to supply a small weblog submit a few given subject that we are going to present.

Crew of Brokers workflow. Picture by the writer

The circulation works like this:

  1. We select a given subject for the brokers to jot down about.
  2. As soon as the crew is began, it is going to 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 tips and passes it to the subsequent agent.
  3. Subsequent, the Planner agent takes over and searches the Web on the lookout for good content material in regards to the subject. It creates a plan of content material and sends it to the subsequent agent.
  4. The Author agent receives the writing plan and executes it in keeping with the context and data acquired.
  5. Lastly, the content material is handed to the final agent, the Editor, who evaluations the content material and returns the ultimate doc because the output.

Within the following part, we are going to see how this may be created.

Code

CrewAI is a superb Python package deal 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 would like, you’ll be able to comply with the directions on their Quickstart web page and have a full mission construction created for you with simply a few instructions on a terminal. Mainly, it is going to set up some dependencies, generate the folder construction recommended for CrewAI initiatives, in addition to generate some .yaml and .py information. 

I personally desire 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’ll 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 mission root: create crew.py and important.py.
Folders construction. Picture by the writer.

Be certain 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
  • Position: LLMs are good position gamers, so right here you’ll be able to inform them which position to play.
  • Objective: inform the mannequin what the aim of that agent is.
  • Backstory: Describe the story behind this agent, who it’s, what it does. 
writer_style:
  position: >
    Writing Model Analyst
  aim: >
    Totally learn the information base and study the traits of the crew, 
    similar to tone, fashion, vocabulary, temper, and grammar.
  backstory: >
    You might be 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 jot down an article on this subject.

I gained’t bore you with all of the brokers created for this crew. I imagine you bought the concept. 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 for those who have been a supervisor hiring individuals to create a workforce. Take into consideration what varieties of pros you would want, and what abilities are wanted.

We want 4 professionals who will work in the direction of the ultimate aim 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 test the total code within the GitHub repository.

Duties

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

Effectively, that might be configured within the file duties.yaml.

As an instance, 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 job to be carried out, identical to we might inform a brand new rent find out how to carry out their new job. Give exact directions to get the most effective consequence attainable.
  • Anticipated output: That is how we wish to see the output. Discover that I give directions like the scale of the weblog submit, the amount of paragraphs, and different info that helps my agent to offer me the anticipated output. 
  • Agent to carry out it: Right here, we’re indicating the agent who will carry out this job, utilizing the identical title 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 submit on {subject}.
    2. Incorporate website positioning key phrases naturally.
    3. Sections/Subtitles are correctly named in an attractive method. Be certain 
    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 partaking and sophisticated ideas simpler
    to grasp.
  expected_output: >
    A well-written weblog submit in markdown format, prepared for publication.
    The article have to be inside a 7 to 12 minutes learn.
    Every part should have no less than 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 partaking
    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 circulation.

Coding the Crew

Now we are going to create the file crew.py, the place we are going to translate the beforehand offered circulation to Python code.

We start by importing the wanted modules.

#Imports
import os
from crewai import Agent, Activity, Course of, Crew, LLM
from crewai.mission import CrewBase, agent, crew, job
from crewai.information.supply.pdf_knowledge_source import PDFKnowledgeSource
from crewai_tools import SerperDevTool

We’ll use the fundamental Agent, Activity, Crew, Course of and LLM to create our circulation. PDFKnowledgeSource will assist the primary agent studying my writing fashion, and SerperDevTool is the device to look the web. For that one, ensure to get your API key at https://serper.dev/signup.

A finest 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 are going to use the PDFKnowledgeSource to indicate the Crew the place to seek for the author’s fashion. By default, that device appears to be like on the information folder of your mission, thus the significance of the title being the identical.

# Data sources

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

Now we will arrange the LLM we wish to use for the Crew. It may be any of them. I examined a bunch of them, and people I preferred probably the most have been qwen-qwq-32b and gpt-4o. When you select OpenAI’s, you will have an API Key as effectively. 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 we have now to create a Crew Base, exhibiting the place CrewAI can discover the brokers and duties configuration information.

# Creating the crew: base reveals the place the brokers and duties are outlined

@CrewBase
class BlogWriter():
    """Crew to jot down a weblog submit"""
    agents_config = "config/brokers.yaml"
    tasks_config = "config/duties.yaml"

Brokers Features

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 title of the agent within the config file, the extent of verbosity, being 1 low, 2 excessive. It’s also possible to use a Boolean worth, similar to true or false.

Lastly, we specify if the agent makes use of any device, and what mannequin it is going to 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 Features

The subsequent step is creating the duties. Equally to the brokers, we are going to create a operate and adorn it with @job. We use the category Activity to inherit CrewAI’s functionalities after which level to the duty for use from our duties.yaml file for use for every job created. If any output file is anticipated, use the output_file argument.

# Configuring the duties    

    @job
    def fashion(self) -> Activity:
        return Activity(
        config=self.tasks_config['mystyle'],
        )

    @job
    def plan(self) -> Activity:
        return Activity(
        config=self.tasks_config['plan'],
        )

    @job
    def write(self) -> Activity:
        return Activity(
        config=self.tasks_config['write'],
        output_file='output/blog_post.md' # That is the file that might be comprise the ultimate weblog submit.
        )

    @job
    def edit(self) -> Activity:
        return Activity(
        config=self.tasks_config['edit']
        )

Crew

To attach all the things collectively, we now create a operate and adorn 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 only: sequential. In different phrases, all the things runs in sequence, from begin to end.

@crew

    def crew(self) -> Crew:
        """Creates the Weblog Submit 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
        )

Working the Crew

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

# Script to run the weblog author mission

# Warning management
import warnings
warnings.filterwarnings('ignore')
from crew import BlogWriter


def write_blog_post(subject: str):
    # Instantiate the crew
    my_writer = BlogWriter()
    # Run
    consequence = (my_writer
              .crew()
              .kickoff(inputs = {
                  'subject': subject
                  })
    )

    return consequence

if __name__ == "__main__":

    write_blog_post("Value Optimization with Python")

There it’s. The result’s a pleasant weblog submit created by the LLM. See beneath.

Ensuing weblog submit. GIF by the writer.

That’s so good!

Earlier than You Go

Earlier than you go, know that this weblog submit was 100% created by me. This crew I created was an experiment I wished to do to study extra about find out how to create AI brokers and make them work collectively. And, like I stated, 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 have been in a position to full the duties efficiently, however they gave me a really shallow submit and code. I’d not publish this, however no less than it could possibly be a begin, possibly. 

From right here, I encourage you to study extra about CrewAI. I took their free course the place João de Moura, the creator of the package deal, reveals us find out how to create totally different sorts of crews. It’s actually attention-grabbing.

GitHub Repository

https://github.com/gurezende/Crew_Writer

About Me

If you wish to study extra about my work, or comply with 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://study.crewai.com/)

Tags: AgentBlogcreatingCrewAIPostswrite
Previous Post

Prompting for the perfect price-performance

Next Post

High quality-tune giant language fashions with reinforcement studying from human or AI suggestions

Next Post
High quality-tune giant language fashions with reinforcement studying from human or AI suggestions

High quality-tune giant language fashions with reinforcement studying from human or AI suggestions

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Popular News

  • How Aviva constructed a scalable, safe, and dependable MLOps platform utilizing Amazon SageMaker

    How Aviva constructed a scalable, safe, and dependable MLOps platform utilizing Amazon SageMaker

    401 shares
    Share 160 Tweet 100
  • Diffusion Mannequin from Scratch in Pytorch | by Nicholas DiSalvo | Jul, 2024

    401 shares
    Share 160 Tweet 100
  • Unlocking Japanese LLMs with AWS Trainium: Innovators Showcase from the AWS LLM Growth Assist Program

    401 shares
    Share 160 Tweet 100
  • Proton launches ‘Privacy-First’ AI Email Assistant to Compete with Google and Microsoft

    401 shares
    Share 160 Tweet 100
  • Streamlit fairly styled dataframes half 1: utilizing the pandas Styler

    400 shares
    Share 160 Tweet 100

About Us

Automation Scribe is your go-to site for easy-to-understand Artificial Intelligence (AI) articles. Discover insights on AI tools, AI Scribe, and more. Stay updated with the latest advancements in AI technology. Dive into the world of automation with simplified explanations and informative content. Visit us today!

Category

  • AI Scribe
  • AI Tools
  • Artificial Intelligence

Recent Posts

  • Speed up edge AI improvement with SiMa.ai Edgematic with a seamless AWS integration
  • The Automation Entice: Why Low-Code AI Fashions Fail When You Scale
  • AWS machine studying helps Scuderia Ferrari HP pit cease evaluation
  • Home
  • Contact Us
  • Disclaimer
  • Privacy Policy
  • Terms & Conditions

© 2024 automationscribe.com. All rights reserved.

No Result
View All Result
  • Home
  • AI Scribe
  • AI Tools
  • Artificial Intelligence
  • Contact Us

© 2024 automationscribe.com. All rights reserved.