πŸ“ Market Research Agent

Location-intelligence agent for local shop owners, near-zero cost

Python FastAPI SQLite Google Maps (cached) Governed Queries Cloud Run

πŸ“‹ Project Overview & Problem Statement

Challenge: A small shop owner deciding where to open, how to price, or what to launch usually guesses. Proper market research is slow and expensive, and the live-data tools that could answer these questions (a model writing SQL, live Google Maps on every query) rack up cost fast.

Solution: Market Research Agent answers the 10 questions an owner actually asks, drawing on a local business data pack plus cached Google Maps results. The agent never writes free-form SQL; it may only call one of 10 approved, parameterized queries. Maps is called only on a schedule and cached, so user questions cost almost nothing. The demo is configured for a tong shui (Chinese dessert) shop in the Klang Valley, but the same schema and questions work for any local, consumer-facing business.

Key Benefits

πŸ–₯️ Application Features

πŸ“ Where to Open

Finds the area with the highest foot traffic by daypart, and the opportunity pockets that have strong evening traffic but few existing shops. Tong shui peaks at supper, so the answer leans evening.

πŸ‘₯ Who Lives There

Ranks areas by how well the resident profile fits the target customer, using population, age, and Chinese-population share as the demand signal for a tong shui shop.

πŸͺ How Saturated

Counts competing shops in an area from the cached Maps table and reads whether the district is already well served or still open.

πŸ’° How to Price

Returns the competitor price range for a bowl and finds the unoccupied price band, the gap where a quality, less-sweet offer can sit.

πŸ“ˆ What Sells

Projects next quarter's revenue from the sales history and ranks which desserts are growing or declining week over week.

βœ… Stand Out and Decide

Surfaces the top competitor complaints from cached reviews, then assembles a single go / no-go recommendation for a chosen area.

The 10 Governed Questions

πŸ€– AI Integration & Intelligence

🧭 Governed Query Routing

The agent maps a free-text question to one of 10 approved query tools. Routing is deterministic and free for the known questions, with an optional cheap-model (Gemini Flash / Claude Haiku) fallback for open phrasings.

πŸ—ΊοΈ Cached Maps, Not Live

Competitor places and reviews come from a scheduled Google Maps refresh stored as local tables. Every user question reads the cache, so Maps is the only paid call and it runs on a timer, not per request.

🚫 Refusal by Design

Anything outside the 10 questions is declined rather than guessed. The agent cannot write its own SQL, list tables, or dump records, which keeps answers predictable and cheap.

🧩 Multi-Source Synthesis

The go / no-go question combines foot traffic, demographics, the price gap, the demand trend, and competitor complaints into one grounded recommendation for a specific area.

πŸ› οΈ Technical Architecture & Implementation

Frontend Stack

HTML / CSS Vanilla JavaScript Fetch to /ask Static-fallback demo mode

Backend Stack

Python 3.11 FastAPI SQLite 10 Parameterized Queries Google Maps Places (cached)

Deployment & Infrastructure

Google Cloud Run Docker Cloud Scheduler (cache refresh)

System Architecture

πŸ“– Development Setup & Installation Guide

Prerequisites

Quick Start Installation

# Clone the repository git clone https://github.com/lyven81/ai-project.git cd ai-project/projects/market-research-agent # Build the data pack and SQLite database python setup/generate_data.py python setup/build_db.py # Install dependencies and run pip install -r requirements.txt uvicorn app.main:app --port 8080 # open http://127.0.0.1:8080

Environment Configuration

# Only needed for the live Maps cache refresh (cache/refresh_maps_cache.py) MAPS_API_KEY=your_places_api_key_here

Available Scripts

πŸš€ Deployment on Google Cloud Run

# Build and deploy to Cloud Run (scales to zero) gcloud run deploy market-research-agent \ --source . \ --region asia-southeast1 \ --allow-unauthenticated \ --set-env-vars MAPS_API_KEY=your_api_key

Production Notes

πŸ“Š Key Metrics

10
Governed Questions
7
Data Tables
6 / 10
Answered by Pure SQL
Near-Zero
Cost Per Question

Business Value