Conversational Text-to-SQL agent that allows you to ask natural language questions over structured data (Excel → SQLite), using semantic search, automatic SQL generation, safe execution, and LLM-based result interpretation — all with conversation memory and SQL history.
Project description
SQLAgent Community
SQLAgent Community is a Python library for creating intelligent agents that can query SQLite databases using LLMs, generate SQL from natural language, and maintain conversation memory. Ideal for exploratory data analysis, conversational dashboards, or automating complex queries.
Requirements
- Python >= 3.10
- SQLite
- Ollama installed and configured
- Ollama provides the LLM and embedding models used by SQLAgent
- Pandas (for reading Excel files)
- Rich (optional, for nice logs)
Installation
You can install via pip (once published on PyPI):
pip install sqlagent-community
Configuration
Suggested file structure
dataset/
├─ data.db # SQLite database
├─ excels/ # Excel files to build the DB
vector_db/
├─ schema_embeddings.pkl # Schema embeddings
context/
├─ file.md # Additional context for the agent
Initialize Builder and database
from sqlagent_community.Builder import SQLBuilder
builder = SQLBuilder(
excel_dir="dataset/excels",
db_file="dataset/data.db",
embed_file="vector_db/schema_embeddings.pkl",
embed_model="qwen3-embedding:0.6b",
verbose=True
)
builder.build()
Set up Chat and Memory
from sqlagent_community.memory.ChatManager import ChatManager
from sqlagent_community.memory.ConversationSummaryBufferMemory import ConversationSummaryBufferMemory
manager = ChatManager()
chat_id = manager.create_chat()
memory = ConversationSummaryBufferMemory(chat_id=chat_id)
Initialize the Agent
from sqlagent_community.Agent import SQLAgent
agent = SQLAgent(
db_path="dataset/data.db",
embed_file="vector_db/schema_embeddings.pkl",
embedding_model="qwen3-embedding:0.6b",
llm_model="qwen2.5:7b",
text2sql="qwen2.5-coder:7b",
memory=memory,
context="./context/file.md",
verbose=True
)
Asking questions to the agent
question = "What is the average altitude per municipality of the collections?"
result = agent.run(question)
print(result)
The agent converts the question into SQL, executes it on the database, and returns the result, while maintaining conversation history and context.
Features
- Automatic SQLite database construction from Excel files.
- SQL generation via LLM from natural language.
- Summarized conversational memory per chat.
- Additional context from Markdown files.
- Detailed logs for debugging.
License
MIT License – see the LICENSE file for details.
Project details
Release history Release notifications | RSS feed
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 sqlagent_community-0.1.3.tar.gz.
File metadata
- Download URL: sqlagent_community-0.1.3.tar.gz
- Upload date:
- Size: 16.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.10.11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
74ac91fa3483897a915bc90ff54198c1f662e3e07c5ab007760c96a653738f2c
|
|
| MD5 |
0984a0cce8be9879ea6af61424008fd8
|
|
| BLAKE2b-256 |
41d567c0b6400bc4034482d094f521e937939351b6d2e59654373645cd993b19
|
File details
Details for the file sqlagent_community-0.1.3-py3-none-any.whl.
File metadata
- Download URL: sqlagent_community-0.1.3-py3-none-any.whl
- Upload date:
- Size: 20.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.10.11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e8a3354c4d32b4d73cd72b1579df7eb1e91ed036b1ae7e6ee11b606372afed1d
|
|
| MD5 |
03c2f81bf649388c96aa84d129c89527
|
|
| BLAKE2b-256 |
4e1e595028291568c7ce0255bf7ce811d7eddd36a7e19fdf5cde9bf9184bb692
|