Competitor Analysis Agent

Build an AI agent that performs comprehensive competitive intelligence by combining web search, content scraping, and reasoning tools to analyze competitors and generate strategic reports with actionable insights.

What You'll Learn

By building this agent, you'll understand:

  • How to integrate multiple tools (Firecrawl and ReasoningTools) for complex workflows
  • How to structure multi-phase research processes with clear instructions
  • How reasoning tools make the agent's analytical thinking transparent
  • How to define structured output templates for consistent reports

Use Cases

Build market research tools, competitive intelligence systems, strategic planning assistants, or due diligence platforms for investment decisions.

How It Works

The agent follows a systematic five-phase research process:

  1. Discovery: Finds competitors and industry information using web search
  2. Analysis: Scrapes websites and extracts detailed information
  3. Comparison: Analyzes features and competitive positioning
  4. Synthesis: Conducts SWOT analysis with reasoning tools
  5. Reporting: Compiles findings into actionable recommendations

Reasoning tools provide transparency into the agent's analytical thinking throughout the process.

Code

1from textwrap import dedent
2
3from kern.agent import Agent
4from kern.models.openai import OpenAIResponses
5from kern.tools.firecrawl import FirecrawlTools
6from kern.tools.reasoning import ReasoningTools
7
8competitor_analysis_agent = Agent(
9 model=OpenAIResponses(id="gpt-5.2"),
10 tools=[
11 FirecrawlTools(
12 enable_search=True,
13 enable_crawl=True,
14 enable_mapping=True,
15 formats=["markdown", "links", "html"],
16 search_params={
17 "limit": 2,
18 },
19 limit=5,
20 ),
21 ReasoningTools(
22 add_instructions=True,
23 ),
24 ],
25 instructions=[
26 "1. Initial Research & Discovery:",
27 " - Use search tool to find information about the target company",
28 " - Search for '[company name] competitors', 'companies like [company name]'",
29 " - Search for industry reports and market analysis",
30 " - Use the think tool to plan your research approach",
31 "2. Competitor Identification:",
32 " - Search for each identified competitor using Firecrawl",
33 " - Find their official websites and key information sources",
34 " - Map out the competitive landscape",
35 "3. Website Analysis:",
36 " - Scrape competitor websites using Firecrawl",
37 " - Map their site structure to understand their offerings",
38 " - Extract product information, pricing, and value propositions",
39 " - Look for case studies and customer testimonials",
40 "4. Deep Competitive Analysis:",
41 " - Use the analyze tool after gathering information on each competitor",
42 " - Compare features, pricing, and market positioning",
43 " - Identify patterns and competitive dynamics",
44 " - Think through the implications of your findings",
45 "5. Strategic Synthesis:",
46 " - Conduct SWOT analysis for each major competitor",
47 " - Use reasoning to identify competitive advantages",
48 " - Analyze market trends and opportunities",
49 " - Develop strategic recommendations",
50 "- Always use the think tool before starting major research phases",
51 "- Use the analyze tool to process findings and draw insights",
52 "- Search for multiple perspectives on each competitor",
53 "- Verify information by checking multiple sources",
54 "- Be thorough but focused in your analysis",
55 "- Provide evidence-based recommendations",
56 ],
57 expected_output=dedent("""\
58 # Competitive Analysis Report: {Target Company}
59
60 ## Executive Summary
61 {High-level overview of competitive landscape and key findings}
62
63 ## Research Methodology
64 - Search queries used
65 - Websites analyzed
66 - Key information sources
67
68 ## Market Overview
69 ### Industry Context
70 - Market size and growth rate
71 - Key trends and drivers
72 - Regulatory environment
73
74 ### Competitive Landscape
75 - Major players identified
76 - Market segmentation
77 - Competitive dynamics
78
79 ## Competitor Analysis
80
81 ### Competitor 1: {Name}
82 #### Company Overview
83 - Website: {URL}
84 - Founded: {Year}
85 - Headquarters: {Location}
86 - Company size: {Employees/Revenue if available}
87
88 #### Products & Services
89 - Core offerings
90 - Key features and capabilities
91 - Pricing model and tiers
92 - Target market segments
93
94 #### Digital Presence Analysis
95 - Website structure and user experience
96 - Key messaging and value propositions
97 - Content strategy and resources
98 - Customer proof points
99
100 #### SWOT Analysis
101 **Strengths:**
102 - {Evidence-based strengths}
103
104 **Weaknesses:**
105 - {Identified weaknesses}
106
107 **Opportunities:**
108 - {Market opportunities}
109
110 **Threats:**
111 - {Competitive threats}
112
113 ### Competitor 2: {Name}
114 {Similar structure as above}
115
116 ### Competitor 3: {Name}
117 {Similar structure as above}
118
119 ## Comparative Analysis
120
121 ### Feature Comparison Matrix
122 | Feature | {Target} | Competitor 1 | Competitor 2 | Competitor 3 |
123 |---------|----------|--------------|--------------|--------------|
124 | {Feature 1} | / | / | / | / |
125 | {Feature 2} | / | / | / | / |
126
127 ### Pricing Comparison
128 | Company | Entry Level | Professional | Enterprise |
129 |---------|-------------|--------------|------------|
130 | {Pricing details extracted from websites} |
131
132 ### Market Positioning Analysis
133 {Analysis of how each competitor positions themselves}
134
135 ## Strategic Insights
136
137 ### Key Findings
138 1. {Major insight with evidence}
139 2. {Competitive dynamics observed}
140 3. {Market gaps identified}
141
142 ### Competitive Advantages
143 - {Target company's advantages}
144 - {Unique differentiators}
145
146 ### Competitive Risks
147 - {Main threats from competitors}
148 - {Market challenges}
149
150 ## Strategic Recommendations
151
152 ### Immediate Actions (0-3 months)
153 1. {Quick competitive responses}
154 2. {Low-hanging fruit opportunities}
155
156 ### Short-term Strategy (3-12 months)
157 1. {Product/service enhancements}
158 2. {Market positioning adjustments}
159
160 ### Long-term Strategy (12+ months)
161 1. {Sustainable differentiation}
162 2. {Market expansion opportunities}
163
164 ## Conclusion
165 {Summary of competitive position and strategic imperatives}
166 """),
167 markdown=True,
168 add_datetime_to_context=True,
169 stream_events=True,
170)
171
172competitor_analysis_agent.print_response(
173 """Analyze the competitive landscape for Stripe in the payments industry.
174 Focus on their products, pricing models, and market positioning.""",
175 stream=True,
176 show_full_reasoning=True,
177)

What to Expect

The agent will conduct a comprehensive competitive analysis in five phases. It uses Firecrawl to search for competitors and scrape their websites, then applies reasoning tools to analyze findings. The analysis streams in real-time so you can follow the agent's research and thinking process.

The final output is a detailed strategic report with competitor profiles, SWOT analyses, comparative tables, and actionable recommendations organized by timeline (immediate, short-term, long-term).

Usage

Set up your virtual environment

1uv venv --python 3.12
2source .venv/bin/activate
1uv venv --python 3.12
2.venv\Scripts\activate

Set your API key

1export OPENAI_API_KEY=xxx
2export FIRECRAWL_API_KEY=xxx

Install dependencies

1uv pip install -U kern-ai openai firecrawl-py

Run Agent

1python competitor_analysis_agent.py
1python competitor_analysis_agent.py

Next Steps

  • Modify the target company in the example query to analyze different markets
  • Adjust search_params and limit in FirecrawlTools for deeper or broader research
  • Customize the expected_output template to focus on specific competitive aspects
  • Explore Reasoning Tools for advanced analytical capabilities