# Deploy a Text-to-SQL AI Agent on Databricks Apps

Deploy the open-source db-agent to Databricks Apps over a built-in sample dataset. The lab then asks a test question through the live app to confirm it works.

- Level: Beginner
- Duration: About 20 min
- Cost: Free tier
- Technologies: Text-to-SQL, AI agents, Databricks Apps, Unity Catalog, SQL warehouse

## What you will build

- A text-to-SQL agent running as a Databricks App in your own workspace
- A connection to the built-in samples catalog, so nothing is downloaded
- A revocable app token stored as a secret
- A verified end-to-end test question

## Prerequisites

- A Databricks workspace (Free Edition works)
- The Databricks CLI, logged in with databricks auth login
- Python 3.9 or newer with pip
- git installed

## Run it

```bash
pip install 'labagent[rag]'
databricks auth login
labagent launch db-agent --name demo --param dataset=bakehouse
labagent destroy db-agent --name demo
```

## Steps

1. Preflight: Check your login, SQL warehouse, sample data and serving endpoints.
2. Fetch db-agent: Clone the app at a pinned commit so you run the code that was reviewed.
3. Create the app token: Make a revocable token and store it as a secret.
4. Deploy the app: Publish the Databricks App.
5. Verify: Ask a test question through the deployed app.

## FAQ

### Which data does the agent query?

The samples catalog every Databricks workspace has. The default dataset is bakehouse. You can pass another, such as tpch, nyctaxi or tpcds_sf1.

### Does labagent copy the db-agent code?

No. It clones db-agent at a pinned commit and deploys it to your workspace.

### What happens to the access token when I remove the lab?

The destroy command revokes the app token and deletes its secret scope.

### Does this lab cost money?

It runs on Databricks Free Edition. Free Edition allows three apps, and apps stop after 24 hours.

## Next steps

- Lab page: https://becloudready.com/labs/catalog/db-agent
- Private environments for your team: https://becloudready.com/labs/teams
- Corporate workshops: https://becloudready.com/workshops
