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:
- Discovery: Finds competitors and industry information using web search
- Analysis: Scrapes websites and extracts detailed information
- Comparison: Analyzes features and competitive positioning
- Synthesis: Conducts SWOT analysis with reasoning tools
- Reporting: Compiles findings into actionable recommendations
Reasoning tools provide transparency into the agent's analytical thinking throughout the process.
Code
1from textwrap import dedent23from kern.agent import Agent4from kern.models.openai import OpenAIResponses5from kern.tools.firecrawl import FirecrawlTools6from kern.tools.reasoning import ReasoningTools78competitor_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}5960 ## Executive Summary61 {High-level overview of competitive landscape and key findings}6263 ## Research Methodology64 - Search queries used65 - Websites analyzed66 - Key information sources6768 ## Market Overview69 ### Industry Context70 - Market size and growth rate71 - Key trends and drivers72 - Regulatory environment7374 ### Competitive Landscape75 - Major players identified76 - Market segmentation77 - Competitive dynamics7879 ## Competitor Analysis8081 ### Competitor 1: {Name}82 #### Company Overview83 - Website: {URL}84 - Founded: {Year}85 - Headquarters: {Location}86 - Company size: {Employees/Revenue if available}8788 #### Products & Services89 - Core offerings90 - Key features and capabilities91 - Pricing model and tiers92 - Target market segments9394 #### Digital Presence Analysis95 - Website structure and user experience96 - Key messaging and value propositions97 - Content strategy and resources98 - Customer proof points99100 #### SWOT Analysis101 **Strengths:**102 - {Evidence-based strengths}103104 **Weaknesses:**105 - {Identified weaknesses}106107 **Opportunities:**108 - {Market opportunities}109110 **Threats:**111 - {Competitive threats}112113 ### Competitor 2: {Name}114 {Similar structure as above}115116 ### Competitor 3: {Name}117 {Similar structure as above}118119 ## Comparative Analysis120121 ### Feature Comparison Matrix122 | Feature | {Target} | Competitor 1 | Competitor 2 | Competitor 3 |123 |---------|----------|--------------|--------------|--------------|124 | {Feature 1} | ✓/✗ | ✓/✗ | ✓/✗ | ✓/✗ |125 | {Feature 2} | ✓/✗ | ✓/✗ | ✓/✗ | ✓/✗ |126127 ### Pricing Comparison128 | Company | Entry Level | Professional | Enterprise |129 |---------|-------------|--------------|------------|130 | {Pricing details extracted from websites} |131132 ### Market Positioning Analysis133 {Analysis of how each competitor positions themselves}134135 ## Strategic Insights136137 ### Key Findings138 1. {Major insight with evidence}139 2. {Competitive dynamics observed}140 3. {Market gaps identified}141142 ### Competitive Advantages143 - {Target company's advantages}144 - {Unique differentiators}145146 ### Competitive Risks147 - {Main threats from competitors}148 - {Market challenges}149150 ## Strategic Recommendations151152 ### Immediate Actions (0-3 months)153 1. {Quick competitive responses}154 2. {Low-hanging fruit opportunities}155156 ### Short-term Strategy (3-12 months)157 1. {Product/service enhancements}158 2. {Market positioning adjustments}159160 ### Long-term Strategy (12+ months)161 1. {Sustainable differentiation}162 2. {Market expansion opportunities}163164 ## Conclusion165 {Summary of competitive position and strategic imperatives}166 """),167 markdown=True,168 add_datetime_to_context=True,169 stream_events=True,170)171172competitor_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.122source .venv/bin/activate1uv venv --python 3.122.venv\Scripts\activateSet your API key
1export OPENAI_API_KEY=xxx2export FIRECRAWL_API_KEY=xxxInstall dependencies
1uv pip install -U kern-ai openai firecrawl-pyRun Agent
1python competitor_analysis_agent.py1python competitor_analysis_agent.pyNext Steps
- Modify the target company in the example query to analyze different markets
- Adjust
search_paramsandlimitin FirecrawlTools for deeper or broader research - Customize the
expected_outputtemplate to focus on specific competitive aspects - Explore Reasoning Tools for advanced analytical capabilities