🗃️ SME Business Advisor — AlloyDB

AI Agent + AlloyDB for Open-Ended Business Analytics

Python Google ADK AlloyDB PostgreSQL Google Gemini 2.0 Flash FastAPI Docker

📋 Project Overview & Problem Statement

Challenge: The previous versions use pre-built analytical tools — each tool answers a fixed type of question. If a user asks something outside those 6-7 tool categories, the agent cannot answer. Real business questions are unpredictable and open-ended.

Solution: This version stores data in a database and lets the AI agent write custom SQL queries for every question. No fixed report menu — the agent converts plain English to SQL, executes it against AlloyDB, and returns the answer. Any question that can be answered with the data is fair game.

How It Works

🖥️ Application Features

💬 Natural Language to SQL

Ask any business question in plain English. The agent translates it into a SQL query, executes it against the database, and returns the answer — no SQL knowledge required from the user.

📜 4-Step Execution Log

Every answer shows the full execution chain: question received, SQL query generated, database query executed, answer returned. Users can inspect exactly how their question was answered.

🟢 Database Status Panel

A status panel in the UI shows the database connection state, table name, total row count, and column count — confirming the agent has access to the full dataset.

💡 No Fixed Menu

Unlike the tool-based versions, there is no fixed set of report types. Users can ask any question the data can answer — from simple lookups to complex multi-condition analyses.

🔭 Complex Query Support

The agent handles multi-filter queries, date range comparisons, grouped aggregations, sorting, and nested conditions — matching what a human analyst would write in SQL.

🏷️ Column Tags Display

The UI displays all available column names as tags, so users know exactly what data fields they can ask about — reducing guesswork and improving question quality.

🤖 AI Integration & Intelligence

🧠 Google ADK + Cloud SQL PostgreSQL

Google ADK orchestrates the agent while Cloud SQL PostgreSQL (AlloyDB-compatible) serves as the data backend. The agent writes SQL dynamically based on user questions — no hardcoded queries.

⚡ Gemini 2.0 Flash

Gemini handles both SQL generation and answer synthesis. It understands the table schema, writes correct SQL, and translates raw query results into plain-language business recommendations.

🔒 SELECT-Only Safety

The agent is restricted to SELECT queries only. INSERT, UPDATE, DELETE, and DDL commands are blocked at the application layer — the database is read-only from the agent's perspective.

🗂️ Schema-Aware Reasoning

The agent is provided with the full table schema (column names, types) at startup. This enables accurate SQL generation without trial-and-error — the agent knows what columns exist before writing any query.

🛠️ Technical Architecture & Implementation

Frontend Stack

FastAPI HTML / CSS / JavaScript Execution Log UI

Backend Stack

Python Google ADK pg8000 (PostgreSQL driver)

Database

Cloud SQL PostgreSQL AlloyDB-Compatible

Deployment

Docker Google Cloud Run

System Architecture

📊 Key Metrics

39,500
Database Rows
17
Data Columns
Unlimited
Query Types
4-Step
Execution Log