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.
- 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.
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).
- Python 3.11+ required
- Install dependencies:
pip install -r requirements.txt - Add your OpenRouter API key to
secrets/.env:OPENROUTER_API_KEY=your-key-here
Run the demo script:
python demo.pyThe agent will connect to data/db.sqlite, profile the database, and answer the question:
“What is the database about?”
- Replace
data/db.sqlitewith your own SQLite database. - Modify
core/system_prompt.txtto change agent behavior. - Extend
core/tools.pyto add more tools.
- Python 3.11+
langchain-openai,langgraph,sqlalchemy,dotenv