An autonomous AI Data Analyst Agent that allows users to interact with a PostgreSQL database using natural language instead of SQL.
This system understands business questions, generates optimized SQL queries, executes them safely (read-only), and returns tabular results with intelligent analytical insights.
It simulates the behaviour of a real Business Intelligence Consultant powered by AI.
Modern businesses generate large amounts of operational data but decision-makers often lack SQL knowledge.
This project demonstrates how an AI Agent can bridge the gap between raw database data and executive-level insights through conversational intelligence.
The agent can:
- Understand intent
- Explore schema automatically
- Generate safe SQL queries
- Analyse results
- Provide business explanations
- Support conversational follow-ups
✅ Natural Language → SQL → Insights pipeline
✅ Conversational memory (context-aware responses)
✅ Automatic database schema understanding
✅ Alias-safe SQL generation
✅ Read-only secure execution layer
✅ Business-focused analytical explanations
✅ Tabular result rendering in chat UI
✅ Model Context Protocol (MCP) compatible
✅ Realistic AI automation demo dataset
- How is my revenue trend?
- Which city generates the highest order value?
- Show pending followups scheduled today
- Which customers are most active recently?
- Are AI-booked orders performing better than human bookings?
- What insights can you give about campaign effectiveness?
- Explain more about that trend
The agent behaves like a data analyst, not just a query engine.
User (Natural Language)
→ AI Reasoning Layer
→ SQL Generation
→ PostgreSQL Execution
→ Result Interpretation
→ Insightful Natural Language Response
This follows a modern Agentic BI Architecture Pattern.
The system is intentionally restricted to:
- SELECT queries only
- No INSERT / UPDATE / DELETE
- No schema modification
This ensures:
✔ Database integrity
✔ Safe enterprise analytics
✔ Risk-free AI exploration
A realistic AI automation business dataset is included.
It simulates:
- Customer lifecycle tracking
- AI service bookings
- Conversation sentiment analysis
- Follow-up automation
- AI task execution monitoring
- Revenue insights
/database/ai_agent_demo_dataset.sql
psql -U postgres -d ai_agent_demo\i database/ai_agent_demo_dataset.sqlThis will create tables:
- customers
- orders
- conversations
- ai_tasks
- followups
- ai_insights
with realistic sample data.
git clone <your-repository-url>
cd postgres-mcpnpm installCreate .env
PGHOST=localhost
PGPORT=5432
PGDATABASE=ai_agent_demo
PGUSER=postgres
PGPASSWORD=your_password
OPENAI_API_KEY=your_openai_keynpm startOpen:
http://localhost:3000
To expose database tools via Model Context Protocol:
node src/server.js --mcpThis enables integration with:
- Claude Desktop
- Agent frameworks
- Autonomous workflows
- Reads full database schema dynamically
- Maintains conversational memory
- Understands business intent
- Generates optimized SQL
- Executes safely
- Converts raw rows into executive insights
This makes the system behave like:
👉 AI Data Analyst
👉 BI Consultant
👉 Decision Support Assistant
- 📈 Automatic chart generation
- 🚨 KPI anomaly detection
- 🔮 Predictive revenue forecasting
- 🧠 Autonomous insight suggestions
- 📊 Dashboard API layer
- 🛠️ Multi-tool planning agent
- ☁️ SaaS deployment architecture
Aditya Jadhav
AI Automation & Agent Systems Builder