Supercharge Your Blog’s Readership with AI Agents: Exploring CrewAI



This content originally appeared on Level Up Coding – Medium and was authored by Ravi Kumar Verma

Content is King But Fresh Ideas are Key

Banner image taken from pexels

In today’s fast paced world keeping you blog fresh and exciting can sometimes feel like a hardway.You sit dwon to write, but the ideas just aren’t crossing your mind. Or worse, you think that your content isn’t as per current requirement.Sound familiar? Don’t worry, you are not alone.

But what if I told with advent of agentic work flow using the power of LLM make this struggle a thing of the past?

CrewAI- a game changing framework design to create a agentic workflow can help you to generate blog topics that resonate with your readers and keep them coming back for more.

Why Content is King?

We all know that user engaging content is king. More content can be created using LLM , but in today’s fast-paced digital world, it’s not enough to just create content — you need to create the right content. This means staying ahead of trends, understanding what your readers are searching for, and consistently offering value. That’s where agentic workflow using CrewAI comes in.

Imagine having a personal assistant who’s an expert at finding exactly what’s hot and trending in your niche. CrewAI does just that, scanning the internet to find the topics that your audience is interested in. It’s like having a crystal ball that reveals the content your readers are hungry for.

What is crew AI?

It is a Cutting-edge framework for orchestrating role-playing, autonomous AI agents. By fostering collaborative intelligence, CrewAI empowers agents to work together seamlessly, tackling complex tasks.

Image by Author

In this blog post, I’ll be discussing how to create a Crew AI agent that helps identify trending topics in a given subject to increase the readership of your published blog.

Identify the Goal of Your Crew

Before we dive into building applications using CrewAI, it’s essential to understand the goal we’re assigning to our AI agent. Think of it like briefing a new team member on their role. In this case, we’re creating a crew that will help identify trending topics in a specific subject area to boost your blog’s readership. This crew will be your digital assistant, tirelessly scouring the internet for what’s hot and what’s not.

User Input: Setting the Stage

Before our crew starts working its magic, we need to give it some direction. Imagine you’re the director, and your crew is waiting for your cue. Here’s what you’ll need to tell them:

  1. What’s the niche or topic you want to write about? Is it data science, AI, travel, or something else entirely?
  2. What specific area of this niche are you interested in? Narrow it down — are you focusing on deep learning in AI, or perhaps sustainable travel tips?
  3. What’s the main objective of your blog post? Do you want to attract more readers, improve your SEO ranking, or perhaps monetize your blog?

Expected Output: What You’ll Get

Once your crew has all the information it needs, it’s time to let them get to work. In return, you’ll receive:

  • A Content Calendar: A roadmap for what to write and when to post it.
  • SEO Strategy: Tailored to help your blog climb the search engine ranks.
  • Engagement Overview: Insights on how to capture and keep your audience’s attention.
  • Execution Plan: A step-by-step guide to bringing all this together.

Setting Up Your Crew: Agents, Tools, Tasks, and Processes

To bring this all to life, let’s break down the components of your CrewAI setup.

  • Tasks: These are the pieces of work that you’ll assign to your agents. In CrewAI, tasks can be collaborative, meaning multiple agents might work together to achieve the goal.
  • Agents: Think of agents as your team members, each with a specific skill set and role. An agent might be a ‘Researcher,’ a ‘Writer,’ or even ‘Customer Support.’ Each agent knows their job and works to accomplish their assigned tasks.
  • Tools: These are the instruments your agents will use to perform their tasks. It could be anything from a search engine to a summarizer or a translator.
  • Process: This dictates how your agents will work together. In this case, we’re using a sequential process, meaning each agent will complete their task before passing it on to the next.

Blueprint for Assembling Your Crew

Before you create your crew, it’s crucial to identify the list of tasks that your agents will perform. Think of this as jotting down your to-do list before starting your day. Here’s how it might look for our use case:

  • Trend Research Analysis Task: Scouring the web to find out what’s currently trending in your niche.
  • Trend Analyst: Analyzing the gathered data to identify patterns and hot topics.
  • Content Creating Task: Drafting engaging and informative content based on the trends.
  • Competitor Analysis Task: Checking out what your competitors are doing and figuring out how to do it better.
  • Summary & Planning Task: Putting it all together in a cohesive plan to maximize your blog’s impact.
Image by Author

Creating Tasks:

After setting up the blueprint for your crew, it’s time to define the tasks. Create a tasks.py which define all the task. Each task in CrewAI has the following properties:

  • Description: A detailed prompt that guides the agent on what to do.
  • Agent: The specific agent assigned to perform the task.
  • Expected Output: The desired outcome or result from the task.
from textwrap import dedent
from crewai import Task

class BlogContentTasks():

def research_task(self, agent, topic, target_audience):
return Task(
description=dedent(f"""\
Conduct thorough research on trending topics within the realm of data science, AI,
deep learning, and NLP. Focus on gathering insights from various sources including
blogs, social media, and news outlets. Pay attention to topics that resonate with
the target audience.

Topic Focus: {topic}
Target Audience: {target_audience}"""),
expected_output=dedent(f"""\
A detailed report summarizing the most trending and relevant topics within the
specified focus area, including the potential audience engagement."""),
agent=agent,

)

def trend_analysis_task(self, agent, collected_data):
return Task(
description=dedent(f"""\
Analyze the collected data to identify key trends, challenges, and opportunities
in the data science field. Consider search volume, social media engagement, and
the potential longevity of each trend to prioritize topics.

Collected Data: {collected_data}"""),
expected_output=dedent("""\
An insightful analysis that identifies which topics are currently most
promising, ranked by their potential to attract readers and generate
revenue."""),
agent=agent,

)

def content_ideation_task(self, agent, analyzed_trends, seo_keywords):
return Task(
description=dedent(f"""\
Generate content ideas, including blog titles, outlines, and key talking points,
based on the identified trends and SEO-optimized keywords. Ensure that each
idea aligns with the interests of the target audience.

Analyzed Trends: {analyzed_trends}
SEO Keywords: {seo_keywords}"""),
expected_output=dedent("""\
A comprehensive list of blog post ideas, complete with titles, outlines, and
recommended SEO keywords to enhance visibility and engagement."""),
agent=agent,

)

def competitor_analysis_task(self, agent, competitors, target_topics):
return Task(
description=dedent(f"""\
Perform a detailed analysis of competitors’ content strategies on the target topics.
Identify gaps, opportunities, and areas where you can offer unique insights or a
different angle. Review metrics such as social engagement, shares, and comments.

Competitors: {competitors}
Target Topics: {target_topics}"""),
expected_output=dedent("""\
A report outlining competitors' strengths and weaknesses, gaps in the content
landscape, and strategic recommendations for differentiating your blog content."""),
agent=agent,

)

def summary_and_planning_task(self, agent, research_results, content_ideas):
return Task(
description=dedent(f"""\
Compile all research findings, trend analysis, and content ideas into a cohesive
content strategy plan. The plan should include a schedule for blog posts, a strategy
for SEO optimization, and an overview of the expected engagement for each topic.

Research Results: {research_results}
Content Ideas: {content_ideas}"""),
expected_output=dedent("""\
A well-structured content strategy document that provides a roadmap for blog posts,
complete with a posting schedule, SEO strategy, and performance expectations."""),
agent=agent,

)

Agents:

Once tasks are defined, the next step is to assign them to agents. Create a agents.py which define all the agents. Agent in CrewAI has these properties:

  • Role: The specific role assigned to the agent.
  • Goal: A clear description of what the agent is aiming to achieve.
  • Tools: A list of tools the agent will use to complete the task.
  • Backstory: A brief description that adds context and clarity to the agent’s function.
from textwrap import dedent
from crewai import Agent

from tools import TrendSearchToolset, ContentAnalysisToolset, SEOOptimizationToolset

class BlogContentAgents():
def research_agent(self):
return Agent(
role="Trend Research Specialist",
goal="Conduct thorough research on trending topics in data science, AI, deep learning, NLP, and related fields.",
tools=TrendSearchToolset.tools(),
backstory=dedent("""\
As a Trend Research Specialist, your mission is to uncover the most trending
and relevant topics in the field of data science. Your insights will guide the
content creation process by identifying topics that will attract readers and
generate revenue."""),
verbose=True
)

def trend_analysis_agent(self):
return Agent(
role='Trend Analysis Expert',
goal='Analyze collected data to identify the most promising topics for blog content.',
tools=ContentAnalysisToolset.tools(),
backstory=dedent("""\
As a Trend Analysis Expert, your role is to analyze the collected data
from various sources, identify the most trending and engaging topics,
and predict which topics will perform well in terms of readership and revenue."""),
verbose=True
)

def content_ideation_agent(self):
return Agent(
role='Content Ideation Specialist',
goal='Generate blog post ideas, titles, and outlines based on identified trends.',
tools=SEOOptimizationToolset.tools(),
backstory=dedent("""\
As a Content Ideation Specialist, your expertise in content creation will guide
the development of blog post ideas, compelling titles, and detailed outlines.
You will ensure that each post is optimized for maximum visibility and engagement."""),
verbose=True
)

def competitor_analysis_agent(self):
return Agent(
role='Competitor Analysis Specialist',
goal='Analyze competitors’ content strategies and identify gaps and opportunities.',
tools=ContentAnalysisToolset.tools(),
backstory=dedent("""\
As a Competitor Analysis Specialist, your role is to examine competitors’ content,
assess their performance, and identify gaps or opportunities that can be
leveraged to create more compelling and unique content for the blog."""),
verbose=True
)

def summary_and_planning_agent(self):
return Agent(
role='Content Strategy Coordinator',
goal='Compile all research and analysis into a detailed content strategy plan.',
backstory=dedent("""\
As the Content Strategy Coordinator, your mission is to consolidate all the research,
analysis, and content ideas into a coherent and actionable content strategy
plan that will guide the blog’s content creation process."""),
verbose=True
)

Tools:

Tools are the resources agents use to complete their tasks. Create a tools.py which define all the tools.These can include search engines, summarizers, translators, etc. In our case, we’re using Exa as the search toolset. Exa is a robust search engine accessible via API. Here’s how a Tool object might be structured in CrewAI:

import os
from exa_py import Exa
from langchain.agents import tool

class TrendSearchToolset():

@tool
def search_trending_topics(query: str):
"""Search for trending topics in data science and related fields."""
return TrendSearchToolset._exa().search(f"{query} trending topics", use_autoprompt=True, num_results=3)

@tool
def search_social_media_trends(query: str):
"""Search for trending topics on social media related to data science."""
return TrendSearchToolset._exa().search(f"site:twitter.com {query} trends", use_autoprompt=True, num_results=3)

def tools():
return [
TrendSearchToolset.search_trending_topics,
TrendSearchToolset.search_social_media_trends
]

def _exa():
return Exa(api_key=os.environ.get('EXA_API_KEY'))

class ContentAnalysisToolset():

@tool
def find_similar_content(url: str):
"""Find content similar to a given URL."""
return ContentAnalysisToolset._exa().find_similar(url, num_results=3)

@tool
def get_webpage_contents(ids: str):
"""Retrieve and summarize the contents of a webpage."""
ids = eval(ids)
contents = str(ContentAnalysisToolset._exa().get_contents(ids))
contents = contents.split("URL:")
contents = [content[:1000] for content in contents]
return "\n\n".join(contents)

@tool
def competitor_content_analysis(query: str):
"""Analyze competitors' content strategies."""
return ContentAnalysisToolset._exa().search(f"{query} competitor content strategy", use_autoprompt=True, num_results=3)

def tools():
return [
ContentAnalysisToolset.find_similar_content,
ContentAnalysisToolset.get_webpage_contents,
ContentAnalysisToolset.competitor_content_analysis
]

def _exa():
return Exa(api_key=os.environ.get('EXA_API_KEY'))

class SEOOptimizationToolset():

@tool
def search_seo_keywords(query: str):
"""Search for SEO-optimized keywords related to a topic."""
return SEOOptimizationToolset._exa().search(f"{query} SEO keywords", use_autoprompt=True, num_results=3)

@tool
def analyze_seo_performance(url: str):
"""Analyze the SEO performance of a given URL."""
return SEOOptimizationToolset._exa().search(f"{url} SEO performance", use_autoprompt=True, num_results=3)

@tool
def get_competitor_seo_strategy(query: str):
"""Analyze competitors' SEO strategies."""
return SEOOptimizationToolset._exa().search(f"{query} competitor SEO strategy", use_autoprompt=True, num_results=3)

def tools():
return [
SEOOptimizationToolset.search_seo_keywords,
SEOOptimizationToolset.analyze_seo_performance,
SEOOptimizationToolset.get_competitor_seo_strategy
]

def _exa():
return Exa(api_key=os.environ.get('EXA_API_KEY'))

Create Crew and Kickoff:

The process determines how our agents work together. Here, we’re using a sequential process, meaning each agent completes their task one after the other. Create a main.py and run your crew with this code

from dotenv import load_dotenv
from crewai import Crew
from tasks import BlogContentTasks
from agents import BlogContentAgents
from datetime import datetime

def main():
load_dotenv()

print("## Welcome to the Data Science Blog Content Creation Crew")
print('-------------------------------------------------------')
niche = input("What is the niche or topic you want to write about?\n")
specific_focus = input("What specific area of this niche are you interested in?\n")
blog_goal = input("What is the main objective for your blog post (e.g., attract readers, SEO ranking, monetize)?\n")

tasks = BlogContentTasks()
agents = BlogContentAgents()

# Create agents
trend_research_agent = agents.research_agent()
trend_analysis_agent = agents.trend_analysis_agent()
content_ideation_agent = agents.content_ideation_agent()
competitor_analysis_agent = agents.competitor_analysis_agent()
summary_and_planning_agent = agents.summary_and_planning_agent()

# Create tasks
trend_research_task = tasks.research_task(trend_research_agent, niche, specific_focus)
trend_analysis_task = tasks.trend_analysis_task(trend_analysis_agent, trend_research_task)
content_ideation_task = tasks.content_ideation_task(content_ideation_agent, trend_analysis_task, blog_goal)
competitor_analysis_task = tasks.competitor_analysis_task(competitor_analysis_agent, niche, specific_focus)
summary_and_planning_task = tasks.summary_and_planning_task(summary_and_planning_agent, trend_research_task, content_ideation_task)

# Set context for tasks
trend_analysis_task.context = [trend_research_task]
content_ideation_task.context = [trend_analysis_task]
summary_and_planning_task.context = [trend_research_task, trend_analysis_task, content_ideation_task, competitor_analysis_task]

# Initialize Crew with agents and tasks
crew = Crew(
agents=[
trend_research_agent,
trend_analysis_agent,
content_ideation_agent,
competitor_analysis_agent,
summary_and_planning_agent
],
tasks=[
trend_research_task,
trend_analysis_task,
content_ideation_task,
competitor_analysis_task,
summary_and_planning_task
]
)

result = crew.kickoff()

if __name__ == "__main__":
main()

Final Thought:

CrewAI isn’t just for finding trending topics — by customizing tools, agents, and tasks, you can create unique workflows tailored to your needs, opening up possibilities for other use cases too. Dive in, experiment, and let AI streamline your content creation process.

Thank you for reading

You can find the code for this article in this Github.

LinkedIn, Twitter


Supercharge Your Blog’s Readership with AI Agents: Exploring CrewAI was originally published in Level Up Coding on Medium, where people are continuing the conversation by highlighting and responding to this story.


This content originally appeared on Level Up Coding – Medium and was authored by Ravi Kumar Verma