An AI-powered two-agent system that compares any two products — giving you specs, pros/cons, and a smart recommendation.
The Product Comparison Engine is an intelligent web application that allows users to compare any two products side-by-side. Users simply enter two product names (e.g., iPhone 15 vs Samsung Galaxy S24), and a multi-agent AI pipeline automatically fetches product data, analyses it, and delivers a clear, unbiased recommendation.
Problem it solves: Researching and comparing products is time-consuming. Users visit multiple sites, read lengthy reviews, and still struggle to make a decision. This engine automates the entire process.
Who it's for: Students, shoppers, tech enthusiasts, and anyone who wants to make smarter purchase decisions quickly.
Students will learn how to:
- Build a multi-agent AI system using LangChain
- Use LLM tool calling and ReAct agents
- Integrate a Streamlit frontend with a multi-step AI backend
- Design agent pipelines where Agent 1 feeds Agent 2
- Handle real-world web data fetching inside agent tools
- Structure a production-grade Python AI project
Key concepts covered:
- LangChain Agents & AgentExecutor
- ReAct (Reason + Act) agent pattern
- LangChain Tools (
@tooldecorator) - Chat models with Groq llama
- Streamlit UI with dynamic state management
- 🔵 Agent 1 — Data Collector: Automatically fetches specs, price, ratings, and key info for any product
- 🟢 Agent 2 — Decision Maker: Analyses both products and generates a structured comparison with pros, cons, and recommendation
- ⚡ Real-time streaming UI with live status updates per agent
- 📦 VS input parser: Accepts both separate fields and
"Product A vs Product B"format - 💡 Quick example buttons in the sidebar for instant demos
- 📊 Formatted comparison table with markdown rendering
- 🔒 Secure API key input via sidebar (not stored)
User Input (Product A, Product B)
│
▼
┌──────────────────────────┐
│ Agent 1: Data Collector │ ← Uses fetch_product_data tool
│ - Fetches specs │ (DuckDuckGo API + Claude knowledge)
│ - Price range │
│ - User ratings │
│ - Target audience │
└──────────┬───────────────┘
│ Structured Profile A + B
▼
┌──────────────────────────┐
│ Agent 2: Decision Maker │ ← Reasoning-only (no tool needed)
│ - Comparison table │
│ - Pros & Cons │
│ - Final recommendation │
└──────────┬───────────────┘
│
▼
Streamlit UI — Full Report
Step-by-step flow:
- User enters Product A and Product B in the Streamlit UI
- Agent 1 runs for Product A → fetches web data → builds structured profile
- Agent 1 runs for Product B → same process
- Agent 2 receives both profiles → performs deep comparison analysis
- Full report with table, pros/cons, and recommendation is displayed
| Layer | Technology |
|---|---|
| Language | Python 3.10+ |
| Agent Framework | LangChain 0.2.x |
| LLM Provider | Groq (LLaMA 3 70B) |
| Frontend | Streamlit 1.35 |
| Web Data Tool | DuckDuckGo Instant API + LLM knowledge |
| HTTP Client | Requests |
| Environment | python-dotenv |
product_comparison_engine/
│
├── main.py # Streamlit app entry point
│
├── agents/
│ ├── __init__.py
│ ├── data_collector.py # Agent 1: fetches product data
│ └── decision_maker.py # Agent 2: compares & recommends
│
├── tools/
│ ├── __init__.py
│ └── product_fetcher.py # LangChain tool: web search
│
├── utils/
│ ├── __init__.py
│ └── helpers.py # Input parsing & text utilities
│
├── .env # Environment variable template
├── requirements.txt # Python dependencies
└── README.md
- Python 3.10 or higher
- A Groq API key → Get one here
- A SerpAPI key → Get one here (Free, 250 searches/month)
Step 1: Clone or download the project
git clone <your-repo-url>
cd product_comparison_engineStep 2: Create a virtual environment (recommended)
python -m venv venv
source venv/bin/activate # Mac/Linux
venv\Scripts\activate # WindowsStep 3: Install dependencies
pip install -r requirements.txtStep 4: Set up environment
- GROQ_API_KEY=gsk_your_groq_key_here
- SERPAPI_KEY=your_serpapi_key_here
streamlit run main.pyThen open your browser at: http://localhost:8501
Defines a LangChain @tool called fetch_product_data. It calls the DuckDuckGo Instant Answer API to retrieve a web snippet about the product, and returns it as a formatted string. This is the "eyes" of Agent 1.
Builds a ReAct agent using create_react_agent. The agent receives a product name, uses the fetch_product_data tool to gather web data, and then uses Claude to reason over that data and return a clean structured profile (price, specs, ratings, etc.).
A reasoning-only agent (no tool needed). It receives the two structured profiles from Agent 1, and uses a carefully crafted system prompt to produce a formatted comparison table, pros/cons lists, and a clear recommendation.
Contains helper functions like parse_vs_input() which parses a string like "iPhone vs Samsung" into two separate product names, and sanitize_product_name() for clean formatting.
The Streamlit UI. Handles user input, calls both agents sequentially, shows live status for each agent step, and renders the final markdown report.
Input:
Product A: iPhone 15 Pro
Product B: Samsung Galaxy S24
Agent 1 Output (per product):
Product Name: iPhone 15 Pro
Category: Smartphone
Price Range: ₹1,34,900 – ₹1,59,900
Key Specifications:
- A17 Pro chip (3nm)
- 48MP main camera, 12MP ultrawide, 12MP telephoto
- 6.1-inch Super Retina XDR display
- USB-C with USB 3 speeds
- Titanium frame
User Ratings: 4.6/5 — Highly praised for camera and performance
Availability: Online & Offline
Target Audience: Premium users, creative professionals
Agent 2 Output:
## 📊 Comparison Summary
| Feature | iPhone 15 Pro | Samsung Galaxy S24 |
|--------------|--------------|-------------------|
| Price | ₹1,34,900+ | ₹79,999+ |
| Rating | 4.6/5 | 4.5/5 |
| Performance | A17 Pro | Snapdragon 8 Gen 3|
...
## 🏆 Recommendation
Best Choice: Samsung Galaxy S24
Why: Offers flagship performance at a significantly lower price point...
Best for: Budget-conscious users who want premium Android experience
Students can extend this project in several ways:
- Add real APIs: Integrate the Flipkart Affiliate API or Amazon Product Advertising API for live pricing
- Add more agents: Create an "Agent 3 — Review Sentiment Analyzer" that reads user reviews from the web
- Price tracking: Add a history graph showing price trends over time using Plotly
- Category auto-detection: Automatically detect whether products are phones, laptops, headphones, etc. and adjust comparison criteria
- Export feature: Let users download the comparison as a PDF report
- Voice input: Add speech-to-text so users can speak product names
- 🔄 Streaming responses — Show the comparison report token by token as it's generated
- 🌐 Real e-commerce API integration — Live price and availability from Amazon/Flipkart
- 📈 Comparison history — Save past comparisons in a local database
- 🌍 Multi-language support — Generate reports in Tamil, Hindi, etc.
- 📱 Mobile-responsive UI — Better layout for phone screens
- 🤝 Group comparison — Compare 3 or more products at once
- 🔔 Price alert agent — Notify user when a product drops in price
- Kruthiga T B
- Lavanya S
Built with ❤️ using LangChain, Groq (LLaMA 3 70B), and Streamlit