Skip to content

3cx/GoogleBigQueryAgent

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

1 Commit
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

3CX BigQuery SQL Agent

A Python CLI agent powered by Google Gemini & Google ADK that queries BigQuery data using natural language.

Features

  • πŸ—£οΈ Natural Language Queries - Ask questions in plain English, get SQL results
  • πŸ€– Powered by Gemini 3 Pro - Uses Google's latest LLM for intelligent query generation
  • πŸ”§ Google ADK Integration - Built with Google's Agent Development Kit
  • 🎨 Colored CLI Output - Easy-to-read responses with syntax highlighting
  • ⏳ Progress Indicator - Spinner shows when queries are processing
  • πŸ“Š Usage Stats - See duration and token usage for each query

Architecture

flowchart LR
    User[User CLI] <--> Runner[ADK Runner]
    Runner <--> Agent[LlmAgent]
    Agent <--> Gemini[Google Gemini]
    Agent <--> BQToolset[BigQueryToolset]
    BQToolset <--> BQ[(BigQuery)]
    
    subgraph tools [Available Tools]
        list_datasets[list_dataset_ids]
        get_dataset[get_dataset_info]
        list_tables[list_table_ids]
        get_table[get_table_info]
        execute_sql[execute_sql]
    end
    
    BQToolset --> tools
Loading

How It Works

  1. User CLI β†’ Sends question to ADK Runner
  2. ADK Runner β†’ Wraps message and sends to LlmAgent
  3. LlmAgent β†’ Sends question + tool definitions to Gemini
  4. Google Gemini β†’ Analyzes question, returns tool call (e.g., SQL query)
  5. LlmAgent β†’ Passes tool call to BigQueryToolset
  6. BigQueryToolset β†’ Executes query against BigQuery
  7. BigQuery β†’ Returns query results
  8. Gemini β†’ Formats results into human-readable response
  9. CLI β†’ Displays the answer with stats

Installation

Prerequisites

  • Python 3.10+
  • Google Cloud account with BigQuery access
  • Gemini API key

Setup

  1. Clone the repository

    git clone https://github.com/yourusername/GoogleBigQueryAgent.git
    cd GoogleBigQueryAgent
  2. Create virtual environment

    python -m venv venv
    source venv/bin/activate  # On Windows: venv\Scripts\activate
  3. Install dependencies

    pip install -r requirements.txt
  4. Authenticate with Google Cloud

    gcloud auth application-default login
  5. Configure environment variables

    cp .env.example .env
    # Edit .env with your settings

Configuration

Create a .env file with:

# Required
GOOGLE_API_KEY=your-gemini-api-key

# Optional - override defaults
GOOGLE_CLOUD_PROJECT=your-project-id
BIGQUERY_DEFAULT_DATASET=your-dataset-name

Usage

python main.py

Or if installed as a package:

bigquery-agent

Example Session

============================================================
BigQuery SQL Agent
============================================================
Google Cloud Project ID: **********568
Default BigQuery Dataset: 3cx_call_data
------------------------------------------------------------
Ask questions about your BigQuery data.
Type 'quit' or 'exit' to stop.

You: What datasets are available?

Agent: I found the following datasets in your project:
- 3cx_call_data
- analytics
- logs

────────────────────────────────────────
Duration: 2.34s | Tokens: 150 in / 89 out
────────────────────────────────────────

Example Questions

Discovery & Schema

  • "What Datasets are available?"
  • "Show me the schema of the cdroutput table"

Data Queries

  • "Show me all calls that happened yesterday"
  • "Print all the information about this call"
  • "Is there a recording associated with this call?"

Investigation

  • "I had a complaint in the last 30 days. All I know is that the customer name is John and recipient was Sarah"
  • "Can you show me all calls in the last 30 days that were abusive or spam related?"

Performance Analysis

  • "How many calls did Sarah answer in the last 30 days? Which ones were with a duration of more than 1 minute?"
  • "Based on these calls, how can I help my colleague to do her job better?"

Project Structure

GoogleBigQueryAgent/
β”œβ”€β”€ bigquery_agent/
β”‚   β”œβ”€β”€ __init__.py       # Package exports
β”‚   β”œβ”€β”€ agent.py          # LlmAgent configuration
β”‚   └── cli.py            # CLI interface with colors/spinner
β”œβ”€β”€ .env.example          # Environment template
β”œβ”€β”€ .gitignore            # Git ignore rules
β”œβ”€β”€ LICENSE               # MIT License
β”œβ”€β”€ main.py               # Entry point
β”œβ”€β”€ pyproject.toml        # Package configuration
β”œβ”€β”€ README.md             # This file
└── requirements.txt      # Dependencies

Development

Running locally

python main.py

Installing as editable package

pip install -e .

License

MIT License - see LICENSE for details.

Acknowledgments

About

A BigQuery SQL Agent powered by Google Gemini and Google ADK

Resources

License

Stars

1 star

Watchers

1 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages