⚡ DB-Agent
Enterprise AI Database Copilot & Autonomous Data Agent (CLI)
Author: Santhosh Gupta | 100% Free, Standalone, Works Offline (Ollama) or with Cloud AI (Gemini / Groq / OpenRouter).
🌟 What is DB-Agent?
DB-Agent is a production-grade AI Database Agent and Copilot. It empowers developers, DBAs, data analysts, and non-technical users to inspect schemas, discover complex multi-hop table relationships, generate and optimize SQL, execute queries with enterprise safety guardrails, and visualize data directly in the terminal.
🚀 2-Minute Quickstart
Step 1: Install from PyPI
pip install "dbagent-cli[all]"
Step 2: 1-Click AI Setup
db-agent setup
Choose between:
- Local Offline AI (Ollama): Zero API keys, 100% private, runs entirely on your machine.
- Free Cloud AI (Gemini / Groq / OpenRouter): Ultra-fast cloud processing.
- Database Tools Only: Standard DB introspection and CLI tools without AI.
Step 3: Connect Database & Save Alias
db-agent connect postgresql://user:password@localhost:5432/mydb --alias my_db
(Supports PostgreSQL, MySQL, SQLite, SQL Server, Oracle, DuckDB, and MongoDB).
Step 4: Ask Plain English Questions or Launch Chat!
# 1. Ask a question and get instant live results table + ASCII charts
db-agent ask "list top 10 users" --db my_db
# 2. Or start the interactive AI copilot shell
db-agent chat --db my_db
🛡️ Key Enterprise Features
1. 🧠 Relationship Graph & Smart Multi-Hop JOINs
Automatically discovers multi-hop join paths between disconnected tables without guessing arbitrary joins.
# Find shortest relationship path between two tables:
db-agent path users events --db my_db
# Explain join cardinality (1:1, 1:N) and recommended join syntax:
db-agent explain-join customers orders --db my_db
2. ⚡ Persistent Schema Cache & Change Detection
Never runs expensive full database scans on every query. Local cache (~/.dbagent/cache/) detects schema diffs:
db-agent refresh-schema --db my_db
db-agent schema-status --db my_db
3. 🔒 Safety Modes & Production Protection
Five operational safety modes enforce strict boundaries before SQL execution:
SAFE: OnlySELECT,SHOW,DESCRIBE,EXPLAIN,WITHallowed. All writes and DDL are strictly blocked.READ_ONLY: Enforced onPRODUCTIONenvironments with 5s timeouts and row caps.CONFIRM: Reads auto-execute; write and DDL operations require interactive confirmation.SANDBOX: Writes executed inside uncommitted transactions with before/after diff preview.ADMIN: Full administrative access with audit tracking.
4. ⏪ Change Sets & Snapshot Rollback
Before executing modifying queries, DB-Agent captures a recovery snapshot and creates an auditable ChangeSet:
db-agent changes
db-agent changes-show CS-20260828-001
db-agent rollback CS-20260828-001 --db my_db
5. 🏥 Database Doctor & Query Optimizer
Run comprehensive health checks on connectivity, latency, unindexed foreign keys, and slow queries:
# Database health diagnostics:
db-agent doctor --db my_db
# EXPLAIN plan analysis & index recommendations:
db-agent optimize "SELECT * FROM events WHERE camera_id = 42" --db my_db
6. 📚 Business Semantic Dictionary & Query Templates
Teach DB-Agent your domain-specific metrics and definitions:
# Define a business metric:
db-agent define offline_camera "A camera with no heartbeat for > 2 minutes" --sql "last_heartbeat < NOW() - INTERVAL '2 mins'"
# List all definitions:
db-agent definitions
# Manage trusted SQL templates:
db-agent template list
7. 🎭 Sensitive Data Masking & RBAC
Automatically classifies columns into PII, Secrets, and Financial data, masking confidential values in outputs (s***@gmail.com, **********, ****-****-****-1234).
8. 📊 Automatic Visualization Detector
Detects when query results represent time series, category distributions, or single metrics, and renders ASCII/Unicode charts directly in your terminal.
📖 Complete CLI Command Reference
| Command | How to Use | Purpose |
|---|---|---|
ask |
db-agent ask "list top 10 users" --db my_db |
Natural language to SQL -> executes & renders table. |
chat |
db-agent chat --db my_db |
Interactive terminal copilot with multi-turn context. |
doctor |
db-agent doctor --db my_db |
Comprehensive database and AI health diagnostic check. |
path |
db-agent path users events --db my_db |
Shortest multi-hop foreign key join path discovery. |
explain-join |
db-agent explain-join customers orders |
Explains join relationship, cardinality, and syntax. |
optimize |
db-agent optimize "<SQL>" --db my_db |
Analyzes EXPLAIN plan and recommends indexes. |
scan |
db-agent scan --db my_db --export db.md |
Full database schema introspection & Markdown export. |
refresh-schema |
db-agent refresh-schema --db my_db |
Refreshes schema cache and reports detected diffs. |
schema-status |
db-agent schema-status --db my_db |
Displays schema cache age, version, and health. |
changes |
db-agent changes |
Lists recorded write ChangeSets. |
changes-show |
db-agent changes-show CS-20260828-001 |
Shows before/after snapshot of a ChangeSet. |
rollback |
db-agent rollback CS-20260828-001 |
Generates and executes inverse rollback SQL. |
define |
db-agent define revenue "SUM(order.amount)" |
Saves a business definition into the semantic layer. |
definitions |
db-agent definitions |
Lists all defined business terminology. |
template |
db-agent template list |
Manages reusable, parameterized query templates. |
audit |
db-agent audit |
Displays recent query execution audit log. |
connect |
db-agent connect <url> --alias my_db |
Tests connection and saves profile alias. |
use |
db-agent use gemini |
Switches default AI provider. |
run |
db-agent run "SELECT * FROM users" --db my_db |
Executes raw SQL query with Rich table output. |
generate |
db-agent generate "ETL script" --db my_db -o etl.py |
Generates Python ETL, Alembic migrations, or APIs. |
setup |
db-agent setup |
1-Click setup wizard for local or cloud AI. |
config |
db-agent config |
Interactive AI API keys and preferences wizard. |
profiles |
db-agent profiles |
Lists all saved database connection profiles. |
models |
db-agent models |
Status of local Ollama models and cloud AI providers. |
guide |
db-agent guide |
Displays full interactive command cheatsheet. |
💬 In-Chat REPL Commands (db-agent chat)
Inside the interactive chat shell, you can use built-in colon commands:
:doctor— Run database health diagnostics.:path <t1> <t2>— Discover shortest join path between tables.:join <t1> <t2>— Explain join cardinality and recommended join syntax.:mode <SAFE|CONFIRM|SANDBOX|ADMIN>— Switch safety mode mid-session.:changes— List recent write ChangeSets.:tables— List all database tables.:table <name>— Inspect columns, types, primary keys, and sample data.:fk <name>— View incoming and outgoing foreign keys.:provider <name>— Switch AI provider (ollama,gemini,groq,openrouter).:model <name>— Switch active model name on the fly.:explain— Show generated SQL and query analysis for the last turn.:history— View query history for the session.:auto/:noauto— Toggle automatic execution of read queries.:run— Re-execute the last generated SQL query.:clear— Clear multi-turn conversational context.:export <file>— Save the last generated SQL to a file.:exit— Exit chat session.
📄 License
MIT License. Built with ❤️ by Santhosh Gupta.
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file dbagent_cli-0.3.7.tar.gz.
File metadata
- Download URL: dbagent_cli-0.3.7.tar.gz
- Upload date:
- Size: 95.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/7.0.0 CPython/3.11.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c87cf8ffc602cc04e0320aad4c3d812bb4ed7fce9a60a7a35f94695a75e729d8
|
|
| MD5 |
1aa4a2c16ce591c16cab21dd5c8f1824
|
|
| BLAKE2b-256 |
30c84cccd99af368b2388d4d019721959747a34a2a500f41f1d819265e224d07
|
File details
Details for the file dbagent_cli-0.3.7-py3-none-any.whl.
File metadata
- Download URL: dbagent_cli-0.3.7-py3-none-any.whl
- Upload date:
- Size: 100.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/7.0.0 CPython/3.11.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5b66205caf024c158691f4fa6ffaa8f49cac588eaa7b72c7ce07fcf268f3df51
|
|
| MD5 |
84e7e85a328d18bef83b03599811764e
|
|
| BLAKE2b-256 |
637114b620ed0e44b2664a80a1482c583a5c62d133f8d90aadbd1833fd435b94
|