Skip to main content

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

sqlagent_community-0.1.1.tar.gz (16.1 kB view details)

Uploaded Source

Built Distribution

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

sqlagent_community-0.1.1-py3-none-any.whl (20.3 kB view details)

Uploaded Python 3

File details

Details for the file sqlagent_community-0.1.1.tar.gz.

File metadata

  • Download URL: sqlagent_community-0.1.1.tar.gz
  • Upload date:
  • Size: 16.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.11

File hashes

Hashes for sqlagent_community-0.1.1.tar.gz
Algorithm Hash digest
SHA256 0496dd4565ca053f09d0a9eeddab9ea64ba105e12e431288bf40fcc2f8759dfd
MD5 6220538e4cea62bc6f663d9700aa53f7
BLAKE2b-256 1db220064ef5187cc285992817a38f5c4f462a2a92f4c103819c2e7d22e941ef

See more details on using hashes here.

File details

Details for the file sqlagent_community-0.1.1-py3-none-any.whl.

File metadata

File hashes

Hashes for sqlagent_community-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 7b815fb5fb73bab5bf9251da86c63d85a4c6255f48c088c9b28537e3629bc163
MD5 498cc3a4bcaf6962bb48df0be3710ad6
BLAKE2b-256 e7192de8d045119664af65036fcfab4a6b352fbbb136163f029c16a8a2e9c54c

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page