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.2.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.2-py3-none-any.whl (20.3 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: sqlagent_community-0.1.2.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.2.tar.gz
Algorithm Hash digest
SHA256 50190b222dedd9b0df0cbf9ac3d6543fa21d5bbbc60540e559da827a1762e285
MD5 0be7909fc674b10ccf1bc6cb88593ac3
BLAKE2b-256 6139f7c3b7cfc32186999299fb1d875c5f7424c9e67019e6248a0f521cbc7b56

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for sqlagent_community-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 d379b4432da1d1f0a8774bc35d0504381071831190d0aece170812c38a282239
MD5 fc86591679eafe9be31e75d835013d70
BLAKE2b-256 688812efcf061cc3a03ea65799b892c1433798aeb93eb55792a4a19a2d1ca895

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