0% found this document useful (0 votes)
22 views47 pages

Building Database Agents

This course focuses on building AI agents that interact with tabular data and SQL databases, utilizing the OpenAI Assistants API. It is designed for entrepreneurs, developers, data professionals, and business analysts with a basic understanding of programming. The course includes theoretical concepts, hands-on projects, and covers the use of Langchain for creating agents that can process natural language queries into SQL commands.

Uploaded by

naguciti1973
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
22 views47 pages

Building Database Agents

This course focuses on building AI agents that interact with tabular data and SQL databases, utilizing the OpenAI Assistants API. It is designed for entrepreneurs, developers, data professionals, and business analysts with a basic understanding of programming. The course includes theoretical concepts, hands-on projects, and covers the use of Langchain for creating agents that can process natural language queries into SQL commands.

Uploaded by

naguciti1973
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 47

Who Am I?

Paulo Dichone

Software, Cloud, AI Engineer


and Instructor
What Is This Course About?

● Building Database (AI) Agents -


○ Develop AI agents that interact with tabular data and SQL Databases
○ Function calls
○ OpenAI Assistants API with SQL databases and AI Agents
Who Is This Course For

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

2. This is not a programming course


3. Willingness to learn :)
Course Structure

Theory (Fundamental Concepts)

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

Python (Win, Mac, Linux)

https://kinsta.com/knowledgebase/install-python/
● What is it?
AI Agent ● Why (motivation)?

Deep Dive ● Advantages


What is an (AI) agent?
Search the web

Agents
Query a SQL Database

Query
Interact with a CSV File

answer Call a tool…


What is an agent & what they can do?
Personalized recommendations
Browse history
Previous vacations and activities…

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

Customer service chatbots

Personal assistants

Data analysis

Smart home systems…


First Build your very first Agent
● We’ll use Langchain

Agent ● OpenAI model


LangChain
A framework (open source) for building applications that leverage various LLMs
(Large Language Models).
Additionally - you can also use external sources of data combined with various
LLMs!

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

Database ● Transform CSV file into SQL


database

Agent ● OpenAI model


● Langchain
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
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

What’s the weather like in Tokyo right now?

Step 1: OpenAI API


Call the model with functions and the user’s input

Step 2: Third party API


Use the model response to call your API

Step 3: OpenAI API


Send the response back to the model to summarize…

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

Leveraging the Assistants API for SQL DBs

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

● Assistants API extends the existing


OpenAI API
○ Easier to build AI assistants
○ Bots, AI tools, etc..
Assistants API
What Problem It Solves?
Assistants API Benefits
Building Complex AI Applications is very difficult!

Developers need to:


● Manage infrastructures
● Data
● Models
● Prompts
● Application state
● Embeddings,
● Storage mechanism
● …

Developers need to spend most of their time stitching


tech together, instead of actually solving customer
problems
Assistants API Benefits
● Persistent threading for ongoing conversations
○ Being able to save messages & context of the
conversation
● Retrieval mechanisms for digging through data
○ Upload files for the models to use for additional
knowledge-base
● Code Interpreter
○ Write, analyze code…
● Function calling to execute custom tasks with ease
Assistants API Benefits
OpenAI Models

Call with specific Tools


instructions
Code
Interpreter
Access multiple
Assistants Tools in parallel Knowledge
Retrieval
My Own tools
Function
Calling

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 Thread Run


(Travel agent bot) Trip to Paris Assistant: Travel agent bot
Thread: Trip to Paris

User’s message Steps:


What’s the cost for an extra 1. Use code interpreter
day in Paris? 2. Create Message
3. Call another tool…

Assistant’s message
The total cost will be $12,890.
Assistants API & Agents - Benefits

Code Interpreter & Function calling are supported in the


Assistants API
● Code interpreter - the assist. API can modify Python
code iteratively
● Useful for complex tasks (adjusting code until the
right result is generated)
Assistants API Benefits
OpenAI Models

Call with specific Tools


instructions
Code
Interpreter
Access multiple
Assistants Tools in parallel Knowledge
Retrieval
My Own tools
Function
Calling

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!

You might also like