This project is an Azure Functions app (Python Programming Model v2) exposing a single HTTP endpoint that:
- Accepts a
user_inputprompt. - Runs an agent (OpenAI Agents SDK) which can call a Databricks SQL tool.
- Returns a JSON response with the final output.
function_app.py: Function definitions, agent setup, Databricks tool.requirements.txt: Python dependencies.local.settings.json: Local-only app settings (not deployed).data/team_stats_data_model.json: Bundled JSON used in agent instructions.openapi.yaml: OpenAPI 3.1.0 spec for/api/agent_invoke(GET documented).
- Python 3.10 or 3.11
- Azure Functions Core Tools v4
- Azure CLI
cd /Users/vince/dev_projects/azure/agent_functionapp
python -m venv .venv
source .venv/bin/activate
pip install -r requirements.txt
func startEdit local.settings.json (values are examples; do not commit secrets):
{
"IsEncrypted": false,
"Values": {
"AzureWebJobsStorage": "UseDevelopmentStorage=true",
"FUNCTIONS_WORKER_RUNTIME": "python",
"DATABRICKS_HOST": "https://<your-databricks-workspace-host>",
"DATABRICKS_TOKEN": "<your-personal-access-token>",
"DATABRICKS_WAREHOUSE_ID": "<optional-warehouse-id>"
}
}- GET
curl "http://localhost:7071/api/agent_invoke?user_input=Hello"- POST
curl -X POST http://localhost:7071/api/agent_invoke \
-H "Content-Type: application/json" \
-d '{"user_input":"Use query_databricks to run: SELECT 1 AS x"}'Responses
{
"last_agent": "Assistant",
"final_output": "..."
}On error (centralized error handling):
{
"error": "Function execution failed",
"message": "<exception message>"
}The tool uses the SQL Statements REST API with INLINE + JSON_ARRAY results. Ensure these app settings are set locally (above) and in Azure (see Deploy below):
DATABRICKS_HOST(e.g.,https://dbc-xxxx.cloud.databricks.com)DATABRICKS_TOKEN(Databricks PAT)DATABRICKS_WAREHOUSE_ID(optional; recommended)
data/team_stats_data_model.json is packaged with the app and read at import time to inform the agent. Place your own JSON under data/ and load it via a module-scope read for best cold-start performance.
- File:
openapi.yaml(OpenAPI 3.1.0) - Documents the GET
/api/agent_invokeendpoint. Import it into Swagger UI/Postman. - You can extend it to include the POST body schema if desired.
az login
az account set --subscription "<SUBSCRIPTION>"
RESOURCE_GROUP="rg-agent-func"
LOCATION="eastus"
APP_NAME="agent-func-$RANDOM" # must be globally unique
STORAGE_ACCOUNT="stagent$RANDOM" # must be globally unique
az group create --name $RESOURCE_GROUP --location $LOCATION
az storage account create --name $STORAGE_ACCOUNT --resource-group $RESOURCE_GROUP --location $LOCATION --sku Standard_LRS
az functionapp create \
--resource-group $RESOURCE_GROUP \
--consumption-plan-location $LOCATION \
--name $APP_NAME \
--storage-account $STORAGE_ACCOUNT \
--functions-version 4 \
--runtime python \
--runtime-version 3.11 \
--os-type Linux
# App settings (set secrets here, not in code)
az functionapp config appsettings set \
--name $APP_NAME \
--resource-group $RESOURCE_GROUP \
--settings \
DATABRICKS_HOST="https://<your-databricks-host>" \
DATABRICKS_TOKEN="<your-pat>" \
DATABRICKS_WAREHOUSE_ID="<your-warehouse>"
# Publish from project folder
cd /Users/vince/dev_projects/azure/agent_functionapp
func azure functionapp publish $APP_NAME --python
# Invoke
curl "https://$APP_NAME.azurewebsites.net/api/agent_invoke?user_input=Hello"az functionapp cors add --resource-group $RESOURCE_GROUP --name $APP_NAME --allowed-origins https://portal.azure.com https://ms.portal.azure.com
# Optionally your app origins
az functionapp cors add --resource-group $RESOURCE_GROUP --name $APP_NAME --allowed-origins http://localhost:3000- Module not found
agents: ensure you start the host from the venv and dependencies are installed.source .venv/bin/activate pip install -r requirements.txt python -c "import agents; print(agents.__file__)" func start
- Malformed input / 400: send
user_inputeither as?user_input=...or{ "user_input": "..." }JSON body. - 500 with JSON error: check
az webapp log tail --resource-group $RESOURCE_GROUP --name $APP_NAMEand your app settings. - Do not commit secrets in code or in
local.settings.json. Use Azure App Settings; rotate any exposed tokens.