Real-World Project
Time to put everything together. In this lesson, you'll build a market research crew — a three-agent system that researches a market, analyzes the findings, and produces a professional report. This is a realistic workflow you can adapt for your own projects.
The Brief
You're building a crew that takes a company or market as input and produces a comprehensive market research report. The crew consists of three specialists:
- Market Researcher — gathers data on market size, trends, and key players
- Industry Analyst — analyzes the research and identifies opportunities and threats
- Report Writer — produces a polished, executive-ready report
Step 1: Set Up the Project
First, create a new project directory and install dependencies:
pip install crewai crewai-tools
Create a file called market_research_crew.py:
from crewai import Agent, Task, Crew, Process
from crewai_tools import SerperDevTool, ScrapeWebsiteTool
Step 2: Define the Agents
Each agent has a distinct role that maps to a real-world research team:
# Agent 1: The Researcher
# Gathers raw data and facts from the web
market_researcher = Agent(
role="Senior Market Researcher",
goal="Gather comprehensive, accurate market data and industry trends",
backstory="You are a senior market researcher with 15 years of experience "
"in technology markets. You are known for thorough data collection "
"and always citing your sources. You focus on quantitative data: "
"market size, growth rates, funding rounds, and user statistics.",
tools=[SerperDevTool(), ScrapeWebsiteTool()],
verbose=True
)
# Agent 2: The Analyst
# Makes sense of the data and draws conclusions
industry_analyst = Agent(
role="Industry Analyst",
goal="Identify actionable insights, opportunities, and threats from market data",
backstory="You are a strategic analyst at a top consulting firm. You excel "
"at finding patterns in data, identifying market gaps, and "
"assessing competitive dynamics. You always support your "
"conclusions with evidence from the research.",
verbose=True
)
# Agent 3: The Writer
# Turns analysis into a polished deliverable
report_writer = Agent(
role="Executive Report Writer",
goal="Produce clear, professional market research reports",
backstory="You are a business writer who specializes in executive-level "
"reports. You structure information for quick comprehension, "
"use clear headings and bullet points, and always include "
"an executive summary. You write for busy decision-makers.",
verbose=True
)
Notice how each agent's backstory encodes specific behaviors:
- The researcher focuses on quantitative data and citing sources
- The analyst focuses on patterns and evidence-based conclusions
- The writer focuses on structure and readability
Step 3: Define the Tasks
Each task maps to one phase of the research workflow:
# Task 1: Research
# The researcher gathers raw market data
research_task = Task(
description=(
"Conduct thorough market research on the {industry} industry. "
"Your research must cover:\n"
"1. Current market size (in USD) and projected growth rate\n"
"2. Top 5 companies by market share with brief descriptions\n"
"3. Recent trends shaping the industry (last 12 months)\n"
"4. Key technologies driving change\n"
"5. Recent notable funding rounds or acquisitions\n\n"
"Focus on data from 2024-2025. Cite sources where possible."
),
expected_output=(
"A detailed research document with sections for market size, "
"key players, trends, technologies, and recent deals. "
"Include specific numbers and data points."
),
agent=market_researcher
)
# Task 2: Analysis
# The analyst processes the research into insights
analysis_task = Task(
description=(
"Analyze the market research on the {industry} industry and provide "
"strategic insights. Your analysis must include:\n"
"1. SWOT analysis of the overall market\n"
"2. Identification of the top 3 market opportunities\n"
"3. Assessment of the top 3 market threats\n"
"4. Competitive landscape analysis — who is winning and why\n"
"5. Prediction for the next 2-3 years\n\n"
"Support every conclusion with data from the research."
),
expected_output=(
"A strategic analysis document with SWOT analysis, "
"ranked opportunities and threats, competitive assessment, "
"and market predictions, all supported by research data."
),
agent=industry_analyst,
context=[research_task]
)
# Task 3: Report
# The writer compiles everything into a polished report
report_task = Task(
description=(
"Write a professional market research report on the {industry} industry "
"based on the research and analysis provided. The report must include:\n"
"1. Executive Summary (150 words max)\n"
"2. Market Overview (size, growth, key statistics)\n"
"3. Competitive Landscape (top players, market share)\n"
"4. Trends and Opportunities\n"
"5. Risks and Challenges\n"
"6. Strategic Recommendations (3-5 actionable items)\n\n"
"Format: Use Markdown with clear headings. Keep the total length "
"between 1000-1500 words. Write for a C-level audience."
),
expected_output=(
"A polished market research report in Markdown format, "
"1000-1500 words, with executive summary, market overview, "
"competitive landscape, trends, risks, and recommendations."
),
agent=report_writer,
context=[research_task, analysis_task],
output_file="output/market_research_report.md"
)
Key design decisions:
- Task descriptions are highly specific — word counts, section requirements, formatting instructions
- Context chains — the analyst gets the researcher's output, the writer gets both
- Output file — the final report is saved to disk automatically
Step 4: Assemble and Run the Crew
# Create the crew
market_crew = Crew(
agents=[market_researcher, industry_analyst, report_writer],
tasks=[research_task, analysis_task, report_task],
process=Process.sequential,
verbose=True
)
# Run the crew with a specific industry
result = market_crew.kickoff(inputs={
"industry": "AI code assistants"
})
print("=" * 50)
print("FINAL REPORT")
print("=" * 50)
print(result.raw)
Step 5: The Complete Script
Here's the full market_research_crew.py file:
from crewai import Agent, Task, Crew, Process
from crewai_tools import SerperDevTool, ScrapeWebsiteTool
# --- Agents ---
market_researcher = Agent(
role="Senior Market Researcher",
goal="Gather comprehensive, accurate market data and industry trends",
backstory="You are a senior market researcher with 15 years of experience "
"in technology markets. You are known for thorough data collection "
"and always citing your sources. You focus on quantitative data: "
"market size, growth rates, funding rounds, and user statistics.",
tools=[SerperDevTool(), ScrapeWebsiteTool()],
verbose=True
)
industry_analyst = Agent(
role="Industry Analyst",
goal="Identify actionable insights, opportunities, and threats from market data",
backstory="You are a strategic analyst at a top consulting firm. You excel "
"at finding patterns in data, identifying market gaps, and "
"assessing competitive dynamics. You always support your "
"conclusions with evidence from the research.",
verbose=True
)
report_writer = Agent(
role="Executive Report Writer",
goal="Produce clear, professional market research reports",
backstory="You are a business writer who specializes in executive-level "
"reports. You structure information for quick comprehension, "
"use clear headings and bullet points, and always include "
"an executive summary. You write for busy decision-makers.",
verbose=True
)
# --- Tasks ---
research_task = Task(
description=(
"Conduct thorough market research on the {industry} industry. "
"Your research must cover:\n"
"1. Current market size (in USD) and projected growth rate\n"
"2. Top 5 companies by market share with brief descriptions\n"
"3. Recent trends shaping the industry (last 12 months)\n"
"4. Key technologies driving change\n"
"5. Recent notable funding rounds or acquisitions\n\n"
"Focus on data from 2024-2025. Cite sources where possible."
),
expected_output=(
"A detailed research document with sections for market size, "
"key players, trends, technologies, and recent deals. "
"Include specific numbers and data points."
),
agent=market_researcher
)
analysis_task = Task(
description=(
"Analyze the market research on the {industry} industry and provide "
"strategic insights. Your analysis must include:\n"
"1. SWOT analysis of the overall market\n"
"2. Identification of the top 3 market opportunities\n"
"3. Assessment of the top 3 market threats\n"
"4. Competitive landscape analysis — who is winning and why\n"
"5. Prediction for the next 2-3 years\n\n"
"Support every conclusion with data from the research."
),
expected_output=(
"A strategic analysis document with SWOT analysis, "
"ranked opportunities and threats, competitive assessment, "
"and market predictions, all supported by research data."
),
agent=industry_analyst,
context=[research_task]
)
report_task = Task(
description=(
"Write a professional market research report on the {industry} industry "
"based on the research and analysis provided. The report must include:\n"
"1. Executive Summary (150 words max)\n"
"2. Market Overview (size, growth, key statistics)\n"
"3. Competitive Landscape (top players, market share)\n"
"4. Trends and Opportunities\n"
"5. Risks and Challenges\n"
"6. Strategic Recommendations (3-5 actionable items)\n\n"
"Format: Use Markdown with clear headings. Keep the total length "
"between 1000-1500 words. Write for a C-level audience."
),
expected_output=(
"A polished market research report in Markdown format, "
"1000-1500 words, with executive summary, market overview, "
"competitive landscape, trends, risks, and recommendations."
),
agent=report_writer,
context=[research_task, analysis_task],
output_file="output/market_research_report.md"
)
# --- Crew ---
market_crew = Crew(
agents=[market_researcher, industry_analyst, report_writer],
tasks=[research_task, analysis_task, report_task],
process=Process.sequential,
verbose=True
)
# --- Run ---
if __name__ == "__main__":
result = market_crew.kickoff(inputs={
"industry": "AI code assistants"
})
print("=" * 50)
print("FINAL REPORT")
print("=" * 50)
print(result.raw)
Running the Crew
To run the crew, you'll need API keys for the LLM and search tool:
export OPENAI_API_KEY="your-openai-key"
export SERPER_API_KEY="your-serper-key"
python market_research_crew.py
The crew will take a few minutes to run. You'll see each agent's reasoning in the console (thanks to verbose=True), and the final report will be saved to output/market_research_report.md.
Adapting the Crew
This pattern is highly reusable. Here are some ways to adapt it:
Change the industry: Just change the inputs parameter:
result = market_crew.kickoff(inputs={"industry": "electric vehicles"})
Add more agents: Need a fact-checker? Add one:
fact_checker = Agent(
role="Fact Checker",
goal="Verify all claims and statistics in the report",
backstory="You are a rigorous fact-checker who verifies every number and claim."
)
Change the output format: Want a slide deck outline instead of a report? Change the writer's task description.
Add tools: Need financial data? Create a custom tool that queries a financial API.
Key Takeaways
- A real-world crew mirrors a real-world team: researcher → analyst → writer
- Specific agent backstories produce specific behaviors — encode your requirements there
- Task descriptions should be detailed enough that a human freelancer could follow them
- Use context chains to pass information between tasks automatically
- Use inputs to make crews reusable across different topics
- The sequential process is the right choice for linear research workflows
- Save outputs to files with
output_filefor easy access to results

