Skip to content

kumar-selvakumaran/minimal_db_agent

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

minimal-db-agent

A minimal Python agent that uses LLMs to answer questions about an unknown SQLite database at inference time, leveraging ReAct-style reasoning and SQL queries.

Features

  • Uses OpenRouter-hosted LLMs via LangChain for natural language understanding.
  • Profiles and queries any SQLite database without prior schema knowledge.
  • Implements a ReAct agent with tool support for SQL querying.
  • Returns both natural language answers and the SQL used to derive them.
  • Designed for extensibility and clarity.

Structure

  • core/
    • agent.py: ReAct agent creation and invocation logic.
    • model.py: LLM wrapper and model loader.
    • tools.py: SQL query tool for database interaction.
    • system_prompt.txt: Agent instructions and behavior specification.
  • data/db.sqlite: Store your SQLite database.
  • demo.py: Example script to run the agent on a sample question.
  • secrets/.env: Stores API keys (e.g., OPENROUTER_API_KEY).

Installation

  1. Python 3.11+ required
  2. Install dependencies:
    pip install -r requirements.txt
  3. Add your OpenRouter API key to secrets/.env:
    OPENROUTER_API_KEY=your-key-here
    

Usage

Run the demo script:

python demo.py

The agent will connect to data/db.sqlite, profile the database, and answer the question:
“What is the database about?”

Customization

  • Replace data/db.sqlite with your own SQLite database.
  • Modify core/system_prompt.txt to change agent behavior.
  • Extend core/tools.py to add more tools.

Requirements

  • Python 3.11+
  • langchain-openai, langgraph, sqlalchemy, dotenv

About

A minimal Python agent that uses LLMs to answer questions about an unknown SQLite database at inference time, leveraging ReAct-style reasoning and SQL queries.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages