- Load a SQLite database (sample or your own)
- Auto-detect the schema and define a SQL tool for Mercury 2
- Translate natural language questions into SQL using tool calling
- Execute queries and return natural language answers
- Measure end-to-end latency at each step
Run the SQL Agent
Directly via Google Colab or download the .ipynb to run it locally in Jupyter
Download Sample Database
Download the sample e-commerce SQLite database to use with the notebook.
Dependencies
Install packages and import the libraries required for the Mercury 2 API and SQLite:API Keys
Set up your Inception Labs API key.- Create a
.envfile in this directory - Add your API key to the
.env:INCEPTION_API_KEY
.env file.
Initialize Client
Initialize the Inception (Mercury 2) client:Load Database
We create a small in-memory e-commerce database with three tables —customers, products, and orders. If you want to use your own SQLite database instead, replace this cell with db = sqlite3.connect("your_file.db").
Inspect Schema
We introspect the schema directly from the database, so the tool calling setup automatically adapts to whatever tables are loaded:Define the SQL Tool
We define a single tool —run_sql_query — that Mercury 2 can call to execute SQL against our database. The tool description includes the auto-detected schema so Mercury knows what tables and columns are available:
Query Helper
This function handles the full tool-calling loop:- Send the user’s natural language question to Mercury 2 with the tool definition
- Mercury generates a
run_sql_querytool call with SQL - We execute the SQL and send results back to Mercury
- Mercury returns a natural language answer