Skip to content

Instantly share code, notes, and snippets.

@r0yfire
Created January 24, 2024 14:25
Show Gist options
  • Save r0yfire/65bc9a969cb75de04fe0fc8aedc17321 to your computer and use it in GitHub Desktop.
Save r0yfire/65bc9a969cb75de04fe0fc8aedc17321 to your computer and use it in GitHub Desktop.
Using `crewai` to build an automated marketing content team using LLM Agents

Marketing Content Team using crewai

An experiment using crewai.

Setup

  1. Setup a virtual environment using virtualenv
    virtualenv -p python3 venv
  2. Activate the virtual environment
    source venv/bin/activate
  3. Install the dependencies
    pip install -r requirements.txt
  4. Edit the OPENAI_API_KEY in the script to your own API key
  5. Run the script
    python content_team.py
import os
from crewai import Agent, Task, Crew, Process
from langchain.tools import DuckDuckGoSearchRun
from langchain_openai import ChatOpenAI
# Initialize the search tool
search_tool = DuckDuckGoSearchRun()
# Set the API key
os.environ["OPENAI_API_KEY"] = "YOUR API KEY"
#
# Create the agents
#
# Create a content researcher agent
researcher = Agent(
role="Researcher",
goal="Research for content about identity verification, fraud detection, and KYC in the hospitality industry",
backstory="""You are an ex-content writer turned researcher.
You have been hired by a Autohost, a company that provides identity verification services to the hospitality industry.
Your job is to research for content about identity verification, fraud detection, and KYC in the hospitality industry.
Your expertise lies in identifying emerging trends.
You have a knack for dissecting complex data and presenting actionable insights.""",
tools=[search_tool],
allow_delegation=False,
verbose=True,
llm=ChatOpenAI(model_name="gpt-4-1106-preview", temperature=0)
)
# Create a writer agent
writer = Agent(
role="Writer",
goal="Write a blog post about identity verification, fraud detection, and KYC in the hospitality industry",
backstory="""You are a senior content writer who loves to work with your research and SEO team.
You have been hired by a Autohost, a company that provides identity verification services to the hospitality industry.
Your job is to write a blog post about identity verification, fraud detection, and KYC in the hospitality industry.
The company Autohost provided the following Tone of Voice guidelines:
# Tone of Voice
We aim to stand out from our competition.
We are professional but not corporate.
Our content and visuals should be like our platform: powerful beyond human capabilities but friendly and easy to use!
Always keep in mind our customers are busy people without a lot of time.
Always cut to the chase--no fluff!
- Professional yet Relatable: Position ourselves as industry experts providing actionable advice, while maintaining a warm, human touch. Avoid corporate stiffness.
- Approachable: Make complex topics understandable, minimizing tech jargon but allowing specific industry terms. Cater to a diverse audience, including those without advanced education.
- Trustworthy: Highlight our commitment to cybersecurity through advanced technology, regular updates, and clear communication on risks and solutions. Emphasize our rigorous security validation and adaptive measures against new threats, reinforcing our reliability through proactive customer support.
- Conversational but Respectful: Maintain a friendly and engaging tone, even when discussing serious subjects. Achieve a balance between being informative and accessible, ensuring professionalism and respectfulness.
# Language usage
- Use the active voice over passive.
- Always use the Hemingway Editor to make sure our content is easy to read (should be grade 6 or under).
- Write in 2nd person, communicating to the audience.
- Some jargon is fine but the general tone needs to be smart, subject matter expert whilst still being accessible, concise, and pleasurable to read.
- When referring to the author/brand, use "we" not "I".
- The occasional emoji is also encouraged if used tastefully and in moderation.
- Always remember the customer persona. Readers are property management professionals. Don't talk down to the reader.
- No fluff and do not waste their time with generic content.""",
allow_delegation=True,
verbose=True,
llm=ChatOpenAI(model_name="gpt-4-1106-preview", temperature=0.7)
)
# Create a SEO expert agent
seo_expert = Agent(
role="SEO Expert",
goal="Optimize the blog post for search engines",
backstory="You are an SEO expert who loves to work with your content team. Your job is to optimize the blog post for search engines.",
allow_delegation=True,
verbose=True,
llm=ChatOpenAI(model_name="gpt-4-1106-preview", temperature=0)
)
# Create an editor agent
editor = Agent(
role="Editor",
goal="Edit the blog post for readability, grammar, and style",
backstory="""You are an editor who loves to work with your content team.
Your job is to edit the blog post.
Always use the Hemingway Editor to make sure our content is easy to read (should be grade 6 or under).
Some jargon is fine but the general tone needs to be smart, subject matter expert whilst still being accessible, concise, and pleasurable to read.
Always remember the customer persona. Readers are property management professionals. Don't talk down to the reader.
No fluff and do not waste their time with generic content.""",
allow_delegation=True,
verbose=True,
llm=ChatOpenAI(model_name="gpt-4-1106-preview", temperature=0)
)
#
# Create the tasks
#
# Create a research task
research_task = Task(
description="""Research for content about identity verification, fraud detection, and KYC in the hospitality industry.
Identify key trends, consequences of not using some form of screening and the benefits of using a service like Autohost.
Your final answer MUST be a full analysis report.""",
agent=researcher,
)
# Create a writing task
write_task = Task(
description="""Using the insights from the research, write an engaging blog post about identity verification, fraud detection, and KYC in the hospitality industry.
Your post should be informative yet accessible, concise, and pleasurable to read.
Focus on the hospitality industry and the rapid changes it is undergoing.
Do not make this a sales pitch about Autohost, keep it informative and educational.
Make it sound cool, avoid complex words so it doesn't sound like AI.
Your final answer MUST be the full blog post of at least 4 paragraphs.""",
agent=writer
)
# Create a SEO task
seo_task = Task(
description="Optimize the blog post for search engines",
agent=seo_expert
)
# Rewrite the blog post based on the SEO recommendations
rewrite_task = Task(
description="""Rewrite the blog post based on the SEO recommendations.
Your final answer MUST be the full blog post of at least 4 paragraphs.""",
agent=writer
)
# Create an editing task
edit_task = Task(
description="""Edit the blog post for readability, grammar, and style.
Your final answer MUST be the full blog post of at least 4 paragraphs.""",
agent=editor
)
#
# Create a crew
#
content_team = Crew(
agents=[researcher, writer, seo_expert, editor],
tasks=[research_task, write_task, seo_task, rewrite_task, edit_task],
process=Process.sequential
)
#
# Kick off the crew
#
result = content_team.kickoff()
# Print the result
print("\n\n##########################\n\n")
print(result)
crewai==0.1.32
langchain==0.1.3
langchain-openai==0.0.3
duckduckgo-search==4.2
openai==1.9.0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment