A Creative agent continuously peppers questions to Vanna agent which continuously executes them. An Alert agent notifies the user via WhatsApp if something looks off.
This system proactively monitors your database through three autonomous agents:
- Creative Agent - Generates exploratory questions based on your schema, plus runs scheduled structured tasks
- Vanna Agent - Converts questions to SQL and executes them against your database
- Alert Agent - Analyzes results for anomalies and sends WhatsApp notifications when issues are detected
Creative Agent β Queue β Vanna Agent β Alert Agent β WhatsApp
ββ Exploratory ββ SQL Gen ββ Automatic
ββ Structured ββ Execution ββ Anomaly Detection
Key Features:
- Creative agent continuously generates relevant questions about your data
- Queue system prevents overwhelming the Vanna agent (max 10 items)
- Exploratory questions pause when queue is full
- Structured tasks always run on schedule
- Per-task alert configuration with intelligent anomaly detection
- WhatsApp notifications keep you informed
# Create virtual environment
python3 -m venv venv
source venv/bin/activate
# Install dependencies
pip install -r requirements.txt
# Configure environment variables
cp .env.example .env
# Edit .env and add your API keys:
# - OPENAI_API_KEY (required)
# - VANNA_API_KEY (required)
# - VANNA_USER_EMAIL (required)
# - VANNA_AGENT_ID (required)
# Create schema.json (choose ONE option):
# OPTION A: Extract from BigQuery
gcloud auth application-default login
python extract_schema.py
# OPTION B: Convert from CSV
# 1. Create a CSV file describing your schema (see schema.example.csv)
# 2. Convert it to schema.json:
python csv_to_schema.py your_schema.csv --project your-project --dataset your-dataset
# OPTION C: Create manually
# Use schema.example.json as a template and customize for your database
# Create training_data.csv
# Use training_data.example.csv as a template with example question-SQL pairs
cp training_data.example.csv training_data.csv
# Edit with your own question-SQL examplesCreate your tasks configuration:
cp tasks.example.yaml tasks.yaml
# Edit tasks.yaml with your monitoring tasks and questionsThe example includes:
- Daily user engagement monitoring
- Revenue tracking with dropoff alerts
- Hourly order volume checks
- Weekly signup comparisons
python main.py1. Get Twilio Account
- Sign up at https://www.twilio.com/try-twilio
- Get free trial credits ($15)
2. Join WhatsApp Sandbox
- Go to Console β Messaging β Try it out β Send a WhatsApp message
- Send "join
" to the Twilio WhatsApp number - Note your credentials:
- Account SID
- Auth Token
- Sandbox Number (e.g., +14155238886)
3. Configure Environment Variables
Edit your .env file and add:
TWILIO_ENABLED=true
TWILIO_ACCOUNT_SID=your-account-sid
TWILIO_AUTH_TOKEN=your-auth-token
TWILIO_WHATSAPP_FROM=whatsapp:+14155238886 # Sandbox number
TWILIO_WHATSAPP_TO=whatsapp:+12345678900 # YOUR number with country code
4. Install Twilio (already in requirements.txt)
pip install -r requirements.txt
5. Test
When alerts trigger, you'll receive WhatsApp messages! π±
π MONITORING ALERT
Task: USER_ENGAGEMENT
Type: structured
π¨ ANOMALY DETECTED (HIGH): Engagement dropped 15%
Question: What is user engagement...
Time: 2025-11-13 10:30:45
For production without "sandbox" branding:
- Apply for WhatsApp Business API
- Get business verification (~1-2 weeks)
- Use approved business number
- Sandbox: FREE with trial credits
- Production: ~$0.005 per message
- 10 alerts/day = $1.50/month
- 100 alerts/day = $15/month
Don't set TWILIO_ENABLED or set to "false" - alerts will only show in terminal.
structured_tasks:
- name: vip_user_usage
cadence_hours: 24 # Run daily
question: "What is usage for [email protected], [email protected], and [email protected]?"
alert_mode: "anomaly" # or "automatic"
anomaly_threshold:
type: "percent_change"
value: 0.10 # 10% threshold
- name: weekly_revenue
cadence_hours: 168 # Run weekly (7 days)
question: "What was revenue this week vs last week?"
alert_mode: "automatic"
creative_agent:
enabled: true
cadence_hours: 1 # Run hourly
alert_mode: "anomaly"
anomaly_threshold:
type: "general"
value: 0.05 # 5% threshold
automatic
- Always alerts with results
- Use for: Critical metrics you always want to see
- Example: Daily revenue reports
anomaly
- Only alerts if anomaly detected
- Uses AI to analyze results against thresholds
- Use for: Monitoring that should be quiet unless something's wrong
- Example: VIP user activity (alert if drops >10%)
Type
Description
Example
percent_change
Detects % changes in either direction
Alert if 10% change
dropoff
Detects decreases only
Alert if drops 5% or more
spike
Detects increases only
Alert if increases 20% or more
general
AI decides what's anomalous
Baseline 5% threshold
Hours
Equivalent
Use Case
1
Hourly
Frequent checks
24
Daily
Standard monitoring
168
Weekly
Summary reports
0.0014
~5 seconds
Testing only
0.0028
~10 seconds
Testing only
============================================================
β
VANNA RESULT [STRUCTURED: vip_user_usage]
Question: What is usage for [email protected]...
Result:
Usage is 45 queries this week, up 7% from last week...
============================================================
ππππππππππππππππππππππππππππππ
π’ ALERT: WEEKLY_REVENUE
Type: structured
Reason: Automatic alert (always notifies)
Question: What was revenue this week vs last week?
Timestamp: 2025-11-11 22:30:15
ππππππππππππππππππππππππππππππ
ππππππππππππππππππππππππππππππ
π’ ALERT: VIP_USER_USAGE
Type: structured
Reason: π¨ ANOMALY DETECTED (HIGH): Usage dropped 15% week-over-week, exceeding 10% threshold
Question: What is usage for [email protected]...
Timestamp: 2025-11-11 22:30:15
ππππππππππππππππππππππππππππππ
Edit tasks.yaml:
structured_tasks:
- name: new_metric
cadence_hours: 24
question: "Your question here"
alert_mode: "anomaly"
anomaly_threshold:
type: "percent_change"
value: 0.10
Just edit the YAML and restart the agent (Ctrl+C, then re-run).
Remove the task from YAML and restart.
creative_agent:
enabled: false
proactive-agent/
βββ main.py # Main monitoring agent (Creative/Vanna/Alert)
βββ extract_schema.py # BigQuery schema extractor
βββ csv_to_schema.py # CSV to schema.json converter
βββ .env # Your secrets (not in git)
βββ .env.example # Template for environment variables
βββ tasks.yaml # Your monitoring tasks (create from example)
βββ tasks.example.yaml # Example tasks configuration
βββ schema.json # Your database schema (create from examples)
βββ schema.example.json # Example schema (JSON format)
βββ schema.example.csv # Example schema (CSV format)
βββ training_data.csv # Your Q-SQL training pairs (create from example)
βββ training_data.example.csv # Example training data
βββ questions.db # SQLite database (generated)
βββ requirements.txt # Python dependencies
βββ setup_check.py # Setup verification script
βββ .gitignore # Excludes secrets and user files
βββ README.md # This file
Exploratory Questions:
- AI generates novel questions based on your database schema and past Q-SQL pairs
- Checks for duplicates to avoid repetition
- Pauses if queue is full (>10 items) to prevent overwhelming Vanna
Structured Tasks:
- Runs predefined questions from
tasks.yaml on a schedule
- Always executes on time
- Waits in queue if Vanna agent is busy
- Receives questions from the queue
- Converts natural language to SQL queries
- Executes against your database
- Returns results as text
Automatic Mode:
- Every result triggers a WhatsApp alert
- No analysis needed
- Use for critical metrics you always want to see
Anomaly Mode:
- AI (GPT-4o-mini) analyzes results against configured thresholds
- Detects percent changes, dropoffs, spikes, and other anomalies
- Only sends WhatsApp alert if something looks off
- Keeps notifications relevant and actionable
βοΈ [EXPLORATORY] Queue full (11 items), skipping...
Solution: This is normal. Creative agent pauses exploratory questions until Vanna agent clears the queue.
β Vanna API error: ...
Solution: Check VANNA_API_KEY is set correctly.
β schema.json not found!
Solution: Run python extract_schema.py first.
Solution: Increase cadence_hours for the creative agent in tasks.yaml.
β οΈ WhatsApp alert failed: ...
Solutions:
- Verify you joined Twilio sandbox (send "join
")
- Check phone number format:
whatsapp:+1234567890 (include country code)
- Verify credentials are correct
- Check Twilio account has credits
pip install twilio
cp tasks_test.yaml tasks.yaml
python main.py
Watch for:
- Questions being generated
- Vanna API calls
- Results being displayed
- Alerts appearing (automatic and anomaly)
Press Ctrl+C to stop gracefully.
- Schema extracted (
schema.json exists)
- Training data present (
training_data.csv exists)
- API keys set (OpenAI, Vanna)
- Tasks configured (
tasks.yaml)
- Agent starts without errors
- Questions being generated
- Vanna responses received
- Alerts appearing correctly
- β
Question generation (exploratory + structured)
- β
Vanna execution (SQL + results)
- β
Alert agent (automatic + anomaly detection)
- β
WhatsApp alerts (via Twilio)
- β
Terminal output
- π Hot-reload tasks.yaml without restart
- π Dashboard for viewing history
- π Store results in database
- π Email alerts
- π Slack integration
- π Alert routing rules
python setup_check.py
sqlite3 questions.db "SELECT * FROM generated_questions ORDER BY timestamp DESC LIMIT 10;"
sqlite3 -header -csv questions.db "SELECT * FROM generated_questions;" > generated_questions.csv
To add new features:
- Edit
main.py for agent logic
- Edit
tasks.yaml for configuration
- Update this README
- Test with
tasks_test.yaml first
Internal use only.