Building Database Agents
Building Database Agents
Paulo Dichone
Open
minded
Entrepreneurs
learners :)
Project
Developers Managers
Data
Scientists
Data
Professionals
Business
Analysts
Course Prerequisites
1. Know Programming (highly preferred… at least the basics)
a. There will be Python code
Mixture of both
Hands-on
Development Environment setup
● Python
● VS Code (or any other code editor)
● OpenAI API Account and API Key
Set up OpenAI API Account
** Please note that you will need an API key to use OpenAI
services, and there may be some costs associated with using
the API. However, these costs should be minimal.
OpenAI API - Dev Environment Setup
https://kinsta.com/knowledgebase/install-python/
● What is it?
AI Agent ● Why (motivation)?
Agents
Query a SQL Database
Query
Interact with a CSV File
Tools
Agents API…
GoogleSearch
Wikipedia
…
What is an agent & what they can do?
SELECT * FROM
SQL
sales WHERE
DB
Agent date >=
“Show me the sales '2026-01-01' AND
data for the last quarter.” date <=
'2026-03-31'
Process results
Final result
Key characteristics
Autonomy
Learning and adaptation
Interaction
Goal-driven
Use cases
Personal assistants
Data analysis
General
Knowledge
…
Company … PDF
Action 2
Y
LangChain Database
Framework … Action to take… email
Actio
Your n 4…
Document
Build your very first Agent
First ● Computer scientist agent
● Interact with the agent
Agent ● Langchain
Interacting with CSV data
CSV ● Extract CSV file data
● OpenAI model
Agent ● Langchain
Interacting with tabular data (CSV)
Lang ChainAgent
Interacting with CSV data
● Extract CSV file data
CSV ● OpenAI model
● Langchain
Agent ○ Added custom prompts to
refine our CSV agent
Interacting with SQL Database
SELECT * FROM
SQL
sales WHERE
DB
Agent date >=
“Show me the sales '2026-01-01' AND
data for the last quarter.” date <=
'2026-03-31'
Process results
Final result
Interacting with SQL Database
● Transform CSV file into SQL
Database database
● OpenAI model
Agent ● Langchain
○ UI with streamlit
Agents Give agents more tools to work
with
Function calling
Agents and Function-calling
Function
calling
LangChain Agent
getAllIds()
getAverageSalary()
…
SQL
DB
Function-calling Benefits
● Task specialization
○ Provide specific instructions for finding information
needed
● Improved accuracy and efficiency
○ Prioritize queries for precise results & desired format
■ AI models can call predefined functions
● Security and control
○ Add control and encapsulate queries for better structure
and predictable behavior
○ Sensitive operations can be restricted to specific function,
enhancing security
Function-calling Deep dive
Model (LLM)
The weather in Tokyo is currently sunny with a temperature of 23 degrees Celsius
Function Calling Hands on
OpenAI Leveraging OpenAI Function
calling with SQL Database
Function calling
Function Calling Hands on - DB Agent
OpenAI Assistants API & SQL Databases
Assistants API
SQL
DB
Assistants API
What is it & How it works?
Assistants API
A tool to allow developers to craft powerful
AI assistants that can perform a variety of
tasks.
Assistants
API OpenAI API
Persistent
Threads
Access Files
(several formats)
The Chat Completion API
OpenAI Models
OpenAI
LLMs
Completion & Response
API Knowledge
base
General Comparison
Assistants API Building Blocks
Assistant’s message
The total cost will be $12,890.
Assistants API & Agents - Benefits
Persistent
Threads
Access Files
(several formats)
Hands on
You made it to the end!
Congratulations! ● Next steps…
Course Summary
● Building Database (AI) Agents
○ Agents deep dive
○ Key characteristics
○ Agent use cases
○ Deep dive into Building Database Agents
■ Built first simple Agent (using Langchain framework)
■ Agents that interact with CSV, tabular data
■ Agents that interact with SQL databases
● Agents take natural language queries and transform into
SQL to interact with DB
○ Function calls (OpenAI) overview
○ Function calls and database agents
○ Leveraging the Assistants API for SQL DBs and Agents
Wrap up - Where to Go From Here?
● Keep learning
○ Extend the projects we worked on in this course
○ Implement your own SQL database
● Read more on Lanchain-
https://python.langchain.com/v0.2/docs/tutorials/agents/
● Read the OpenAI documentation:
https://platform.openai.com/docs/overview
● Challenge yourself to keep learning new skills!
Thank you!