An intelligent multi-agent system for database operations, analytics, and visualization, powered by OpenAI GPT.
- Database Agent: Schema management and evolution
- ETL Agent: Data import and transformation
- Analytics Agent: Business intelligence and visualization
- Orchestrator Agent: Pipeline coordination
- Natural language to SQL conversion
- Automated schema generation and management
- Intelligent data import with referential integrity
- Interactive business analytics dashboards
- Query validation and execution
- Async support
- Python 3.8+
- PostgreSQL 12+
- OpenAI API key
- pip (Python package manager)
-
Install PostgreSQL:
# Ubuntu/Debian sudo apt-get update sudo apt-get install postgresql postgresql-contrib # macOS using Homebrew brew install postgresql@14
-
Create a database and user:
# Connect to PostgreSQL psql postgres # In psql console: CREATE DATABASE your_database_name; CREATE USER your_username WITH PASSWORD 'your_password'; GRANT ALL PRIVILEGES ON DATABASE your_database_name TO your_username;
-
Clone and install:
git clone https://github.com/yourusername/sqlagent cd sqlagent python -m venv venv source venv/bin/activate # or .\venv\Scripts\activate on Windows pip install -e .
-
Configure environment:
# Create .env file echo "OPENAI_API_KEY=your_openai_api_key" >> .env echo "DB_CONNECTION_STRING=postgresql://your_username:your_password@localhost:5432/your_database_name" >> .env
from src.core.agent import SQLAgent
from src.utils.config import Config
async def main():
config = Config()
agent = SQLAgent(config)
# Get schema
schema = await agent.get_schema()
# Import data
await agent.import_csv_data(schema, "data/sales_data.csv")
# Generate sales analytics dashboard
await agent.generate_dashboard(results, query)
request = QueryRequest(
question="What are the top 5 products by total sales?",
include_explanation=True
)
result = await agent.process_request(request)
The system provides several pre-built analytics views:
- Sales Trends Analysis
- Product Performance Metrics
- Geographic Distribution
- Payment and Order Status Analysis
Access the interactive dashboard at http://localhost:8050
after running the dashboard demo.
sqlagent/
├── src/
│ ├── agents/ # Specialized AI agents
│ ├── core/ # Core functionality
│ ├── database/ # Database operations
│ ├── visualization/ # Dashboard generation
│ └── utils/ # Utilities
├── examples/ # Usage examples
└── tests/ # Test suite
# Basic usage
python examples/basic_usage.py
# Dashboard demo
python examples/dashboard_demo.py
# Complete workflow
python examples/complete_workflow.py
- Fork the repository
- Create your feature branch
- Commit your changes
- Push to the branch
- Create a Pull Request
-
Dashboard not showing:
- Ensure you're accessing http://localhost:8050
- Check if the port is available
- Verify data was imported successfully
-
Data import errors:
- Verify CSV format matches schema
- Check database permissions
- Ensure referential integrity
-
Environment issues:
- Verify .env file exists and is properly formatted
- Check OpenAI API key is valid
- Confirm database connection string is correct
MIT License - see LICENSE file for details