--- title: Build AI Agent Text-to-SQL emoji: 🗣️ colorFrom: green colorTo: blue sdk: static pinned: false app_file: index.html --- ## Build AI Agent Text-to-SQL 🗣️ **Text-to-SQL AI Agent** A demonstration project for building an intelligent agent that translates natural language queries into SQL, executes them, and returns results using [smolagents](https://github.com/smol-ai/smol-agent), [SQLAlchemy](https://www.sqlalchemy.org/), and [python-dotenv](https://pypi.org/project/python-dotenv/). --- ## Features - Converts plain English questions into SQL queries. - Executes queries on an in-memory SQLite database. - Supports multiple tables and table joins. - Uses LLMs for advanced query understanding. - Easily extensible for new tables and schemas. ## Installation ````bash git clone https://github.com/your-username/txt-to-sql-agent.git cd txt-to-sql-agent pip install -r requirements.txt ```plaintext ## Usage Edit `text_to_sql.py` to define your tables and sample data. Run the agent: ```bash python text_to_sql.py ```` ## Example Ask the agent: > "Which waiter received the highest total amount in tips?" The agent will generate and execute the appropriate SQL query, returning the answer. ## Project Structure ```text . ├── README.md ├── text_to_sql.py ├── index.html ``` ## How It Works - Defines tables (`receipts`, `waiters`) using SQLAlchemy. - Loads sample data into an in-memory SQLite database. - Uses smolagents to create a CodeAgent with SQL querying tools. - The agent interprets natural language and generates SQL queries. - Results are printed to the console. ## Contributing Pull requests and suggestions are welcome! Please open an issue for bugs or feature requests. ## License [![License](https://img.shields.io/badge/Apache--2.0-green?style=for-the-badge)](https://opensource.org/licenses/Apache-2.0) --- [![HF Space](https://img.shields.io/badge/-HuggingFace-FDEE21?style=for-the-badge&logo=HuggingFace&logoColor=black)](https://huggingface.co/spaces/dev-jas/text-to-sql-smolagent)