Chat with an SQLite auto-parts inventory in plain English. A LangChain agent
inspects the schema, writes SQL, runs it read-only and explains the result.
Follow-ups like "now only the ones under ₹500" work because the conversation
is stored per thread in chat_memory.db, so it also survives restarts.
python -m venv .venv
.venv\Scripts\Activate.ps1
pip install -r requirements.txt
copy .env.example .env # then paste your ANTHROPIC_API_KEY into .env
python seed_db.py # builds inventory.db with sample data
python main.pyCommands: /new starts a fresh conversation, /help shows tips, /quit exits.
The bot prints a [tool] line each time the agent calls a tool, so you can
watch the loop: list tables, describe, query, answer.
Try:
- Which brake parts are out of stock?
- Show Hyundai Creta parts under ₹3000
- Now only the ones from Bosch India
- Which supplier has the most stock value?
| File | Purpose |
|---|---|
seed_db.py |
Builds inventory.db (suppliers, vehicles, parts, fitment, stock) |
db.py |
Read-only connection, SELECT-only guard, 50-row cap |
tools.py |
list_tables, describe_table, run_query |
agent.py |
Model, system prompt, SQLite checkpointer, agent graph |
main.py |
CLI loop with streaming and /new, /help, /quit |
The database opens in read-only mode, only a single SELECT or WITH query
passes validation, and results are capped at 50 rows. Errors go back to the
agent as text so it can fix its SQL and retry.
Add DB_PATH=C:\path\to\your.db to .env. The agent discovers tables and
columns itself; you may want to adjust the prices and currency line in the
system prompt in agent.py.
greenletfails to build: use Python 3.12 (for exampleconda create -n sqlchat python=3.12), or runpip install --only-binary=:all: --upgrade greenletfirst.ImportErroroncreate_agent: harmless;agent.pyfalls back to LangGraph'screate_react_agentautomatically.- Weird characters instead of ₹: run
chcp 65001in the console first.