Transform market research from weeks to minutes with AI-powered competitor analysis
Traditional competitor analysis is time-consuming, expensive, and often incomplete. Business analysts spend weeks:
Result: Outdated insights by the time reports are ready, with high costs and inconsistent quality.
The Competitor Analysis Multi-Agent System automates this entire process using AI agents that work together intelligently. What used to take weeks now takes minutes, with:

Scenario: Launching a new product in a competitive market
How it helps:
Example Query:
python -m src.main "Analyze competitors in the project management SaaS market and recommend entry strategy"
Scenario: Regular monitoring of competitor landscape
How it helps:
Example Query:
python -m src.main "Compare top 5 competitors in the CRM space, focusing on pricing and feature differentiation"
Scenario: Understanding where your product fits in the market
How it helps:
Example Query:
python -m src.main "Analyze competitor positioning in the AI chatbot market and identify differentiation opportunities"
Scenario: Evaluating market opportunities for investment
How it helps:
Scenario: Equipping sales teams with competitive intelligence
How it helps:

python -m src.main "Analyze competitors in the SaaS project management market"
Output:
================================================================================
COMPETITOR ANALYSIS REPORT
================================================================================
# Competitor Analysis Report
## Executive Summary
[Generated summary...]
## SWOT Analysis
### Strengths
- [Strength 1]
- [Strength 2]
...
Export Files Generated:
- pdf: data/exports/report_20240101_120000.pdf
- swot_diagram: data/exports/swot_diagram_20240101_120000.png

Query: "Analyze the top 5 competitors in the AI code assistant market. Focus on pricing, features, and market positioning. Provide recommendations for market entry."
Use Case: Startup planning to launch an AI coding assistant
Output Includes: List of top 5 competitors, pricing comparison, feature matrix, market positioning analysis, entry strategy recommendations, SWOT diagram

Query: "Compare pricing strategies of CRM competitors: Salesforce, HubSpot, and Pipedrive. Analyze their target markets and feature sets."
Use Case: Sales team preparing competitive battle cards
Output Includes: Detailed pricing comparison, target market analysis, feature differentiation, competitive advantages/disadvantages

Query: "Provide comprehensive analysis of the fintech payment processing market. Include market size, key players, trends, and opportunities."
Use Case: Investment firm evaluating market opportunity
Output Includes: Market overview, key players analysis, industry trends, growth opportunities, risk assessment
The system generates multiple output formats:

Enable detailed logging for debugging:
python -m src.main --verbose "Your query"
Or set in .env:
LOG_LEVEL=DEBUG
The system uses a multi-agent architecture built on LangGraph, where specialized AI agents collaborate through a stateful workflow.

| Framework | Purpose | Version |
|---|---|---|
| LangGraph | Workflow orchestration | ≥0.2.0 |
| LangChain | LLM integration & tools | ≥0.3.0 |
| Groq | Fast LLM inference | ≥0.2.0 |
| Pydantic | Data validation | ≥2.5.0 |
| Tavily | Web search API | ≥0.5.0 |
Each agent is a specialized AI component with a specific role:

Groq API Key (Required)
Tavily API Key
The system uses LangGraph's StateGraph to orchestrate agent interactions:

The complete execution flow from user query to final report:

The codebase follows SOLID principles with clear separation of concerns:
src/
├── main.py # Entry point
├── config.py # Configuration management
│
├── agents/ # AI Agent implementations
│ ├── base_agent.py # Abstract base class
│ ├── planner_agent.py
│ ├── supervisor_agent.py
│ ├── data_collector.py
│ ├── insight_agent.py
│ ├── report_agent.py
│ └── export_agent.py
│
├── graph/ # Workflow orchestration
│ ├── workflow.py # LangGraph builder
│ ├── state.py # State management
│ ├── nodes/ # Pure function nodes
│ └── validators/ # Quality gates
│
├── tools/ # Stateless tools
│ ├── web_search.py
│ ├── scraper.py
│ ├── query_generator.py
│ └── text_utils.py
│
├── models/ # Pydantic data models
│ ├── plan_model.py
│ ├── competitor_profile.py
│ ├── insight_model.py
│ └── report_model.py
│
└── exceptions/ # Custom exceptions
All agents follow a consistent pattern with dependency injection, abstract base classes, and type-safe interfaces. Each agent implements an execute() method that takes a WorkflowState and returns an updated state.
Benefits: Consistent interface, easy testing, dependency injection, type safety
Nodes are pure functions that wrap agents. They follow a factory pattern where each node is created with dependencies (LLM, config) and returns a pure function State -> State.
Benefits: No side effects, easy to test, composable, thread-safe
Validators return structured ValidationResult objects instead of raising exceptions. This allows for composable validations and structured error reporting without interrupting workflow execution.
Benefits: Non-throwing, structured error reporting, composable validations, easy to test
The Supervisor Agent acts as the quality control and workflow coordinator, checking the work of other agents:

Supervisor Responsibilities:
The workflow uses a TypedDict (WorkflowState) for type-safe state management. The state contains: messages, plan, collected_data, insights, report, export_paths, retry_count, current_task, and validation_errors. This ensures type safety throughout the workflow execution.
State Evolution:

The system implements defense in depth with multiple error handling layers:

The system implements intelligent retry logic with query improvement:

Default configuration: MAX_RETRIES = 3 (configurable via .env). Retry behavior: increments retry_count, modifies search queries to be more specific, clears validation errors, and returns to supervisor for re-routing.
When retrying, the system progressively improves queries. For example: "Find competitors" → "Find top competitors in [specific market]" → "Find top 5 competitors in [specific market] with [specific criteria]" → "Find top 5 competitors in [specific market] with [specific criteria] from [specific sources]"
Type: Business rule violations
Handling: Retry with improved queries
Example: "Minimum 4 sources required, found 2" - Returns ValidationResult with is_valid=False and error messages
Type: External service failures
Handling: Automatic retry with exponential backoff using tenacity library
Example: Groq API rate limit, Tavily API timeout - Automatically retries up to 3 times with exponential backoff (2-10 seconds)
Type: Connection failures
Handling: Retry with tenacity
Example: Timeout, connection refused
Type: Invalid or incomplete data
Handling: Validation gates catch and retry
Example: Missing required fields, invalid URLs

GROQ_API_KEY not foundSolution:
# Check .env file exists ls -la .env # Verify key is set cat .env | grep GROQ_API_KEY
ModuleNotFoundErrorSolution:
# Reinstall dependencies pip install -r requirements.txt --upgrade
Solution:
MAX_RETRIES in .envSolution:
Before installation, ensure you have:
git clone https://github.com/ashrafyahya/multi_agent_system_project.git cd multi_agent_system_project
Windows:
python -m venv venv venv\Scripts\activate
macOS/Linux:
python -m venv venv source venv/bin/activate
pip install -r requirements.txt
This installs:
Create a .env file in the project root:
# Required GROQ_API_KEY=your_groq_api_key_here GROQ_MODEL=llama-3.1-8b-instant # Optional but Recommended TAVILY_API_KEY=your_tavily_api_key_here # Configuration MAX_RETRIES=3 LOG_LEVEL=INFO DATA_DIR=./data
Run a quick test:
python -m src.main "Test query"
If you see the workflow executing, installation is successful! 🎉
Check that everything is installed correctly:
# Check Python version python --version # Should be 3.10+ # Check installed packages pip list | grep langchain pip list | grep langgraph # Run tests pytest tests/ -v
The Competitor Analysis Multi-Agent System revolutionizes market research by:
From weeks to minutes. From expensive to affordable. From inconsistent to reliable.