Skip to main content

⚡ DB-Agent (dbagent-cli)

Enterprise AI Database Copilot, Schema Graph Introspector & Autonomous Recovery Agent
Author: Santhosh Gupta | 100% Free, Standalone, Works 100% Offline (Ollama) or with High-Speed Cloud AI (Gemini / Groq / OpenRouter).

PyPI Version Python Versions License: MIT Database Support


🌟 What is DB-Agent?

DB-Agent (dbagent-cli) is an enterprise-grade, privacy-first AI Database Copilot. Designed for developers, DBAs, data engineers, and analysts, it transforms plain English prompts into highly optimized, dialect-precise SQL, executes queries under strict safety guardrails, and renders crystal-clear data visualizations.

🚀 Key Highlights:

  • Instant On-Demand Introspection: Targeted single-query metadata resolution (< 30ms) across databases with 300+ tables.
  • Interactive Data Grid Suite: Native desktop GUI window (:window), browser virtual grid (:web), column paging (:page), and responsive zoom-out (:wide).
  • Long-Term Post-Commit Rollback: Pluggable recovery engine that snapshots pre-write row states, detects concurrency conflicts, and allows safe revert hours or days after COMMIT.
  • Multi-Hop Join Discovery: Automatically computes the shortest foreign-key join paths between disconnected tables.
  • Enterprise Safety Guardrails: 5 operational modes (SAFE, READ_ONLY, CONFIRM, SANDBOX, ADMIN), PII masking, and destructive query protection.
  • Zero-Cost Local or Cloud AI: Native support for Google Gemini (gemini-3.6-flash), Local Ollama (100% offline), Groq, and OpenRouter.

📦 Installation

Install dbagent-cli via pip:

# Recommended: Install with all database drivers
pip install --upgrade "dbagent-cli[all]"

Optional Driver Extras:

pip install "dbagent-cli[postgres]"   # PostgreSQL (psycopg2-binary, asyncpg)
pip install "dbagent-cli[mysql]"      # MySQL & MariaDB (pymysql, cryptography)
pip install "dbagent-cli[mongo]"      # MongoDB (pymongo)
pip install "dbagent-cli[duckdb]"     # DuckDB (duckdb, duckdb-engine)
pip install "dbagent-cli[mssql]"      # Microsoft SQL Server (pyodbc)
pip install "dbagent-cli[oracle]"     # Oracle Database (oracledb)

⚡ 2-Minute Quickstart

1. Configure AI Provider

db-agent setup

Follow the interactive prompt to choose your preferred AI backend:

  • Google Gemini (Recommended Cloud): Ultra-fast inference with free tier (gemini-3.6-flash).
  • Local Ollama (Recommended Offline): 100% private, runs entirely on your GPU/CPU with 0 API keys.
  • Groq / OpenRouter: Fast open-weights inference (Llama 3.3, Qwen 2.5 Coder).

2. Connect Database & Save Profile Alias

db-agent connect postgresql://user:pass@localhost:5432/mydb --alias my_db

(Supports PostgreSQL, MySQL, SQLite, MSSQL, Oracle, DuckDB, and MongoDB).

3. Ask Plain English Questions or Start Interactive Chat

# Ask a one-off question:
db-agent ask "list top 10 most recent active users" --db my_db

# Launch the interactive AI shell:
db-agent chat --db my_db

🪟 Interactive Viewing & Multi-Column Scroller Suite

When working with wide enterprise tables containing 20, 40, or 60+ columns, DB-Agent provides 5 flexible viewing modes:

View Mode In-Chat Command Description
Desktop GUI Grid :window / :grid Opens a native desktop window with ↔️ horizontal & ↕️ vertical scrollbars, live search/filter, and CSV export.
Browser Data Table :web / :browser Generates a standalone virtual data grid and opens it in your default browser.
Column Paging :page <n> Browse wide columns in clean horizontal chunks (:page 1, :page 2, :page 3).
Vertical Card View :card / :v Displays every row as an expanded vertical record card with all columns cleanly listed.
Responsive Zoom-Out :wide Dynamically auto-scales column count to fill wide or zoomed-out (Ctrl + -) terminal windows.

🛡️ Enterprise Long-Term Rollback & Recovery Engine

Unlike standard transaction rollbacks that only protect uncommitted sessions, DB-Agent includes a Post-Commit Long-Term Recovery Engine:

User: Update all inactive users to ACTIVE where last_login < '2025-01-01'
AI:   Modifying 42 rows. Capturing pre-write snapshot...
      Change committed successfully.
      Change ID: CS-20260828-001 (Recovery available for 30 days)

... 5 days later ...

User: db-agent rollback CS-20260828-001 --db my_db
AI:   Verifying live data checksums... No concurrency conflicts detected.
      Inverse UPDATE executed successfully. 42 rows restored!

Recovery CLI Commands:

# List all recorded write ChangeSets:
db-agent changes

# Inspect before/after row snapshots of a change:
db-agent changes-show CS-20260828-001

# Preview rollback SQL without executing:
db-agent rollback CS-20260828-001 --preview

# Execute rollback with conflict safety:
db-agent rollback CS-20260828-001 --conflict-policy abort

# Roll back the most recent change:
db-agent rollback --last

# Manage recovery storage retention:
db-agent recovery status
db-agent recovery cleanup --older-than-days 30

🔒 Production Safety Guardrails & Operational Modes

DB-Agent provides 5 strictly enforced operational safety modes:

  • SAFE: Only read-only queries (SELECT, SHOW, DESCRIBE, EXPLAIN, WITH) allowed. All writes and DDL are blocked.
  • READ_ONLY: Enforced on PRODUCTION environments with query execution timeouts and row limits.
  • CONFIRM (Default): Read queries execute automatically; write (UPDATE, INSERT, DELETE) and DDL (ALTER, DROP) operations require user confirmation.
  • SANDBOX: Executes writes within an uncommitted transaction to generate before/after diffs without modifying live data.
  • ADMIN: Full administrative execution with audit tracking.

Sensitive Data Masking:

Confidential fields (emails, passwords, API tokens, credit cards) are automatically masked in console outputs: a***@motivitylabs.com, **********, ****-****-****-1234.


🧠 Schema Graph & Multi-Hop JOIN Discovery

DB-Agent builds an in-memory directed graph of foreign-key relationships across your database schema:

# Discover shortest foreign-key path between disconnected tables:
db-agent path ivis_user ivis_camera_mapping --db my_db

# Explain join cardinality (1:1, 1:N) and recommended syntax:
db-agent explain-join customers orders --db my_db

🏥 Database Doctor & Query Diagnostics

Run comprehensive database health checks and EXPLAIN plan optimizations:

# Full connectivity, latency, index, and table health diagnostics:
db-agent doctor --db my_db

# Analyze query execution plan and recommend missing indexes:
db-agent optimize "SELECT * FROM ivis_user WHERE email = 'test@example.com'" --db my_db

📚 Business Semantic Dictionary

Teach DB-Agent your domain-specific metrics and shorthand:

# Define a business metric:
db-agent define active_user "A user who logged in within the last 30 days" --sql "last_login >= NOW() - INTERVAL '30 days'"

# List all saved business terminology:
db-agent definitions

# Manage parameterized query templates:
db-agent template list

📖 Complete CLI Command Reference

Command Usage Description
ask db-agent ask "<prompt>" --db <alias> Translates natural language to SQL, executes query, and renders table.
chat db-agent chat --db <alias> Launches interactive multi-turn AI copilot shell.
doctor db-agent doctor --db <alias> Runs database health, connectivity, and index diagnostics.
path db-agent path <t1> <t2> --db <alias> Discovers shortest multi-hop foreign-key join path.
explain-join db-agent explain-join <t1> <t2> Explains join relationship, cardinality, and syntax.
optimize db-agent optimize "<SQL>" --db <alias> Analyzes EXPLAIN plan and recommends performance indexes.
scan db-agent scan --db <alias> -o schema.md Full database introspection and Markdown catalog export.
refresh-schema db-agent refresh-schema --db <alias> Refreshes schema cache and reports detected diffs.
schema-status db-agent schema-status --db <alias> Displays schema cache age, version, and health.
changes db-agent changes Lists recorded write ChangeSets.
changes-show db-agent changes-show <id> Shows before/after snapshot of a ChangeSet.
rollback db-agent rollback <id> [--preview] [--last] Generates and executes inverse rollback SQL.
recovery db-agent recovery [list|status|cleanup] Manages snapshot storage and retention policies.
define db-agent define <term> "<desc>" --sql "<sql>" Saves business terminology into semantic dictionary.
definitions db-agent definitions Lists all defined business terminology.
template db-agent template [list|add|run] Manages reusable, parameterized query templates.
audit db-agent audit Displays recent query execution audit log.
connect db-agent connect <url> --alias <name> Tests database connection and saves profile.
profiles db-agent profiles Lists all configured database profiles.
use db-agent use <provider> Switches active AI provider (gemini, ollama, groq, openrouter).
models db-agent models Status of local Ollama models and cloud AI providers.
setup db-agent setup 1-Click AI configuration setup wizard.
config db-agent config Interactive AI API keys and preferences wizard.
guide db-agent guide Displays full interactive command cheatsheet.

💬 In-Chat Colon Commands (db-agent chat)

Inside the interactive chat REPL, use these colon commands:

  :window                     -> Open native desktop GUI data grid with horizontal & vertical scrollbars
  :web                        -> Open interactive browser data table with virtual scrolling
  :page <n>                   -> View column page <n> for wide tables (e.g. :page 1, :page 2)
  :card                       -> View last result in expanded vertical card format (all columns)
  :wide                       -> Render all columns across expanded / zoomed-out terminal
  :scroll                     -> Interactive terminal column scroller
  :tables                     -> List all tables in this database
  :table <name>               -> Inspect columns, PKs, types & sample data
  :fk <name>                  -> View mapped foreign keys & related tables
  :path <t1> <t2>             -> Discover shortest join path between tables
  :join <t1> <t2>             -> Explain join cardinality & syntax
  :doctor                     -> Run database health diagnostics
  :mode <name>                -> Switch mode (SAFE, READ_ONLY, CONFIRM, SANDBOX, ADMIN)
  :changes                    -> List recent write ChangeSets
  :provider <name>            -> Switch AI provider (gemini, ollama, groq, openrouter)
  :model <name>               -> Switch active model name (e.g. gemini-3.6-flash)
  :models                     -> Show active AI provider and model status
  :explain                    -> Show generated SQL & query analysis for last turn
  :history                    -> View history of queries in this session
  :auto / :noauto             -> Toggle automatic execution of read queries
  :run                        -> Re-execute the last generated SQL query
  :clear                      -> Clear conversation 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

dbagent_cli-0.9.4.tar.gz (125.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

dbagent_cli-0.9.4-py3-none-any.whl (132.8 kB view details)

Uploaded Python 3

File details

Details for the file dbagent_cli-0.9.4.tar.gz.

File metadata

  • Download URL: dbagent_cli-0.9.4.tar.gz
  • Upload date:
  • Size: 125.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.11.0

File hashes

Hashes for dbagent_cli-0.9.4.tar.gz
Algorithm Hash digest
SHA256 0f1919030b81302ed22e94c762cdcfdc78043a189b9683679bf6d3678c67306a
MD5 6bfce7c5daf2cf772ba74ab9aa99d5b0
BLAKE2b-256 29e9f11b052a55f5110c1da4a55504ce08eda5f0ddb24bfadc580db60745b1bd

See more details on using hashes here.

File details

Details for the file dbagent_cli-0.9.4-py3-none-any.whl.

File metadata

  • Download URL: dbagent_cli-0.9.4-py3-none-any.whl
  • Upload date:
  • Size: 132.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.11.0

File hashes

Hashes for dbagent_cli-0.9.4-py3-none-any.whl
Algorithm Hash digest
SHA256 ffba3dfcaaebf6a6a729eb6fc02511878caaa04c24f1c99034a5ec353450578a
MD5 1b4dd7115fbcec897c8a004c1c73938d
BLAKE2b-256 5a490ef123746d4565c90a7b92841f057eb39227476feab9e8d900cde60347d3

See more details on using hashes here.

Release history Release notifications | RSS feed

0.11.1

2 files

0.11.0

2 files

0.10.0

2 files

0.9.9

2 files

0.9.8

2 files

0.9.7

2 files

0.9.6

2 files

0.9.5

2 files

This release

0.9.4 This release

2 files

0.9.3

2 files

0.9.2

2 files

0.9.1

2 files

0.9.0

2 files

0.8.9

2 files

0.8.8

2 files

0.8.7

2 files

0.8.6

2 files

0.8.5

2 files

0.8.4

2 files

0.8.3

2 files

0.8.2

2 files

0.8.1

2 files

0.8.0

2 files

0.7.3

2 files

0.7.2

2 files

0.7.1

2 files

0.7.0

2 files

0.6.1

2 files

0.6.0

2 files

0.5.2

2 files

0.5.1

2 files

0.5.0

2 files

0.4.1

2 files

0.4.0

2 files

0.3.9

2 files

0.3.8

2 files

0.3.7

2 files

0.3.6

2 files

0.3.5

2 files

0.3.4

2 files

0.3.3

2 files

0.3.2

2 files

0.3.1

2 files

0.3.0

2 files

0.2.2

2 files

0.2.1

2 files

0.2.0

2 files

0.1.9

2 files

0.1.8

2 files

0.1.7

2 files

0.1.6

2 files

0.1.5

2 files

0.1.4

2 files

0.1.3

2 files

0.1.2

2 files

0.1.1

2 files

0.1.0

2 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page