Thoughts on Machine Learning

Explore the world of AI with ‘Thoughts on Machine Learning’: a high-quality blog offering in-depth…

Follow publication

Member-only story

Build a Text-to-SQL Agent Using the SmolAgents Library

FS Ndzomga
Thoughts on Machine Learning
4 min readMar 6, 2025

--

I recently started experimenting with the SmolAgents library from Hugging Face.

It is a nice library for building powerful AI agents quickly.

I created a course for it:

In the course, I go into detail about the core abstractions of the smolagents library and explain everything with practical examples.

In this tutorial, I am going to quickly present how to build a text-to-SQL agent using smolagents.

The setup is simple.

I am going to use a fake SQLite database, feed some employee data, then create an AI agent that runs SQL queries on the database to reply to user queries.

Here is how to set up the database:

import os
import sqlite3
from smolagents import Tool, ToolCallingAgent, LiteLLMModel, GradioUI
from dotenv import load_dotenv

load_dotenv()

# ----- Step 1: Build an Enhanced SQLite Database -----
db_file = "fake_db.sqlite"
conn = sqlite3.connect(db_file)
cursor = conn.cursor()

# Create an enhanced…

--

--

Thoughts on Machine Learning
Thoughts on Machine Learning

Published in Thoughts on Machine Learning

Explore the world of AI with ‘Thoughts on Machine Learning’: a high-quality blog offering in-depth tutorials and insights on AI startups. Ditch the hit-or-miss content of Medium for expert, well-researched articles that enlighten and inspire.

FS Ndzomga
FS Ndzomga

Written by FS Ndzomga

Engineer passionate about data science, startups, philosophy and French literature. Built lycee.ai, discute.co and rimbaud.ai . Open for consulting gigs

No responses yet

Write a response