Build a Cybersecurity Content Agent
Use CrewAI to build two AI agents that research and write social media posts.
Introduction
30 Second Summary
Every cybersecurity company needs a constant stream of social media content, but researching trends and writing platform-specific posts eats up hours every week.
In this project, you will build a team of AI agents that collaborate to research cybersecurity trends and generate ready-to-post social media content for LinkedIn, Facebook, Instagram, and TikTok.
What You'll Build
A multi-agent content engine powered by CrewAI that takes a cybersecurity topic as input and produces a batch of platform-specific social media posts.
By the end of this project, you'll have:
- A working CrewAI project with two specialized agents: a Cybersecurity Trend Researcher and a Social Media Content Creator.
- A reusable project structure with YAML-based configuration for agents and tasks that you can adapt for other use cases like note-taking, calendar management, or budgeting.
- Hands-on experience defining agent roles, goals, and backstories and understanding how agents collaborate in a sequential workflow.
- A Secret Mission to add a third Content Reviewer agent that checks all posts for accuracy, tone, and platform best practices before finalizing the output.
Are there any prerequisites?
You need basic Python knowledge (variables, functions, editing files). No prior AI or agent experience is needed. You should have Python 3.10 or higher installed on your machine.
Set Up Your Tools and API Keys
Before you can build your AI agent crew, you need the right tools installed and API keys ready to go. CrewAI uses a package manager called uv and its own CLI to scaffold and run projects. Your agents also need access to OpenAI for their brains and Serper.dev for web search capabilities.
In This Step, Get Ready To:
- Install uv and the CrewAI CLI on your machine.
- Get an OpenAI API key and add prepaid credits for powering your agents.
- Get a free Serper.dev API key for web search.
Install uv and the CrewAI CLI
CrewAI requires Python >=3.10 and <3.14. It uses uv as its dependency manager instead of pip. You will install uv first, then use it to install the CrewAI CLI.
- Open PowerShell and run the uv installer.
powershell -ExecutionPolicy ByPass -c "irm https://astral.sh/uv/install.ps1 | iex"
- Close and reopen your terminal so the PATH updates take effect.
- Install the CrewAI CLI.
uv tool install crewai
What does this command do?
The uv tool install command installs the CrewAI command-line tool globally on your system. This gives you the crewai command, which you will use to create projects, install dependencies, and run your agent crews.
- If you see a PATH warning after installation, run the following command to update your shell.
uv tool update-shell
- Verify the installation by listing your installed tools.
uv tool list
I see crewai listed
You should see crewai listed with a version number (e.g., crewai v0.102.0). You are all set to move on.
I see an error
crewai not showing up?
Make sure you closed and reopened your terminal after installing uv. PATH changes only take effect in new terminal sessions. Try running uv tool update-shell again, then close and reopen your terminal one more time.
Also confirm that Python 3.10 or higher is installed and available in your PATH. You can check by running python --version. Still stuck? Ask for help here.
Get Your OpenAI API Key
Your AI agents need a large language model to think and write. OpenAI's gpt-4o-mini model is the best balance of quality and cost for this project. Each full crew run costs roughly $0.02 to $0.05, so the $5 minimum prepaid credit will last for over 100 runs.
- Go to platform.openai.com and create an account or sign in.
- Navigate to Settings, then Billing.
- Add a payment method.
- Click Add to credit balance and add $5 (the minimum).
- Navigate to Settings, then API Keys.
- Click Create new secret key.
- Give it a name like "crewai-project" and copy the key immediately.
Copy your key right now
OpenAI only shows your API key once. After you close the dialog, you will not be able to see it again. Copy it and store it somewhere safe, like a password manager or a private note.
Why platform.openai.com and not ChatGPT?
The OpenAI API platform is separate from ChatGPT. ChatGPT is the consumer chat product. The API platform is where developers get programmatic access to OpenAI's models. Your CrewAI agents will call the API directly, so you need an API key from the platform site.
Get Your Serper.dev API Key
Your researcher agent needs the ability to search the web for current cybersecurity news. Serper.dev provides a web search API that CrewAI integrates with natively through its built-in SerperDevTool. The free tier includes 2,500 searches with no credit card required. Each crew run uses approximately 3-5 searches, so the free tier covers hundreds of runs.
- Go to serper.dev and create a free account.
- After signing in, your API key is displayed on the dashboard.
- Copy and save this key alongside your OpenAI key.
Your tools are installed and your API keys are ready. Next up, you will scaffold your CrewAI project and explore the files where your agents will come to life.
Scaffold Your CrewAI Project
With your tools installed and API keys ready, it's time to create the actual project structure.
The CrewAI CLI can scaffold an entire project for you in one command. This generates all the configuration files, folder structure, and boilerplate code you need to start defining agents and tasks.
In This Step, Get Ready To:
- Create a new CrewAI crew project using the CLI.
- Explore the generated project structure and understand what each file does.
- Configure your environment variables so your agents can access OpenAI and Serper.dev.
Create the Crew Project
The crewai create crew command scaffolds a complete project with all the files you need. It also walks you through selecting your LLM provider and model.
- Open your terminal and navigate to the folder where you want to create the project:
cd C:\Users\[[YOURNAME="your Windows username"]]\Projects
- Run the CrewAI create command:
crewai create crew cyber-content-crew
What does this command do?
This command tells the CrewAI CLI to generate a new project called cyber-content-crew. It creates a folder with all the configuration files, Python modules, and directory structure you need to define agents and tasks.
The CLI will ask you a couple of questions during setup.
- When prompted to select an LLM provider, choose OpenAI.
- When prompted to select a model, choose gpt-4o-mini.
- When prompted for your OpenAI API key, paste the key you saved in Step 1.
Why gpt-4o-mini?
At $0.15 per million input tokens and $0.60 per million output tokens, gpt-4o-mini is the best balance of quality and cost for content generation tasks. A full crew run with two agents costs roughly $0.02 to $0.05. Your $5 in prepaid credits will last for over 100 runs.
- Once the CLI finishes, navigate into your new project:
cd cyber_content_crew
Command not found or creation failed?
If you see a "command not found" error for crewai, try closing and reopening your terminal so the PATH updates take effect. Also make sure you have Python 3.10 or higher installed and available in your PATH. Help me troubleshoot this.
Explore the Project Structure
The CLI generated a full project with several files and folders. Before making any changes, take a moment to understand what each piece does.
- Open the cyber_content_crew folder in your text editor or IDE.
Here are the key files you will be working with throughout this project:
cyber_content_crew/
├── .env # Your API keys go here
├── pyproject.toml # Project dependencies
├── src/
│ └── cyber_content_crew/
│ ├── main.py # Entry point - kicks off the crew
│ ├── crew.py # Wires agents, tasks, and tools together
│ ├── config/
│ │ ├── agents.yaml # Define your agents here
│ │ └── tasks.yaml # Define your tasks here
│ └── tools/
│ └── custom_tool.py # Custom tools (we will use a built-in one)
What are all these files for?
- agents.yaml is where you define each agent's role, goal, and backstory. Think of it as writing job descriptions for your AI team members.
- tasks.yaml is where you define the specific work each agent performs and what output they should produce.
- crew.py is the Python file that connects your YAML-defined agents and tasks together, assigns tools, and sets the execution order.
- main.py is the entry point that starts the crew with your chosen topic.
Pro tip: YAML keys matter
The keys you define in agents.yaml and tasks.yaml must exactly match the method names decorated with @agent and @task in crew.py. A mismatch causes a runtime error. You will see this in action when you edit these files in the next steps.
Configure Your Environment Variables
Your agents need access to OpenAI for language processing and Serper.dev for web search. The .env file stores these API keys so your code can use them without hardcoding secrets.
- Open the .env file in your text editor.
- Make sure it contains both of your API keys:
OPENAI_API_KEY=your-openai-api-key-here
SERPER_API_KEY=your-serper-api-key-here
What does this command do?
The .env file is a standard way to store environment variables. CrewAI automatically reads this file when your crew runs. Replace your-openai-api-key-here and your-serper-api-key-here with the actual keys you saved in Step 1.
- Save the file.
Never share your .env file
The .env file contains your secret API keys. Never commit it to a public Git repository or share it with others. The generated project already includes a .gitignore that excludes .env from version control.
Your project is scaffolded and configured. Next up, you will define the two AI agents that make up your cybersecurity content crew.
Define Your AI Agents
Your project structure is in place, and now it is time to design the team members who will do the actual work. In CrewAI, each agent is like an employee with a specific job title, a clear goal, and a backstory that shapes how they think and work. You will define two agents: a researcher who finds the latest cybersecurity trends, and a content creator who turns those findings into social media posts.
In This Step, Get Ready To:
- Configure a Cybersecurity Trend Researcher agent with a role, goal, and backstory.
- Configure a Social Media Content Creator agent tailored for platform-specific writing.
Configure the Cybersecurity Trend Researcher Agent
Every agent in CrewAI needs three things: a role (its job title), a goal (what it is trying to accomplish), and a backstory (its expertise and personality). The backstory is the most interesting part. It shapes how the LLM approaches its work, just like a detailed job description shapes how a new hire performs.
- Open src/cyber_content_crew/config/agents.yaml in your text editor.
- Delete all the existing placeholder content in the file.
- Replace it with the researcher agent definition:
cybersecurity_researcher:
role: >-
Senior Cybersecurity Trend Researcher
goal: >-
Research and identify the latest cybersecurity trends, threats, and news
related to {topic} that would be valuable for social media content
backstory: >-
You are a seasoned cybersecurity analyst with over 15 years of experience
tracking emerging threats, vulnerabilities, and industry developments.
You have a talent for identifying the stories and statistics that
resonate with business audiences. You always verify your sources and
prioritize recent, credible information. Your research forms the
foundation for compelling social media content that positions
cybersecurity companies as thought leaders.
What is a backstory?
The backstory is a prompt engineering technique. It gives the LLM a persona to adopt, which influences the quality and style of its output. A researcher with "15 years of experience tracking emerging threats" will produce more thorough, source-backed research than a generic assistant.
What is {topic}?
The {topic} placeholder is a variable that gets replaced at runtime. When you run the crew later, you will pass in a topic like "ransomware protection strategies for small businesses." CrewAI injects that value everywhere {topic} appears in your YAML files.
Pro tip: YAML keys matter
The YAML key cybersecurity_researcher must exactly match the method name you will use with the @agent decorator in crew.py later. A mismatch causes a runtime error.
Configure the Social Media Content Creator Agent
Your second agent takes the researcher's findings and transforms them into engaging, platform-specific social media posts. This agent needs a different kind of expertise. It understands how LinkedIn posts differ from TikTok captions, and it writes from the perspective of a cybersecurity company sharing expert insights.
- Add the following agent definition below the researcher in the same agents.yaml file:
social_media_creator:
role: >-
Senior Social Media Content Creator
goal: >-
Transform cybersecurity research findings into engaging,
platform-specific social media posts for LinkedIn, Facebook,
Instagram, and TikTok
backstory: >-
You are an expert social media strategist who specializes in
cybersecurity content marketing. You understand the nuances of each
platform: LinkedIn's professional tone and 1300-character post limit,
Facebook's conversational engagement style, Instagram's visual-first
captions with strategic hashtags, and TikTok's hook-first educational
format. You write content that positions cybersecurity companies as
trusted authorities while making complex security topics accessible
and engaging for business audiences. Every post you create drives
engagement and builds brand credibility.
Why does the backstory mention platform details?
Including specific platform knowledge in the backstory (like LinkedIn's 1300-character limit and Instagram's hashtag strategy) guides the LLM to produce content that actually fits each platform. Without these details, the agent would generate generic posts that look the same everywhere.
Your complete agents.yaml file should now contain both agent definitions, one after the other. Save the file.
What should I see?
Your agents.yaml file should have two top-level YAML keys: cybersecurity_researcher and social_media_creator. Each one has three fields: role, goal, and backstory.
Your two agents are defined and ready to go. Next up, you will create the tasks that tell each agent exactly what to do and what output to deliver.
Define Your Tasks
Your agents know who they are, but they don't know what to do yet. Tasks are the specific assignments you hand to each agent. They define the instructions, the expected output format, and how information flows from one agent to the next. In this step, you'll create two tasks: one for researching cybersecurity trends and one for generating social media content from that research.
In This Step, Get Ready To:
- Create a research task that tells the researcher agent what to search for and how to format its findings.
- Create a content creation task that chains off the research output to produce platform-specific social media posts.
Create the Research Task
Each task in CrewAI has three key fields. The description tells the agent exactly what to do. The expected_output defines the format and structure of the result. The agent field assigns the task to a specific agent. The expected_output field is especially important because it shapes how the agent structures its response.
- Open src/cyber_content_crew/config/tasks.yaml in your text editor.
- Replace the entire contents of the file with the following:
research_task:
description: >
Research the latest cybersecurity trends, threats, and news related to {topic}.
Search for at least 3-5 current and credible sources.
Summarize key findings with specific facts, statistics, and expert quotes.
Identify angles that would resonate with a business audience on social media.
Focus on actionable insights and emerging threats that businesses need to know about.
expected_output: >
A structured markdown report with the following sections:
- Executive Summary (2-3 sentences)
- Key Findings (3-5 bullet points with specific facts and statistics)
- Notable Statistics (any numbers, percentages, or data points found)
- Source URLs (list of sources used)
- Recommended Content Angles (3-4 angles suitable for social media posts)
agent: cybersecurity_researcher
What Is the {topic} Variable?
The {topic} placeholder gets replaced at runtime with whatever topic you pass in from main.py. You'll set this up in the next step. For now, just include it in your task description so the agent knows to focus its research on your chosen subject.
Why Does the Agent Field Matter?
The agent field value must exactly match the key name you used in agents.yaml. It must also match the method name you'll decorate with @agent in crew.py. A mismatch causes a runtime error because CrewAI can't find the agent to assign the task to.
Create the Content Creation Task
The content creation task is where the magic of multi-agent collaboration happens. You'll use a context field to tell this task to receive the output of the research task as its input. This is how one agent's work feeds into another's.
- Add the following task definition below the research task in tasks.yaml:
content_creation_task:
description: >
Using the research findings provided, create engaging social media posts
about {topic} for a cybersecurity company.
Generate posts for each of the following platforms: LinkedIn, Facebook, Instagram, and TikTok.
Adapt the tone, length, and format for each platform:
- LinkedIn: Professional thought leadership tone, under 1300 characters, 3-5 hashtags
- Facebook: Conversational and engaging, include a question to drive comments, 2-3 hashtags
- Instagram: Visual-first caption style, use emojis, 20-30 relevant hashtags
- TikTok: Hook-first opening (grab attention in the first line), casual and educational tone, trending hashtags
Write from the perspective of a cybersecurity company sharing expert insights.
Include specific facts and statistics from the research to build credibility.
expected_output: >
A markdown document organized by platform with the following structure:
## LinkedIn
### Post 1
[post content]
### Post 2
[post content]
## Facebook
### Post 1
[post content]
### Post 2
[post content]
## Instagram
### Post 1
[post content]
### Post 2
[post content]
## TikTok
### Post 1
[post content]
### Post 2
[post content]
Each platform section should have 2 post variations.
agent: content_creator
context:
- research_task
What Does the Context Field Do?
The context field creates a dependency between tasks. When you set context: [research_task], CrewAI automatically passes the research task's output into the content creation task as input. The content creator agent receives the full research report and uses it as the basis for writing posts.
Your final tasks.yaml file should now contain both tasks: research_task and content_creation_task.
Pro tip: tweak the platform guidelines
The platform-specific instructions in your task description directly shape the output quality. If you want different results, try adjusting the character limits, hashtag counts, or tone descriptions. The more specific your instructions, the better the agent performs.
Your tasks are locked in. Each agent now has a clear assignment and knows exactly what format to deliver. Next up, you'll wire everything together in Python and watch your agents collaborate in real time.
Wire Up the Crew and Run It
You have your agents defined and your tasks ready. Now it is time to connect everything in Python so your agents can actually collaborate.
The crew.py file is the control center of your project. It loads your YAML configurations, assigns tools to agents, and defines the order agents run in. The main.py file is the entry point that kicks everything off with your chosen topic.
In This Step, Get Ready To:
- Wire up agents, tasks, and tools in the crew file.
- Set the input topic and configure the main entry point.
- Install dependencies and run your crew to generate social media content.
Configure the Crew File
The crew.py file is where your YAML definitions come to life. Each agent and task you defined in YAML needs a matching Python method in this file. The YAML keys must exactly match the method names decorated with @agent and @task. A mismatch causes a runtime error.
- Open src/cyber_content_crew/crew.py in your text editor.
- Replace the entire contents of the file with the following code:
from crewai import Agent, Crew, Process, Task
from crewai.project import CrewBase, agent, crew, task
from crewai_tools import SerperDevTool
@CrewBase
class CyberContentCrew():
"""CyberContentCrew crew"""
# Path references to your YAML config files
agents_config = 'config/agents.yaml'
tasks_config = 'config/tasks.yaml'
# --- Agents ---
# Method names MUST match the keys in agents.yaml
@agent
def cybersecurity_researcher(self) -> Agent:
# Only the researcher needs web search capabilities
return Agent(
config=self.agents_config['cybersecurity_researcher'],
tools=[SerperDevTool()],
verbose=True
)
@agent
def content_creator(self) -> Agent:
# The content creator works with research output, no extra tools needed
return Agent(
config=self.agents_config['content_creator'],
verbose=True
)
# --- Tasks ---
# Method names MUST match the keys in tasks.yaml
@task
def research_task(self) -> Task:
return Task(
config=self.tasks_config['research_task']
)
@task
def content_creation_task(self) -> Task:
# context links this task to the research task's output
return Task(
config=self.tasks_config['content_creation_task'],
context=[self.research_task()],
output_file='output/social_media_posts.md'
)
# --- Crew Assembly ---
@crew
def crew(self) -> Crew:
"""Creates the CyberContentCrew crew"""
return Crew(
agents=self.agents,
tasks=self.tasks,
process=Process.sequential, # Researcher runs first, then content creator
verbose=True
)
What Does This Code Do?
This file does four things:
- It imports SerperDevTool and assigns it to the researcher agent, giving it the ability to search the web via Serper.dev.
- It defines agent methods that load their configuration from your agents.yaml file.
- It defines task methods and sets context on the content creation task so it receives the research output as input.
- It assembles everything into a Crew with Process.sequential, meaning the researcher runs first and the content creator runs second.
What Is Process.sequential?
CrewAI supports different process types that control how agents collaborate. Process.sequential runs agents in order, passing the output from one agent to the next. This is perfect for your use case because the content creator needs the researcher's findings before it can write posts.
Update the Main Entry Point
The main.py file is where you define the topic you want your crew to research and create content about. The {topic} variable gets injected into your agent goals and task descriptions wherever you used it in the YAML files.
- Open src/cyber_content_crew/main.py in your text editor.
- Replace the contents of the file with the following code:
#!/usr/bin/env python
import sys
import warnings
from cyber_content_crew.crew import CyberContentCrew
warnings.filterwarnings("ignore", category=SyntaxWarning, module="pysbd")
def run():
"""
Run the crew.
"""
inputs = {
# Change this topic to anything you want to research and post about
'topic': 'ransomware protection strategies for small businesses'
}
CyberContentCrew().crew().kickoff(inputs=inputs)
def train():
"""
Train the crew for a given number of iterations.
"""
inputs = {
'topic': 'ransomware protection strategies for small businesses'
}
try:
CyberContentCrew().crew().train(
n_iterations=int(sys.argv[1]),
filename=sys.argv[2],
inputs=inputs
)
except Exception as e:
raise Exception(f"An error occurred while training the crew: {e}")
def replay():
"""
Replay the crew execution from a specific task.
"""
try:
CyberContentCrew().crew().replay(
task_id=sys.argv[1]
)
except Exception as e:
raise Exception(f"An error occurred while replaying the crew: {e}")
def test():
"""
Test the crew execution and returns the results.
"""
inputs = {
'topic': 'ransomware protection strategies for small businesses'
}
try:
CyberContentCrew().crew().test(
n_iterations=int(sys.argv[1]),
openai_model_name=sys.argv[2],
inputs=inputs
)
except Exception as e:
raise Exception(f"An error occurred while testing the crew: {e}")
What Does This Code Do?
The run() function is the one that matters most. It creates an inputs dictionary with your chosen cybersecurity topic. Then it creates your crew and calls kickoff() to start the agents working. The other functions (train, replay, test) are scaffolded by CrewAI for advanced use cases. You can ignore them for now.
Pro tip: customize your topic
The topic value in the inputs dictionary is what drives your entire crew. Try changing it to something specific to your interests, like zero trust security for remote teams or AI-powered phishing attacks in 2025.
Install Dependencies and Run Your Crew
Everything is wired up. Time to install the project dependencies and launch your agents.
- Open your terminal and make sure you are in the cyber_content_crew project root directory.
- Install the project dependencies:
crewai install
- Run your crew:
crewai run
Watch the terminal output. You will see the researcher agent searching the web, gathering information, and reasoning about its findings. Then the content creator agent takes over and generates your social media posts.
What Should I See?
The terminal shows detailed logs from each agent as it works. You will see the researcher making web searches, analyzing results, and compiling its report. Then the content creator receives that report and starts drafting posts for each platform.
The final output is a markdown file saved to output/social_media_posts.md containing your platform-specific social media posts. The full output is also printed to the terminal. The entire run typically takes 1-2 minutes.
Seeing an Error About YAML Keys Not Matching?
The most common error is a mismatch between the keys in your YAML files and the method names in crew.py. For example, if your agents.yaml has a key called cybersecurity_researcher, the matching method in crew.py must also be named cybersecurity_researcher. Double-check that all names match exactly.
If you are hitting a different error, help me debug my CrewAI crew.
Build Error With chroma-hnswlib on Windows?
If you see a build error related to chroma-hnswlib during crewai install, you need to install Visual Studio Build Tools. Download them from the Visual Studio website and select Desktop development with C++ during installation. Then try crewai install again.
Your multi-agent crew is alive and producing content. Next up, take on the secret mission and add a third agent to review and polish your posts before they go live.
Secret mission
Add a Content Reviewer Agent
Your two-agent crew produces solid content, but what if a third agent could review every post for accuracy, tone, and platform best practices before it goes live? Add a Content Reviewer to your pipeline and see how quality control transforms your output.
Before you go
Clean Up Your Resources
Decide whether to keep your resources running, pause them to come back later, or delete them entirely. This project runs locally with pay-per-use API credits, so there are no ongoing costs unless you run the crew again.
Resources you used:
- OpenAI API key and prepaid credits ($5 minimum).
- Serper.dev API key (free tier with 2,500 searches).
- CrewAI CLI installed via uv.
- Local project folder cyber_content_crew with all source files.
- Environment variables in .env (OpenAI and Serper API keys).
Keep everything running
No action needed. Choose this if you are still actively building or plan to run the crew again soon.
- Your project files, API keys, and installed tools stay in place.
- Your OpenAI credits are only consumed when you run the crew. Each run costs roughly $0.02-$0.05 with gpt-4o-mini.
- Your Serper.dev free tier searches are only consumed when the researcher agent runs.
Pause - I'll come back to this later
Keep your files and API keys but clean up anything you do not need right now.
- No running processes to stop. The crew only runs when you execute crewai run.
- Keep your .env file and project folder intact so you can pick up where you left off.
- Optionally, revoke your OpenAI API key at platform.openai.com under Settings > API Keys if you are concerned about security. You can create a new one when you return.
Delete - I don't want to use this again
Remove all project resources and start fresh.
- Delete the cyber_content_crew project folder from your computer.
- Revoke your OpenAI API key at platform.openai.com under Settings > API Keys. Click the trash icon next to your key.
- Your remaining OpenAI prepaid credits stay in your account. They do not expire and can be used for future projects.
- Revoke your Serper.dev API key from your Serper.dev dashboard if you no longer need it.
- Optionally, uninstall the CrewAI CLI by running uv tool uninstall crewai in your terminal.
Mission accomplished
That's a Wrap!
Nice work! You just built a multi-agent AI system that researches cybersecurity trends and generates ready-to-post social media content, all from a single command.
Here's what you learned:
- Designed role-based AI agents with YAML configuration, defining roles, goals, and backstories that shape how each agent approaches its work.
- Built a sequential multi-agent pipeline where a researcher agent's output feeds directly into a content creator agent's input, automating real business work.
- Gave an agent real-time web search capabilities using the SerperDevTool, so your crew works with current information instead of stale training data.
- Added a Content Reviewer agent to introduce quality control into your pipeline, catching errors and polishing posts before they go live.
Ready to quiz yourself?