desolo-2918's picture
Fix workflow and sync
7ffd176

A newer version of the Gradio SDK is available: 6.11.0

Upgrade
metadata
title: Competitive Analysis Single Agent
emoji: πŸ“Š
colorFrom: blue
colorTo: green
sdk: gradio
sdk_version: 4.19.2
python_version: 3.11
app_file: app.py
pinned: false

πŸ† Competitive Analysis Agent - MCP Implementation

A sophisticated single-agent system for comprehensive competitive analysis using the Model Context Protocol (MCP) with FastMCP. This implementation combines web research, intelligent reasoning, and structured analysis to provide actionable competitive insights.

🎯 Architecture Overview

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚     Single-File Application (app.py)                     β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚                                                          β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚
β”‚  β”‚  Gradio Web Interface (User UI)                    β”‚ β”‚
β”‚  β”‚            :7860                                   β”‚ β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”‚
β”‚                        β”‚                                β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚
β”‚  β”‚  Analysis Engine & Tools:                          β”‚ β”‚
β”‚  β”‚  β€’ validate_company()       - Verify company      β”‚ β”‚
β”‚  β”‚  β€’ identify_sector()        - Find industry       β”‚ β”‚
β”‚  β”‚  β€’ identify_competitors()   - Discover rivals     β”‚ β”‚
β”‚  β”‚  β€’ browse_page()            - Extract data        β”‚ β”‚
β”‚  β”‚  β€’ generate_report()        - Create analysis     β”‚ β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”‚
β”‚                        β”‚                                β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚
β”‚  β”‚  AI Agent (OpenAI GPT-4)                           β”‚ β”‚
β”‚  β”‚  Strategic reasoning & insights generation        β”‚ β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”‚
β”‚                                                          β”‚
β”‚              External APIs:                             β”‚
β”‚              β€’ DuckDuckGo (Web Search)                 β”‚
β”‚              β€’ OpenAI (LLM Analysis)                   β”‚
β”‚              β€’ External Web Pages (Scraping)           β”‚
β”‚                                                          β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Single-File Design: All functionality is consolidated in one app.py file for simplicity and ease of deployment. No separate MCP server needed.

✨ Features

πŸ” Company Analysis

  • Validation: Confirms company legitimacy using web search
  • Sector Identification: Determines industry using multi-stage analysis
  • Competitor Discovery: Identifies top 3 competitors with ranking

πŸ“Š Strategic Analysis

  • Web Research: Automatically gathers company information
  • Content Extraction: Extracts relevant strategic data
  • Structured Reports: Generates professional analysis with:
    • Executive summary
    • Competitor comparison table
    • Strategic recommendations
    • Actionable insights

πŸ› οΈ MCP Architecture

  • FastMCP Server: Lightweight, high-performance tool hosting
  • Tool Isolation: Each analysis function is a callable MCP tool
  • Scalable Design: Easy to add new tools or extend functionality
  • Robust Error Handling: Graceful fallbacks and error management

πŸ“‹ Prerequisites

βš™οΈ Installation

  1. Clone the repository:

    git clone <repository-url>
    cd single-agent-competitive-analysis-agent
    
  2. Install dependencies:

    pip install -r requirements.txt
    
  3. Verify installation:

    python -c "import gradio; import openai; import requests; import beautifulsoup4; print('βœ“ All dependencies installed')"
    

πŸš€ Running the Application

Quick Start (One Command!)

python app.py

That's it! The application will:

  1. Start the Gradio web interface at http://0.0.0.0:7860
  2. Initialize the analysis engine
  3. Open in your browser automatically (or visit http://localhost:7860)

Expected Output

Running on local URL:  http://0.0.0.0:7860
Opening in browser...

πŸ’‘ Usage Guide

Basic Workflow

  1. Enter Company Name: Type the name of the company you want to analyze

    • Example: "Tesla", "Spotify", "Microsoft", "Stripe"
  2. Provide OpenAI API Key: Paste your OpenAI API key

  3. Click "Analyze Competitors": The system will:

    • Validate the company exists
    • Identify its sector
    • Find top 3 competitors
    • Analyze competitor strategies
    • Generate comprehensive report
  4. Review Analysis Report: The report includes:

    • Company overview and sector
    • Top 3 competitors
    • Detailed competitor comparison
    • Strategic insights
    • Actionable recommendations

πŸ“ Project Structure

single-agent-competitive-analysis-agent/
β”œβ”€β”€ app.py                 # Complete application (Gradio UI + Analysis Engine)
β”œβ”€β”€ requirements.txt       # Python dependencies
β”œβ”€β”€ .env.example          # Environment variables template
β”œβ”€β”€ README.md             # This file
└── ARCHITECTURE.md       # Detailed architecture documentation

Application Components

The app.py file includes:

πŸ” Analysis Tools

  • validate_company: Company existence verification via web search
  • identify_sector: Industry classification with multi-strategy analysis
  • identify_competitors: Competitor discovery and ranking
  • browse_page: Web content extraction and parsing
  • generate_report: Structured competitive analysis report generation

πŸ€– AI Agent

  • OpenAI GPT-4 integration for strategic reasoning
  • Orchestrates analysis tools in logical sequence
  • Generates insights and actionable recommendations
  • Error handling with fallback modes

πŸ’» User Interface

  • Gradio-based web interface
  • Professional report formatting in Markdown
  • Real-time analysis execution
  • Input validation and error handling

πŸ”’ Security & Privacy

  • βœ… API Keys: Never stored, used only in current session
  • βœ… Web Data: Temporary, not cached
  • βœ… No Tracking: Local processing only

πŸš€ Quick Start

# 1. Install dependencies
pip install -r requirements.txt

# 2. Run the application
python app.py

# 3. Open browser to http://localhost:7860
# (usually opens automatically)

That's all! No need for multiple terminals or separate server startup.

4. Enter company name and OpenAI API key

5. Click "Analyze Competitors"


## πŸ› Troubleshooting

**OpenAI API Key invalid**: Check it starts with `sk-` and is active  
**MCP Server not running**: Run `python mcp_server.py` in separate terminal  
**Web search failing**: Check internet connection and try different company name  
**Rate limit errors**: Wait 5 minutes before next analysis

## πŸ“Š Performance

- Analysis Time: 30-60 seconds
- Report Generation: ~10 seconds
- API Calls: 5-8 requests per analysis
- Max Competitors: 3 (quality optimized)

---

**Version**: 1.0.0 (MCP Architecture)  
**Last Updated**: March 2026