diff --git a/.nextchanges/bundles/genie_agents.md b/.nextchanges/bundles/genie_agents.md new file mode 100644 index 00000000000..55b7bade691 --- /dev/null +++ b/.nextchanges/bundles/genie_agents.md @@ -0,0 +1 @@ +* Add the `genie_agents` resource for managing AI/BI Genie agents on the direct deployment engine. ([#7617](https://github.com/databricks/cli/pull/7617)) diff --git a/acceptance/bundle/deployment/bind/genie_agent/databricks.yml.tmpl b/acceptance/bundle/deployment/bind/genie_agent/databricks.yml.tmpl new file mode 100644 index 00000000000..93c16f1ef3c --- /dev/null +++ b/acceptance/bundle/deployment/bind/genie_agent/databricks.yml.tmpl @@ -0,0 +1,17 @@ +bundle: + name: test-bundle + +resources: + genie_agents: + agent1: + genie_agent_id: "01f0a1b2c3d4e5f60718293a4b5c6d7e" + display_name: bound-agent + warehouse_id: test-warehouse-id + # Matches the folder the out-of-band create below defaults to, so the + # plan right after bind is clean (no parent_path move). + parent_path: /Users/$CURRENT_USER_NAME + definition: + config: + sample_questions: + - id: "01f0a1b2c3d4e5f60718293a4b5c6d7f" + question: What was the average trip distance last month? diff --git a/acceptance/bundle/deployment/bind/genie_agent/out.test.toml b/acceptance/bundle/deployment/bind/genie_agent/out.test.toml new file mode 100644 index 00000000000..a927a5fbc06 --- /dev/null +++ b/acceptance/bundle/deployment/bind/genie_agent/out.test.toml @@ -0,0 +1,2 @@ +Cloud = false +EnvMatrix.DMS = ["", "true"] diff --git a/acceptance/bundle/deployment/bind/genie_agent/output.txt b/acceptance/bundle/deployment/bind/genie_agent/output.txt new file mode 100644 index 00000000000..bbab2ef84dd --- /dev/null +++ b/acceptance/bundle/deployment/bind/genie_agent/output.txt @@ -0,0 +1,51 @@ + +>>> [CLI] genie-agents create-genie-agent --json { + "display_name": "bound-agent", + "warehouse_id": "test-warehouse-id", + "parent_path": "/Users/[USERNAME]", + "definition": { + "config": { + "sample_questions": [ + {"id": "01f0a1b2c3d4e5f60718293a4b5c6d7f", "question": "What was the average trip distance last month?"} + ] + } + } +} --genie-agent-id 01f0a1b2c3d4e5f60718293a4b5c6d7e +{ + "name": "agents/01f0a1b2c3d4e5f60718293a4b5c6d7e", + "display_name": "bound-agent", + "warehouse_id": "test-warehouse-id" +} + +>>> [CLI] bundle deployment bind agent1 01f0a1b2c3d4e5f60718293a4b5c6d7e --auto-approve +Successfully bound genie_agent with an id '01f0a1b2c3d4e5f60718293a4b5c6d7e' +Run 'bundle deploy' to deploy changes to your workspace + +>>> [CLI] bundle plan +Plan: 0 to add, 0 to change, 0 to delete, 1 unchanged + +>>> [CLI] bundle deploy +Uploading bundle files to /Workspace/Users/[USERNAME]/.bundle/test-bundle/default/files... +Files: 2 uploaded, 0 deleted +Resources: 0 created, 0 changed, 0 deleted, 1 unchanged + +>>> [CLI] genie-agents get-genie-agent agents/01f0a1b2c3d4e5f60718293a4b5c6d7e +{ + "name": "agents/01f0a1b2c3d4e5f60718293a4b5c6d7e", + "display_name": "bound-agent", + "warehouse_id": "test-warehouse-id" +} + +>>> [CLI] bundle deployment unbind agent1 + +>>> [CLI] bundle destroy --auto-approve +All files and directories at the following location will be deleted: /Workspace/Users/[USERNAME]/.bundle/test-bundle/default + +Destroy: 0 deleted + +>>> [CLI] genie-agents get-genie-agent agents/01f0a1b2c3d4e5f60718293a4b5c6d7e +{ + "name": "agents/01f0a1b2c3d4e5f60718293a4b5c6d7e", + "display_name": "bound-agent", + "warehouse_id": "test-warehouse-id" +} diff --git a/acceptance/bundle/deployment/bind/genie_agent/script b/acceptance/bundle/deployment/bind/genie_agent/script new file mode 100644 index 00000000000..1fe7ca8504f --- /dev/null +++ b/acceptance/bundle/deployment/bind/genie_agent/script @@ -0,0 +1,38 @@ +AGENT="01f0a1b2c3d4e5f60718293a4b5c6d7e" + +envsubst < databricks.yml.tmpl > databricks.yml + +# Create the object outside the bundle in the same folder as its local config. +AGENT_CONFIG=$(cat <>> [CLI] bundle summary -o json +{ + "definition": { + "config": { + "sample_questions": [ + { + "id": "01f0a1b2c3d4e5f60718293a4b5c6d7f", + "question": "What was the average trip distance last month?" + } + ] + }, + "data_sources": { + "tables": [ + { + "description": "One row per taxi trip, with pickup and drop-off times.", + "identifier": "samples.nyctaxi.trips" + } + ] + } + }, + "description": "COMMENT1", + "display_name": "my-agent", + "genie_agent_id": "01f0a1b2c3d4e5f60718293a4b5c6d7e", + "modified_status": "created", + "parent_path": "/Workspace/Users/[USERNAME]/.bundle/test-bundle/default/resources", + "warehouse_id": "test-warehouse-id" +} + +=== Verify it does not exist yet + +>>> musterr [CLI] genie-agents get-genie-agent agents/01f0a1b2c3d4e5f60718293a4b5c6d7e +Error: Genie Agent not found + +>>> [CLI] bundle deploy +Uploading bundle files to /Workspace/Users/[USERNAME]/.bundle/test-bundle/default/files... +Created genie_agents.agent1 +Files: 1 uploaded, 0 deleted +Resources: 1 created, 0 changed, 0 deleted, 0 unchanged + +>>> print_requests.py //genie/agents //workspace/mkdirs +{ + "method": "POST", + "path": "/api/2.0/workspace/mkdirs", + "body": { + "path": "/Workspace/Users/[USERNAME]/.bundle/test-bundle/default/state" + } +} +{ + "method": "POST", + "path": "/api/2.0/workspace/mkdirs", + "body": { + "path": "/Workspace/Users/[USERNAME]/.bundle/test-bundle/default/artifacts/.internal" + } +} +{ + "method": "POST", + "path": "/api/2.0/workspace/mkdirs", + "body": { + "path": "/Workspace/Users/[USERNAME]/.bundle/test-bundle/default/files" + } +} +{ + "method": "POST", + "path": "/api/2.0/genie/agents", + "q": { + "genie_agent_id": "01f0a1b2c3d4e5f60718293a4b5c6d7e" + }, + "body": { + "definition": { + "config": { + "sample_questions": [ + { + "id": "01f0a1b2c3d4e5f60718293a4b5c6d7f", + "question": "What was the average trip distance last month?" + } + ] + }, + "data_sources": { + "tables": [ + { + "description": "One row per taxi trip, with pickup and drop-off times.", + "identifier": "samples.nyctaxi.trips" + } + ] + } + }, + "description": "COMMENT1", + "display_name": "my-agent", + "parent_path": "/Workspace/Users/[USERNAME]/.bundle/test-bundle/default/resources", + "warehouse_id": "test-warehouse-id" + } +} +{ + "method": "POST", + "path": "/api/2.0/workspace/mkdirs", + "body": { + "path": "/Workspace/Users/[USERNAME]/.bundle/test-bundle/default/resources" + } +} +{ + "method": "POST", + "path": "/api/2.0/genie/agents", + "q": { + "genie_agent_id": "01f0a1b2c3d4e5f60718293a4b5c6d7e" + }, + "body": { + "definition": { + "config": { + "sample_questions": [ + { + "id": "01f0a1b2c3d4e5f60718293a4b5c6d7f", + "question": "What was the average trip distance last month?" + } + ] + }, + "data_sources": { + "tables": [ + { + "description": "One row per taxi trip, with pickup and drop-off times.", + "identifier": "samples.nyctaxi.trips" + } + ] + } + }, + "description": "COMMENT1", + "display_name": "my-agent", + "parent_path": "/Workspace/Users/[USERNAME]/.bundle/test-bundle/default/resources", + "warehouse_id": "test-warehouse-id" + } +} + +=== Summary should show the id and the Genie room url + +>>> [CLI] bundle summary -o json +{ + "id": "01f0a1b2c3d4e5f60718293a4b5c6d7e", + "url": "[DATABRICKS_URL]/genie/rooms/01f0a1b2c3d4e5f60718293a4b5c6d7e?w=[WORKSPACE_ID]" +} + +=== Verify deployment + +>>> [CLI] genie-agents get-genie-agent agents/01f0a1b2c3d4e5f60718293a4b5c6d7e +{ + "name": "agents/01f0a1b2c3d4e5f60718293a4b5c6d7e", + "display_name": "my-agent", + "description": "COMMENT1", + "warehouse_id": "test-warehouse-id" +} + +=== Update description (should update in place, not recreate) + +>>> update_file.py databricks.yml COMMENT1 COMMENT2 + +>>> [CLI] bundle deploy +Uploading bundle files to /Workspace/Users/[USERNAME]/.bundle/test-bundle/default/files... +Updated genie_agents.agent1 +Files: 1 uploaded, 0 deleted +Resources: 0 created, 1 changed, 0 deleted, 0 unchanged + +>>> print_requests.py //genie/agents +{ + "method": "PATCH", + "path": "/api/2.0/genie/agents/01f0a1b2c3d4e5f60718293a4b5c6d7e", + "q": { + "etag": "1", + "update_mask": "*" + }, + "body": { + "definition": { + "config": { + "sample_questions": [ + { + "id": "01f0a1b2c3d4e5f60718293a4b5c6d7f", + "question": "What was the average trip distance last month?" + } + ] + }, + "data_sources": { + "tables": [ + { + "description": "One row per taxi trip, with pickup and drop-off times.", + "identifier": "samples.nyctaxi.trips" + } + ] + } + }, + "description": "COMMENT2", + "display_name": "my-agent", + "parent_path": "/Workspace/Users/[USERNAME]/.bundle/test-bundle/default/resources", + "warehouse_id": "test-warehouse-id" + } +} + +>>> [CLI] genie-agents get-genie-agent agents/01f0a1b2c3d4e5f60718293a4b5c6d7e +{ + "name": "agents/01f0a1b2c3d4e5f60718293a4b5c6d7e", + "display_name": "my-agent", + "description": "COMMENT2", + "warehouse_id": "test-warehouse-id" +} + +=== Change the identity field (should plan a recreate) + +>>> update_file.py databricks.yml 01f0a1b2c3d4e5f60718293a4b5c6d7e 02f0a1b2c3d4e5f60718293a4b5c6d7e + +>>> [CLI] bundle plan +recreate genie_agents.agent1 + +Plan: 1 to add, 0 to change, 1 to delete, 0 unchanged + +>>> [CLI] bundle deploy --auto-approve +Uploading bundle files to /Workspace/Users/[USERNAME]/.bundle/test-bundle/default/files... + +This action will result in the deletion or recreation of the following Genie agents. +The conversation history attached to a deleted agent is permanently lost: + recreate resources.genie_agents.agent1 +Recreated genie_agents.agent1 +Files: 1 uploaded, 0 deleted +Resources: 1 created, 0 changed, 1 deleted, 0 unchanged + +>>> print_requests.py //genie/agents +{ + "method": "DELETE", + "path": "/api/2.0/genie/agents/01f0a1b2c3d4e5f60718293a4b5c6d7e" +} +{ + "method": "POST", + "path": "/api/2.0/genie/agents", + "q": { + "genie_agent_id": "02f0a1b2c3d4e5f60718293a4b5c6d7e" + }, + "body": { + "definition": { + "config": { + "sample_questions": [ + { + "id": "01f0a1b2c3d4e5f60718293a4b5c6d7f", + "question": "What was the average trip distance last month?" + } + ] + }, + "data_sources": { + "tables": [ + { + "description": "One row per taxi trip, with pickup and drop-off times.", + "identifier": "samples.nyctaxi.trips" + } + ] + } + }, + "description": "COMMENT2", + "display_name": "my-agent", + "parent_path": "/Workspace/Users/[USERNAME]/.bundle/test-bundle/default/resources", + "warehouse_id": "test-warehouse-id" + } +} + +=== Destroy + +>>> [CLI] bundle destroy --auto-approve +The following resources will be deleted: + delete resources.genie_agents.agent1 + +This action will result in the deletion of the following Genie agents. +The conversation history attached to them is permanently lost: + delete resources.genie_agents.agent1 + +All files and directories at the following location will be deleted: /Workspace/Users/[USERNAME]/.bundle/test-bundle/default + +Destroy: 1 deleted + +>>> print_requests.py //genie/agents +{ + "method": "DELETE", + "path": "/api/2.0/genie/agents/02f0a1b2c3d4e5f60718293a4b5c6d7e" +} diff --git a/acceptance/bundle/resources/genie_agents/basic/script b/acceptance/bundle/resources/genie_agents/basic/script new file mode 100644 index 00000000000..41a79d70ebd --- /dev/null +++ b/acceptance/bundle/resources/genie_agents/basic/script @@ -0,0 +1,35 @@ +AGENT="agents/01f0a1b2c3d4e5f60718293a4b5c6d7e" + +title "Initial summary before deploy" +trace $CLI bundle summary -o json | jq .resources.genie_agents.agent1 + +title "Verify it does not exist yet" +trace musterr $CLI genie-agents get-genie-agent "$AGENT" + +trace $CLI bundle deploy +# The default parent_path (the bundle's resource folder) does not exist on a +# first deploy: the create 404s, the adapter mkdirs and retries. +trace print_requests.py //genie/agents //workspace/mkdirs + +title "Summary should show the id and the Genie room url" +trace $CLI bundle summary -o json | jq ".resources.genie_agents.agent1 | {id, url}" + +title "Verify deployment" +trace $CLI genie-agents get-genie-agent "$AGENT" | agent_fields + +title "Update description (should update in place, not recreate)" +trace update_file.py databricks.yml COMMENT1 COMMENT2 +trace $CLI bundle deploy +trace print_requests.py //genie/agents +trace $CLI genie-agents get-genie-agent "$AGENT" | agent_fields + +title "Change the identity field (should plan a recreate)" +trace update_file.py databricks.yml 01f0a1b2c3d4e5f60718293a4b5c6d7e 02f0a1b2c3d4e5f60718293a4b5c6d7e +trace $CLI bundle plan + +trace $CLI bundle deploy --auto-approve +trace print_requests.py //genie/agents + +title "Destroy" +trace $CLI bundle destroy --auto-approve +trace print_requests.py //genie/agents diff --git a/acceptance/bundle/resources/genie_agents/basic/test.toml b/acceptance/bundle/resources/genie_agents/basic/test.toml new file mode 100644 index 00000000000..116f2013783 --- /dev/null +++ b/acceptance/bundle/resources/genie_agents/basic/test.toml @@ -0,0 +1,7 @@ +# Local only: this test inspects the recorded request stream (print_requests), +# which has no equivalent against a real workspace. +Cloud = false + +Ignore = [ + ".databricks", +] diff --git a/acceptance/bundle/resources/genie_agents/lifecycle/databricks.yml.tmpl b/acceptance/bundle/resources/genie_agents/lifecycle/databricks.yml.tmpl new file mode 100644 index 00000000000..3f590b69165 --- /dev/null +++ b/acceptance/bundle/resources/genie_agents/lifecycle/databricks.yml.tmpl @@ -0,0 +1,17 @@ +bundle: + name: deploy-genie-agent-test-$UNIQUE_NAME + +resources: + genie_agents: + agent: + display_name: test_agent_$UNIQUE_NAME + description: "Agent grounded in taxi trip data" + warehouse_id: $TEST_DEFAULT_WAREHOUSE_ID + definition: + config: + sample_questions: + - id: "01f0a1b2c3d4e5f60718293a4b5c6d7e" + question: What was the average trip distance last month? + data_sources: + tables: + - identifier: samples.nyctaxi.trips diff --git a/acceptance/bundle/resources/genie_agents/lifecycle/out.test.toml b/acceptance/bundle/resources/genie_agents/lifecycle/out.test.toml new file mode 100644 index 00000000000..f68b4a89c36 --- /dev/null +++ b/acceptance/bundle/resources/genie_agents/lifecycle/out.test.toml @@ -0,0 +1,2 @@ +Cloud = true +EnvMatrix.DMS = [""] diff --git a/acceptance/bundle/resources/genie_agents/lifecycle/output.txt b/acceptance/bundle/resources/genie_agents/lifecycle/output.txt new file mode 100644 index 00000000000..6fb773b4dba --- /dev/null +++ b/acceptance/bundle/resources/genie_agents/lifecycle/output.txt @@ -0,0 +1,50 @@ + +>>> [CLI] bundle deploy +Uploading bundle files to /Workspace/Users/[USERNAME]/.bundle/deploy-genie-agent-test-[UNIQUE_NAME]/default/files... +Created genie_agents.agent +Files: 2 uploaded, 0 deleted +Resources: 1 created, 0 changed, 0 deleted, 0 unchanged + +>>> [CLI] genie-agents get-genie-agent agents/[AGENT_ID] +{ + "name": "agents/[AGENT_ID]", + "display_name": "test_agent_[UNIQUE_NAME]", + "description": "Agent grounded in taxi trip data", + "warehouse_id": "[TEST_DEFAULT_WAREHOUSE_ID]" +} + +>>> [CLI] bundle plan +Plan: 0 to add, 0 to change, 0 to delete, 1 unchanged + +=== Update description in place + +>>> update_file.py databricks.yml Agent grounded in taxi trip data Agent grounded in taxi trip data, updated + +>>> [CLI] bundle deploy +Uploading bundle files to /Workspace/Users/[USERNAME]/.bundle/deploy-genie-agent-test-[UNIQUE_NAME]/default/files... +Updated genie_agents.agent +Files: 1 uploaded, 0 deleted +Resources: 0 created, 1 changed, 0 deleted, 0 unchanged + +>>> [CLI] genie-agents get-genie-agent agents/[AGENT_ID] +{ + "name": "agents/[AGENT_ID]", + "display_name": "test_agent_[UNIQUE_NAME]", + "description": "Agent grounded in taxi trip data, updated", + "warehouse_id": "[TEST_DEFAULT_WAREHOUSE_ID]" +} + +>>> [CLI] bundle plan +Plan: 0 to add, 0 to change, 0 to delete, 1 unchanged + +>>> [CLI] bundle destroy --auto-approve +The following resources will be deleted: + delete resources.genie_agents.agent + +This action will result in the deletion of the following Genie agents. +The conversation history attached to them is permanently lost: + delete resources.genie_agents.agent + +All files and directories at the following location will be deleted: /Workspace/Users/[USERNAME]/.bundle/deploy-genie-agent-test-[UNIQUE_NAME]/default + +Destroy: 1 deleted diff --git a/acceptance/bundle/resources/genie_agents/lifecycle/script b/acceptance/bundle/resources/genie_agents/lifecycle/script new file mode 100644 index 00000000000..418009c0690 --- /dev/null +++ b/acceptance/bundle/resources/genie_agents/lifecycle/script @@ -0,0 +1,25 @@ +envsubst < databricks.yml.tmpl > databricks.yml + +cleanup() { + trace $CLI bundle destroy --auto-approve +} +trap cleanup EXIT + +trace $CLI bundle deploy + +# The server assigns the id; read it from state and register the [AGENT_ID] +# replacement so the golden does not pin the random value. +AGENT=$(read_id.py agent) + +trace $CLI genie-agents get-genie-agent "agents/$AGENT" | agent_fields + +# Verify there is no drift right after deploy. Text plan (not -o json) keeps the +# output identical between the mock and a real workspace. +trace $CLI bundle plan + +title "Update description in place" +trace update_file.py databricks.yml "Agent grounded in taxi trip data" "Agent grounded in taxi trip data, updated" +trace $CLI bundle deploy +trace $CLI genie-agents get-genie-agent "agents/$AGENT" | agent_fields + +trace $CLI bundle plan diff --git a/acceptance/bundle/resources/genie_agents/lifecycle/test.toml b/acceptance/bundle/resources/genie_agents/lifecycle/test.toml new file mode 100644 index 00000000000..8abb5e502eb --- /dev/null +++ b/acceptance/bundle/resources/genie_agents/lifecycle/test.toml @@ -0,0 +1,9 @@ +# Genie agent lifecycle, also runs against a real workspace. The cloud run +# needs the Genie Agents preview enabled on the test workspaces; locally the +# fake server covers the same flow. +RecordRequests = false + +Ignore = [ + "databricks.yml", + ".databricks", +] diff --git a/acceptance/bundle/resources/genie_agents/remote-delete/databricks.yml b/acceptance/bundle/resources/genie_agents/remote-delete/databricks.yml new file mode 100644 index 00000000000..307d256ea38 --- /dev/null +++ b/acceptance/bundle/resources/genie_agents/remote-delete/databricks.yml @@ -0,0 +1,14 @@ +bundle: + name: test-bundle + +resources: + genie_agents: + agent1: + genie_agent_id: "01f0a1b2c3d4e5f60718293a4b5c6d7e" + display_name: my-agent + warehouse_id: test-warehouse-id + definition: + config: + sample_questions: + - id: "01f0a1b2c3d4e5f60718293a4b5c6d7f" + question: What was the average trip distance last month? diff --git a/acceptance/bundle/resources/genie_agents/remote-delete/out.test.toml b/acceptance/bundle/resources/genie_agents/remote-delete/out.test.toml new file mode 100644 index 00000000000..19b5b15d11f --- /dev/null +++ b/acceptance/bundle/resources/genie_agents/remote-delete/out.test.toml @@ -0,0 +1,2 @@ +Cloud = false +EnvMatrix.DMS = [""] diff --git a/acceptance/bundle/resources/genie_agents/remote-delete/output.txt b/acceptance/bundle/resources/genie_agents/remote-delete/output.txt new file mode 100644 index 00000000000..4b571f5d287 --- /dev/null +++ b/acceptance/bundle/resources/genie_agents/remote-delete/output.txt @@ -0,0 +1,51 @@ + +>>> [CLI] bundle deploy +Uploading bundle files to /Workspace/Users/[USERNAME]/.bundle/test-bundle/default/files... +Created genie_agents.agent1 +Files: 1 uploaded, 0 deleted +Resources: 1 created, 0 changed, 0 deleted, 0 unchanged + +=== Delete the resource out of band + +>>> [CLI] genie-agents delete-genie-agent agents/01f0a1b2c3d4e5f60718293a4b5c6d7e + +=== Plan detects the resource is gone + +>>> [CLI] bundle plan +create genie_agents.agent1 + +Plan: 1 to add, 0 to change, 0 to delete, 0 unchanged + +=== Deploy cannot reuse the pinned ID + +>>> musterr [CLI] bundle deploy +Uploading bundle files to /Workspace/Users/[USERNAME]/.bundle/test-bundle/default/files... +Error: cannot create resources.genie_agents.agent1: Genie Agent 01f0a1b2c3d4e5f60718293a4b5c6d7e already exists (409 ALREADY_EXISTS) + +Endpoint: POST [DATABRICKS_URL]/api/2.0/genie/agents?genie_agent_id=01f0a1b2c3d4e5f60718293a4b5c6d7e +HTTP Status: 409 Conflict +API error_code: ALREADY_EXISTS +API message: Genie Agent 01f0a1b2c3d4e5f60718293a4b5c6d7e already exists + +Files: 0 uploaded, 0 deleted + +>>> [CLI] bundle destroy --auto-approve +All files and directories at the following location will be deleted: /Workspace/Users/[USERNAME]/.bundle/test-bundle/default + +Destroy: 0 deleted + +>>> musterr [CLI] bundle deploy +Uploading bundle files to /Workspace/Users/[USERNAME]/.bundle/test-bundle/default/files... +Error: cannot create resources.genie_agents.agent1: Genie Agent 01f0a1b2c3d4e5f60718293a4b5c6d7e already exists (409 ALREADY_EXISTS) + +Endpoint: POST [DATABRICKS_URL]/api/2.0/genie/agents?genie_agent_id=01f0a1b2c3d4e5f60718293a4b5c6d7e +HTTP Status: 409 Conflict +API error_code: ALREADY_EXISTS +API message: Genie Agent 01f0a1b2c3d4e5f60718293a4b5c6d7e already exists + +Files: 1 uploaded, 0 deleted + +>>> [CLI] bundle destroy --auto-approve +All files and directories at the following location will be deleted: /Workspace/Users/[USERNAME]/.bundle/test-bundle/default + +Destroy: 0 deleted diff --git a/acceptance/bundle/resources/genie_agents/remote-delete/script b/acceptance/bundle/resources/genie_agents/remote-delete/script new file mode 100644 index 00000000000..5584a67e29c --- /dev/null +++ b/acceptance/bundle/resources/genie_agents/remote-delete/script @@ -0,0 +1,18 @@ +trace $CLI bundle deploy + +title "Delete the resource out of band" +trace $CLI genie-agents delete-genie-agent agents/01f0a1b2c3d4e5f60718293a4b5c6d7e + +title "Plan detects the resource is gone" +trace $CLI bundle plan + +# Deleting an agent moves it to trash, where its pinned ID remains reserved. +title "Deploy cannot reuse the pinned ID" +trace musterr $CLI bundle deploy + +trace $CLI bundle destroy --auto-approve + +# Destroy clears bundle state, but the trashed agent still reserves its ID. +trace musterr $CLI bundle deploy + +trace $CLI bundle destroy --auto-approve diff --git a/acceptance/bundle/resources/genie_agents/remote-delete/test.toml b/acceptance/bundle/resources/genie_agents/remote-delete/test.toml new file mode 100644 index 00000000000..ba894313d70 --- /dev/null +++ b/acceptance/bundle/resources/genie_agents/remote-delete/test.toml @@ -0,0 +1,9 @@ +# Local only: simulates an out-of-band delete with a fixed resource id, so it +# can't run against a real workspace. +Cloud = false + +RecordRequests = false + +Ignore = [ + ".databricks", +] diff --git a/acceptance/bundle/resources/genie_agents/script.prepare b/acceptance/bundle/resources/genie_agents/script.prepare new file mode 100644 index 00000000000..661fb3b8f30 --- /dev/null +++ b/acceptance/bundle/resources/genie_agents/script.prepare @@ -0,0 +1,6 @@ +# Project a genie agent read to the fields the test asserts. The etag is +# omitted: the backend bumps it on definition edits, so pinning it would not +# survive a real workspace run. +agent_fields() { + jq '{name, display_name, description, warehouse_id}' +} diff --git a/acceptance/bundle/resources/genie_agents/test.toml b/acceptance/bundle/resources/genie_agents/test.toml new file mode 100644 index 00000000000..03326ae69c0 --- /dev/null +++ b/acceptance/bundle/resources/genie_agents/test.toml @@ -0,0 +1,7 @@ +# Genie agents are managed by the direct deployment engine. +Cloud = true + +# Deployment history has no "genie_agents." resource-key prefix, so enabling +# deployment history warns on every deploy. See dmsResourceTypes in +# libs/testserver/bundledeployments.go, which mirrors the service's allowlist. +EnvMatrixExclude.no_genie_agent_dms = ["DMS=true"] diff --git a/acceptance/bundle/resources/genie_agents/without-definition/databricks.yml.tmpl b/acceptance/bundle/resources/genie_agents/without-definition/databricks.yml.tmpl new file mode 100644 index 00000000000..f000e589e76 --- /dev/null +++ b/acceptance/bundle/resources/genie_agents/without-definition/databricks.yml.tmpl @@ -0,0 +1,8 @@ +bundle: + name: genie-agent-no-definition-$UNIQUE_NAME + +resources: + genie_agents: + agent: + display_name: test_agent_$UNIQUE_NAME + warehouse_id: $TEST_DEFAULT_WAREHOUSE_ID diff --git a/acceptance/bundle/resources/genie_agents/without-definition/out.test.toml b/acceptance/bundle/resources/genie_agents/without-definition/out.test.toml new file mode 100644 index 00000000000..19b5b15d11f --- /dev/null +++ b/acceptance/bundle/resources/genie_agents/without-definition/out.test.toml @@ -0,0 +1,2 @@ +Cloud = false +EnvMatrix.DMS = [""] diff --git a/acceptance/bundle/resources/genie_agents/without-definition/output.txt b/acceptance/bundle/resources/genie_agents/without-definition/output.txt new file mode 100644 index 00000000000..7c21fc74292 --- /dev/null +++ b/acceptance/bundle/resources/genie_agents/without-definition/output.txt @@ -0,0 +1,13 @@ + +>>> [CLI] bundle validate +Warning: required field "definition" is not set + at resources.genie_agents.agent + in databricks.yml:7:7 + +Name: genie-agent-no-definition-[UNIQUE_NAME] +Target: default +Workspace: + User: [USERNAME] + Path: /Workspace/Users/[USERNAME]/.bundle/genie-agent-no-definition-[UNIQUE_NAME]/default + +Found 1 warning diff --git a/acceptance/bundle/resources/genie_agents/without-definition/script b/acceptance/bundle/resources/genie_agents/without-definition/script new file mode 100644 index 00000000000..cfe2ad15929 --- /dev/null +++ b/acceptance/bundle/resources/genie_agents/without-definition/script @@ -0,0 +1,3 @@ +envsubst < databricks.yml.tmpl > databricks.yml + +trace $CLI bundle validate diff --git a/acceptance/bundle/resources/genie_agents/without-definition/test.toml b/acceptance/bundle/resources/genie_agents/without-definition/test.toml new file mode 100644 index 00000000000..1cf5e80e38c --- /dev/null +++ b/acceptance/bundle/resources/genie_agents/without-definition/test.toml @@ -0,0 +1,8 @@ +# Local only: shows the required-field warning; nothing is deployed. +Cloud = false + +RecordRequests = false + +Ignore = [ + ".databricks", +] diff --git a/acceptance/experimental/open/output.txt b/acceptance/experimental/open/output.txt index 09747c5baa0..bae64d7caac 100644 --- a/acceptance/experimental/open/output.txt +++ b/acceptance/experimental/open/output.txt @@ -12,7 +12,7 @@ === unknown resource type >>> [CLI] experimental open --url unknown 123 -Error: unknown resource type "unknown", must be one of: alerts, apps, catalogs, cluster_policies, clusters, dashboards, database_catalogs, database_instances, experiments, feature_specs, features, genie_spaces, instance_pools, jobs, mcp_services, model_provider_services, model_services, model_serving_endpoints, models, notebooks, pipelines, postgres_catalogs, postgres_synced_tables, quality_monitors, queries, registered_models, schemas, secrets, synced_database_tables, vector_search_endpoints, vector_search_indexes, volumes, warehouses +Error: unknown resource type "unknown", must be one of: alerts, apps, catalogs, cluster_policies, clusters, dashboards, database_catalogs, database_instances, experiments, feature_specs, features, genie_agents, genie_spaces, instance_pools, jobs, mcp_services, model_provider_services, model_services, model_serving_endpoints, models, notebooks, pipelines, postgres_catalogs, postgres_synced_tables, quality_monitors, queries, registered_models, schemas, secrets, synced_database_tables, vector_search_endpoints, vector_search_indexes, volumes, warehouses === test auto-completion handler @@ -28,6 +28,7 @@ database_instances experiments feature_specs features +genie_agents genie_spaces instance_pools jobs diff --git a/bundle/config/mutator/resourcemutator/apply_bundle_permissions.go b/bundle/config/mutator/resourcemutator/apply_bundle_permissions.go index 15493ae9d15..c050f77a7a5 100644 --- a/bundle/config/mutator/resourcemutator/apply_bundle_permissions.go +++ b/bundle/config/mutator/resourcemutator/apply_bundle_permissions.go @@ -52,6 +52,10 @@ var ( permissions.CAN_MANAGE: "CAN_MANAGE", permissions.CAN_VIEW: "CAN_READ", }, + "genie_agents": { + permissions.CAN_MANAGE: "CAN_MANAGE", + permissions.CAN_VIEW: "CAN_READ", + }, "apps": { permissions.CAN_MANAGE: "CAN_MANAGE", permissions.CAN_VIEW: "CAN_USE", diff --git a/bundle/config/mutator/resourcemutator/apply_presets.go b/bundle/config/mutator/resourcemutator/apply_presets.go index d808daf82fb..08761609fb6 100644 --- a/bundle/config/mutator/resourcemutator/apply_presets.go +++ b/bundle/config/mutator/resourcemutator/apply_presets.go @@ -286,6 +286,14 @@ func (m *applyPresets) Apply(ctx context.Context, b *bundle.Bundle) diag.Diagnos genieSpace.Title = prefix + genieSpace.Title } + // Genie Agents: Prefix + for _, genieAgent := range r.GenieAgents { + if genieAgent == nil { + continue + } + genieAgent.DisplayName = prefix + genieAgent.DisplayName + } + // Apps: No presets // Alerts: Prefix, TriggerPauseStatus diff --git a/bundle/config/mutator/resourcemutator/apply_target_mode_test.go b/bundle/config/mutator/resourcemutator/apply_target_mode_test.go index 30a2d8d427c..9c6d393cff3 100644 --- a/bundle/config/mutator/resourcemutator/apply_target_mode_test.go +++ b/bundle/config/mutator/resourcemutator/apply_target_mode_test.go @@ -207,6 +207,13 @@ func mockBundle(mode config.Mode) *bundle.Bundle { }, }, }, + GenieAgents: map[string]*resources.GenieAgent{ + "genieagent1": { + GenieAgentConfig: resources.GenieAgentConfig{ + DisplayName: "genieagent1", + }, + }, + }, Apps: map[string]*resources.App{ "app1": { App: apps.App{ @@ -458,6 +465,9 @@ func TestProcessTargetModeDevelopment(t *testing.T) { // Genie Spaces assert.Equal(t, "[dev lennart] geniespace1", b.Config.Resources.GenieSpaces["geniespace1"].Title) + // Genie Agents + assert.Equal(t, "[dev lennart] genieagent1", b.Config.Resources.GenieAgents["genieagent1"].DisplayName) + // Alert 1: has schedule without pause status set - should be paused assert.Equal(t, "[dev lennart] alert1", b.Config.Resources.Alerts["alert1"].DisplayName) assert.Equal(t, sql.SchedulePauseStatusPaused, b.Config.Resources.Alerts["alert1"].Schedule.PauseStatus) @@ -574,6 +584,7 @@ func TestAppropriateResourcesAreRenamed(t *testing.T) { notUserNamed := []string{ "Apps", "Features", + "GenieAgents", "FeatureSpecs", "SecretScopes", "Secrets", diff --git a/bundle/config/mutator/resourcemutator/resource_mutator.go b/bundle/config/mutator/resourcemutator/resource_mutator.go index e00444cc773..16fb6555fdf 100644 --- a/bundle/config/mutator/resourcemutator/resource_mutator.go +++ b/bundle/config/mutator/resourcemutator/resource_mutator.go @@ -53,6 +53,7 @@ func applyInitializeMutators(ctx context.Context, b *bundle.Bundle) { {"resources.dashboards.*.parent_path", b.Config.Workspace.ResourcePath}, {"resources.dashboards.*.embed_credentials", false}, {"resources.genie_spaces.*.parent_path", b.Config.Workspace.ResourcePath}, + {"resources.genie_agents.*.parent_path", b.Config.Workspace.ResourcePath}, {"resources.volumes.*.volume_type", "MANAGED"}, {"resources.alerts.*.parent_path", b.Config.Workspace.ResourcePath}, diff --git a/bundle/config/mutator/resourcemutator/run_as_test.go b/bundle/config/mutator/resourcemutator/run_as_test.go index 6979407c4ec..7a2ad3a72e8 100644 --- a/bundle/config/mutator/resourcemutator/run_as_test.go +++ b/bundle/config/mutator/resourcemutator/run_as_test.go @@ -51,6 +51,7 @@ func allResourceTypes(t *testing.T) []string { "external_locations", "feature_specs", "features", + "genie_agents", "genie_spaces", "instance_pools", "internal_immutable_snapshots", @@ -211,6 +212,7 @@ var allowList = []string{ "experiments", "feature_specs", "features", + "genie_agents", "genie_spaces", "instance_pools", "job_runs", diff --git a/bundle/config/resources.go b/bundle/config/resources.go index b2c968a2b07..0ac8e78b468 100644 --- a/bundle/config/resources.go +++ b/bundle/config/resources.go @@ -35,6 +35,7 @@ type Resources struct { Clusters map[string]*resources.Cluster `json:"clusters,omitempty"` Dashboards map[string]*resources.Dashboard `json:"dashboards,omitempty"` GenieSpaces map[string]*resources.GenieSpace `json:"genie_spaces,omitempty"` + GenieAgents map[string]*resources.GenieAgent `json:"genie_agents,omitempty"` Apps map[string]*resources.App `json:"apps,omitempty"` SecretScopes map[string]*resources.SecretScope `json:"secret_scopes,omitempty"` Alerts map[string]*resources.Alert `json:"alerts,omitempty"` @@ -135,6 +136,7 @@ func (r *Resources) AllResources() []ResourceGroup { collectResourceMap(descriptions["clusters"], r.Clusters), collectResourceMap(descriptions["dashboards"], r.Dashboards), collectResourceMap(descriptions["genie_spaces"], r.GenieSpaces), + collectResourceMap(descriptions["genie_agents"], r.GenieAgents), collectResourceMap(descriptions["volumes"], r.Volumes), collectResourceMap(descriptions["apps"], r.Apps), collectResourceMap(descriptions["alerts"], r.Alerts), @@ -246,6 +248,7 @@ func SupportedResources() map[string]resources.ResourceDescription { "clusters": (&resources.Cluster{}).ResourceDescription(), "dashboards": (&resources.Dashboard{}).ResourceDescription(), "genie_spaces": (&resources.GenieSpace{}).ResourceDescription(), + "genie_agents": (&resources.GenieAgent{}).ResourceDescription(), "volumes": (&resources.Volume{}).ResourceDescription(), "apps": (&resources.App{}).ResourceDescription(), "secret_scopes": (&resources.SecretScope{}).ResourceDescription(), diff --git a/bundle/config/resources/genie_agent.go b/bundle/config/resources/genie_agent.go new file mode 100644 index 00000000000..e7cde2501be --- /dev/null +++ b/bundle/config/resources/genie_agent.go @@ -0,0 +1,97 @@ +package resources + +import ( + "context" + "net/url" + + "github.com/databricks/cli/libs/log" + "github.com/databricks/cli/libs/workspaceurls" + "github.com/databricks/databricks-sdk-go" + "github.com/databricks/databricks-sdk-go/apierr" + "github.com/databricks/databricks-sdk-go/marshal" + "github.com/databricks/databricks-sdk-go/service/genieagents" +) + +// GenieAgentConfig is the bundle-authored state for a Genie Agent. +// +// It embeds the SDK body. The SDK models the create input `genie_agent_id` as a +// URL parameter (`json:"-"`) outside the body and derives the resource `name` +// (`agents/{genie_agent_id}`) server-side, so the ID is added here. The +// output-only SDK fields (etag, create_time, update_time, effective_parent_path) +// are removed from the bundle schema by the generator and zeroed by PrepareState. +type GenieAgentConfig struct { + genieagents.GenieAgent + + // Client-specified ID for the agent: 32 lowercase hexadecimal characters + // (a UUID without dashes), not all zeros. Assigned by the server if + // omitted. Immutable: changing it recreates the resource. After bundle destroy + // or deletion, the agent remains in trash with its ID reserved until + // permanently removed. Omit this field to let the server assign an ID. + GenieAgentId string `json:"genie_agent_id,omitempty"` +} + +func (c *GenieAgentConfig) UnmarshalJSON(b []byte) error { + return marshal.Unmarshal(b, c) +} + +func (c GenieAgentConfig) MarshalJSON() ([]byte, error) { + return marshal.Marshal(c) +} + +// GenieAgent is a Genie Agent resource (the AI/BI Genie assistant surface). +// It manages the same backend object as the older genie_spaces resource, so +// declaring the same object under both resource types is unsupported. +type GenieAgent struct { + BaseResource + ID string `json:"id,omitempty" bundle:"readonly"` + GenieAgentConfig + + Permissions []Permission `json:"permissions,omitempty"` +} + +func (r *GenieAgent) UnmarshalJSON(b []byte) error { + return marshal.Unmarshal(b, r) +} + +func (r GenieAgent) MarshalJSON() ([]byte, error) { + return marshal.Marshal(r) +} + +func (*GenieAgent) Exists(ctx context.Context, w *databricks.WorkspaceClient, id string) (bool, error) { + // The engine tracks the id as the bare genie_agent_id; the API addresses + // the resource by its full name. + _, err := w.GenieAgents.GetGenieAgent(ctx, genieagents.GetGenieAgentRequest{ + Name: "agents/" + id, + }) + if err != nil { + if apierr.IsMissing(err) { + log.Debugf(ctx, "genie agent %s does not exist", id) + return false, nil + } + return false, err + } + return true, nil +} + +func (*GenieAgent) ResourceDescription() ResourceDescription { + return ResourceDescription{ + SingularName: "genie_agent", + PluralName: "genie_agents", + SingularTitle: "Genie Agent", + PluralTitle: "Genie Agents", + } +} + +func (r *GenieAgent) InitializeURL(baseURL url.URL) { + if r.ID == "" { + return + } + + // Agents and spaces are the same backend object, so an agent's UI page is + // the same Genie room page a space uses. + r.URL = workspaceurls.ResourceURL(baseURL, "genie_agents", r.ID) +} + +func (r *GenieAgent) GetName() string { + return r.DisplayName +} diff --git a/bundle/config/resources_test.go b/bundle/config/resources_test.go index 67603159775..e28d1e98665 100644 --- a/bundle/config/resources_test.go +++ b/bundle/config/resources_test.go @@ -226,6 +226,9 @@ func TestResourcesBindSupport(t *testing.T) { GenieSpaces: map[string]*resources.GenieSpace{ "my_genie_space": {}, }, + GenieAgents: map[string]*resources.GenieAgent{ + "my_genie_agent": {}, + }, Volumes: map[string]*resources.Volume{ "my_volume": { CreateVolumeRequestContent: catalog.CreateVolumeRequestContent{}, @@ -446,6 +449,7 @@ func TestResourcesBindSupport(t *testing.T) { m.GetMockClusterPoliciesAPI().EXPECT().GetByPolicyId(mock.Anything, mock.Anything).Return(nil, nil) m.GetMockLakeviewAPI().EXPECT().Get(mock.Anything, mock.Anything).Return(nil, nil) m.GetMockGenieAPI().EXPECT().GetSpace(mock.Anything, mock.Anything).Return(nil, nil) + m.GetMockGenieAgentsAPI().EXPECT().GetGenieAgent(mock.Anything, mock.Anything).Return(nil, nil) m.GetMockVolumesAPI().EXPECT().Read(mock.Anything, mock.Anything).Return(nil, nil) m.GetMockAppsAPI().EXPECT().GetByName(mock.Anything, mock.Anything).Return(nil, nil) m.GetMockAlertsV2API().EXPECT().GetAlertById(mock.Anything, mock.Anything).Return(nil, nil) diff --git a/bundle/direct/dresources/all.go b/bundle/direct/dresources/all.go index 0bc31f6642d..c71c8052684 100644 --- a/bundle/direct/dresources/all.go +++ b/bundle/direct/dresources/all.go @@ -38,6 +38,7 @@ var SupportedResources = map[string]any{ "registered_models": (*ResourceRegisteredModel)(nil), "dashboards": (*ResourceDashboard)(nil), "genie_spaces": (*ResourceGenieSpace)(nil), + "genie_agents": (*ResourceGenieAgent)(nil), "secret_scopes": (*ResourceSecretScope)(nil), "model_serving_endpoints": (*ResourceModelServingEndpoint)(nil), "model_services": (*ResourceModelService)(nil), @@ -67,6 +68,7 @@ var SupportedResources = map[string]any{ "model_serving_endpoints.permissions": (*ResourcePermissions)(nil), "dashboards.permissions": (*ResourcePermissions)(nil), "genie_spaces.permissions": (*ResourcePermissions)(nil), + "genie_agents.permissions": (*ResourcePermissions)(nil), "vector_search_endpoints.permissions": (*ResourcePermissions)(nil), "instance_pools.permissions": (*ResourcePermissions)(nil), diff --git a/bundle/direct/dresources/all_test.go b/bundle/direct/dresources/all_test.go index f80fda21d14..05d29ba2b49 100644 --- a/bundle/direct/dresources/all_test.go +++ b/bundle/direct/dresources/all_test.go @@ -29,6 +29,7 @@ import ( "github.com/databricks/databricks-sdk-go/service/dashboards" "github.com/databricks/databricks-sdk-go/service/database" "github.com/databricks/databricks-sdk-go/service/dataquality" + "github.com/databricks/databricks-sdk-go/service/genieagents" "github.com/databricks/databricks-sdk-go/service/jobs" "github.com/databricks/databricks-sdk-go/service/ml" "github.com/databricks/databricks-sdk-go/service/pipelines" @@ -336,6 +337,31 @@ var testConfig map[string]any = map[string]any{ SerializedSpace: "{}", }, + "genie_agents": &resources.GenieAgent{ + GenieAgentId: "01f0a1b2c3d4e5f60718293a4b5c6d7e", + DisplayName: "my-genie-agent", + Description: "Test genie agent", + WarehouseId: "test-warehouse-id", + ParentPath: "/Workspace/Users/user@example.com", + Definition: genieagents.GenieAgentDefinition{ + Config: &genieagents.GenieAgentConfig{ + SampleQuestions: []genieagents.GenieAgentSampleQuestion{ + {Id: "01f0a1b2c3d4e5f60718293a4b5c6d7e", Question: "What were total sales?"}, + }, + }, + DataSources: &genieagents.GenieAgentDataSources{ + Tables: []genieagents.GenieAgentTable{ + {Identifier: "main.sales.orders", Description: "Orders table"}, + }, + }, + Instructions: &genieagents.GenieAgentInstructions{ + TextInstructions: []genieagents.GenieAgentTextInstruction{ + {Id: "01f0a1b2c3d4e5f60718293a4b5c6d7f", Content: "Report revenue as the sum of order_amount."}, + }, + }, + }, + }, + "vector_search_endpoints": &resources.VectorSearchEndpoint{ Name: "my-endpoint", EndpointType: vectorsearch.EndpointTypeStandard, @@ -639,6 +665,33 @@ var testDeps = map[string]prepareWorkspace{ }, nil }, + "genie_agents.permissions": func(ctx context.Context, client *databricks.WorkspaceClient) (any, error) { + resp, err := client.GenieAgents.CreateGenieAgent(ctx, genieagents.CreateGenieAgentRequest{ + GenieAgent: genieagents.GenieAgent{ + DisplayName: "genie-agent-permissions", + WarehouseId: "test-warehouse-id", + Definition: genieagents.GenieAgentDefinition{ + Config: &genieagents.GenieAgentConfig{ + SampleQuestions: []genieagents.GenieAgentSampleQuestion{ + {Id: "01f0a1b2c3d4e5f60718293a4b5c6d7e", Question: "What were total sales?"}, + }, + }, + }, + }, + }) + if err != nil { + return nil, err + } + + return &PermissionsState{ + ObjectID: "/genie/" + strings.TrimPrefix(resp.Name, "agents/"), + EmbeddedSlice: []StatePermission{{ + Level: "CAN_MANAGE", + UserName: "user@example.com", + }}, + }, nil + }, + "model_serving_endpoints.permissions": func(ctx context.Context, client *databricks.WorkspaceClient) (any, error) { waiter, err := client.ServingEndpoints.Create(ctx, serving.CreateServingEndpoint{ Name: "endpoint-permissions", diff --git a/bundle/direct/dresources/apitypes.generated.yml b/bundle/direct/dresources/apitypes.generated.yml index fb16c02facf..d6f851317c4 100644 --- a/bundle/direct/dresources/apitypes.generated.yml +++ b/bundle/direct/dresources/apitypes.generated.yml @@ -26,6 +26,8 @@ feature_specs: ml.FeatureSpec features: ml.Feature +genie_agents: genieagents.GenieAgent + genie_spaces: dashboards.GenieUpdateSpaceRequest instance_pools: compute.CreateInstancePool diff --git a/bundle/direct/dresources/configs/genie_agents.generated.yml b/bundle/direct/dresources/configs/genie_agents.generated.yml new file mode 100644 index 00000000000..27f8c1c0dad --- /dev/null +++ b/bundle/direct/dresources/configs/genie_agents.generated.yml @@ -0,0 +1,11 @@ +# Generated, do not edit. + +ignore_remote_changes: + - field: create_time + reason: spec:output_only + - field: effective_parent_path + reason: spec:output_only + - field: etag + reason: spec:output_only + - field: update_time + reason: spec:output_only diff --git a/bundle/direct/dresources/configs/genie_agents.yml b/bundle/direct/dresources/configs/genie_agents.yml new file mode 100644 index 00000000000..8db16a6834b --- /dev/null +++ b/bundle/direct/dresources/configs/genie_agents.yml @@ -0,0 +1,16 @@ +provided_id_fields: + # genie_agent_id is the leaf of the server-derived resource name + # (agents/{genie_agent_id}), which is what the resource is fetched by. It is + # server-assigned when omitted on create; a local change recreates. + - field: genie_agent_id + reason: id_field +stable_output_fields: + # name ("agents/{genie_agent_id}") is derived from the immutable ID, so it does + # not change on an in-place update; see the stable_output_fields doc in config.go. + - field: name + +ignore_remote_changes: + # name is derived server-side from genie_agent_id and is not user input, so it + # is not in the bundle schema and its remote value is never compared. + - field: name + reason: output_only diff --git a/bundle/direct/dresources/genie_agent.go b/bundle/direct/dresources/genie_agent.go new file mode 100644 index 00000000000..02a84cb8110 --- /dev/null +++ b/bundle/direct/dresources/genie_agent.go @@ -0,0 +1,151 @@ +package dresources + +import ( + "context" + "fmt" + "strings" + + "github.com/databricks/cli/bundle/config/resources" + "github.com/databricks/databricks-sdk-go" + "github.com/databricks/databricks-sdk-go/common/types/fieldmask" + "github.com/databricks/databricks-sdk-go/service/genieagents" +) + +// ResourceGenieAgent manages Genie Agents (the AI/BI Genie assistant surface). +// It mirrors ResourceGenieSpace, which manages the same backend object through +// the older Genie Spaces API; declaring the same object under both resource +// types is unsupported. Bind of an object created through either surface works, +// since both address it by the same id. +// +// API: https://docs.databricks.com/api/workspace/genieagents +// Terraform: databricks_genie_agent +// +// Identity: the engine tracks the bare genie_agent_id; the API addresses the +// resource by its full name (agents/{genie_agent_id}). genie_agent_id is +// optional on create (server-assigned when omitted) and immutable, so a local +// change recreates. +const genieAgentNamePrefix = "agents/" + +type ResourceGenieAgent struct { + client *databricks.WorkspaceClient +} + +func (*ResourceGenieAgent) New(client *databricks.WorkspaceClient) *ResourceGenieAgent { + return &ResourceGenieAgent{client: client} +} + +func (*ResourceGenieAgent) PrepareState(input *resources.GenieAgent) *resources.GenieAgentConfig { + state := input.GenieAgentConfig + // Server-derived fields are never user input. Zeroing them keeps the saved + // state and local diffs to the authored body; their remote values are read by + // DoRead and skipped via ignore_remote_changes. + state.Name = "" + state.Etag = "" + state.CreateTime = nil + state.UpdateTime = nil + state.EffectiveParentPath = "" + return &state +} + +// responseToGenieAgentConfig converts a returned GenieAgent into remote state. +// The API returns parent_path exactly as submitted; effective_parent_path may +// omit /Workspace. +func responseToGenieAgentConfig(agent *genieagents.GenieAgent) *resources.GenieAgentConfig { + return &resources.GenieAgentConfig{ + GenieAgent: *agent, + GenieAgentId: strings.TrimPrefix(agent.Name, genieAgentNamePrefix), + } +} + +func (r *ResourceGenieAgent) DoRead(ctx context.Context, id string) (*resources.GenieAgentConfig, error) { + agent, err := r.client.GenieAgents.GetGenieAgent(ctx, genieagents.GetGenieAgentRequest{ + Name: genieAgentNamePrefix + id, + }) + if err != nil { + return nil, err + } + return responseToGenieAgentConfig(agent), nil +} + +// DoCreate deliberately issues up to three SDK calls — create, mkdirs, create — +// an exception to the one-SDK-call-per-DoCreate rule in +// bundle/direct/dresources/README.md. The default parent_path is the bundle's +// workspace resource folder (workspace.resource_path), which does not exist on +// a first deploy, so create retries once after mkdirs. ResourceGenieSpace.DoCreate +// handles the same condition the same way; isMissingGenieParentPathError +// recognises the two shapes the Genie backend uses for a missing folder. The +// Agents API is expected to surface the standard 404 RESOURCE_DOES_NOT_EXIST +// shape, which apierr.IsMissing catches; the legacy 400 shape is kept for +// parity with genie_spaces on the same backend object. +func (r *ResourceGenieAgent) DoCreate(ctx context.Context, config *resources.GenieAgentConfig) (string, *resources.GenieAgentConfig, error) { + req := genieagents.CreateGenieAgentRequest{ + GenieAgent: config.GenieAgent, + GenieAgentId: config.GenieAgentId, + ForceSendFields: nil, + } + + resp, err := r.client.GenieAgents.CreateGenieAgent(ctx, req) + if err != nil && isMissingGenieParentPathError(err) { + err = r.client.Workspace.MkdirsByPath(ctx, config.ParentPath) + if err != nil { + return "", nil, fmt.Errorf("failed to create parent directory: %w", err) + } + resp, err = r.client.GenieAgents.CreateGenieAgent(ctx, req) + } + if err != nil { + return "", nil, err + } + + return strings.TrimPrefix(resp.Name, genieAgentNamePrefix), responseToGenieAgentConfig(resp), nil +} + +// DoUpdate sends update_mask "*": the API documents that the wildcard replaces +// every updatable field (display_name, description, warehouse_id, definition, +// parent_path), taking each field's value from the body even when unset there, +// so removing a field from config clears it. definition is replaced as a whole; +// paths within it are not supported. +// +// The etag is the one from the remote read the plan was built on, so the update +// fails if the definition was edited after planning instead of overwriting it. +// Metadata edits do not change the etag, so they never trigger this. Drift is +// otherwise detected on read by comparing the full config against the GET response. +func (r *ResourceGenieAgent) DoUpdate(ctx context.Context, id string, config *resources.GenieAgentConfig, planEntry *PlanEntry) (*resources.GenieAgentConfig, error) { + resp, err := r.client.GenieAgents.UpdateGenieAgent(ctx, genieagents.UpdateGenieAgentRequest{ + GenieAgent: config.GenieAgent, + Name: genieAgentNamePrefix + id, + UpdateMask: fieldmask.FieldMask{Paths: []string{"*"}}, + Etag: plannedGenieAgentEtag(planEntry), + ForceSendFields: nil, + }) + if err != nil { + return nil, err + } + return responseToGenieAgentConfig(resp), nil +} + +// plannedGenieAgentEtag returns the etag from the plan's remote read. An empty +// etag sends no precondition, which only happens when the plan carries no remote state. +func plannedGenieAgentEtag(planEntry *PlanEntry) string { + if planEntry == nil { + return "" + } + remote, ok := planEntry.RemoteState.(*resources.GenieAgentConfig) + if !ok || remote == nil { + return "" + } + return remote.Etag +} + +// DoDelete sends no etag. The engine passes only the persisted state here, and +// PrepareState does not persist the etag, so no plan-time etag is available. Using +// the etag from the last deploy instead would make destroy fail after any +// definition edit made since then. +func (r *ResourceGenieAgent) DoDelete(ctx context.Context, id string, _ *resources.GenieAgentConfig) error { + // Delete moves the agent to trash; NOT_FOUND afterwards means it is gone + // (the trash is not readable through this API). + return r.client.GenieAgents.DeleteGenieAgent(ctx, genieagents.DeleteGenieAgentRequest{ + Name: genieAgentNamePrefix + id, + Etag: "", + ForceSendFields: nil, + }) +} diff --git a/bundle/direct/dresources/genie_agent_test.go b/bundle/direct/dresources/genie_agent_test.go new file mode 100644 index 00000000000..90d0e82b2b0 --- /dev/null +++ b/bundle/direct/dresources/genie_agent_test.go @@ -0,0 +1,85 @@ +package dresources + +import ( + "testing" + + "github.com/databricks/cli/bundle/config/resources" + "github.com/databricks/cli/bundle/deployplan" + "github.com/databricks/databricks-sdk-go/common/types/fieldmask" + "github.com/databricks/databricks-sdk-go/experimental/mocks" + "github.com/databricks/databricks-sdk-go/service/genieagents" + "github.com/stretchr/testify/require" +) + +// The plan's remote read carries the etag the update is guarded by. The +// config (and so the persisted state) never carries it, so the etag must come +// from the plan entry. +func TestGenieAgentDoUpdateSendsPlannedEtag(t *testing.T) { + ctx := t.Context() + m := mocks.NewMockWorkspaceClient(t) + r := (&ResourceGenieAgent{}).New(m.WorkspaceClient) + + config := &resources.GenieAgentConfig{ + DisplayName: "new", + WarehouseId: "wh", + } + entry := &deployplan.PlanEntry{ + RemoteState: &resources.GenieAgentConfig{Etag: "etag-3"}, + } + + m.GetMockGenieAgentsAPI().EXPECT(). + UpdateGenieAgent(ctx, genieagents.UpdateGenieAgentRequest{ + Etag: "etag-3", + GenieAgent: config.GenieAgent, + Name: "agents/agent-id", + UpdateMask: fieldmask.FieldMask{Paths: []string{"*"}}, + }). + Return(&genieagents.GenieAgent{Name: "agents/agent-id", DisplayName: "new", Etag: "etag-4"}, nil). + Once() + + remote, err := r.DoUpdate(ctx, "agent-id", config, entry) + require.NoError(t, err) + require.Equal(t, "agent-id", remote.GenieAgentId) + require.Equal(t, "new", remote.DisplayName) +} + +// Without a plan-time remote read there is nothing to guard the update with. +func TestGenieAgentDoUpdateWithoutPlannedRemoteSendsNoEtag(t *testing.T) { + ctx := t.Context() + m := mocks.NewMockWorkspaceClient(t) + r := (&ResourceGenieAgent{}).New(m.WorkspaceClient) + + config := &resources.GenieAgentConfig{DisplayName: "new", WarehouseId: "wh"} + + m.GetMockGenieAgentsAPI().EXPECT(). + UpdateGenieAgent(ctx, genieagents.UpdateGenieAgentRequest{ + GenieAgent: config.GenieAgent, + Name: "agents/agent-id", + UpdateMask: fieldmask.FieldMask{Paths: []string{"*"}}, + }). + Return(&genieagents.GenieAgent{Name: "agents/agent-id"}, nil). + Once() + + _, err := r.DoUpdate(ctx, "agent-id", config, &deployplan.PlanEntry{}) + require.NoError(t, err) +} + +// Server-derived fields must not reach the persisted state or the local diff. +func TestGenieAgentPrepareStateZeroesServerDerivedFields(t *testing.T) { + input := &resources.GenieAgent{ + GenieAgentId: "agent-id", + Name: "agents/agent-id", + Etag: "etag-3", + EffectiveParentPath: "/Users/someone", + DisplayName: "name", + } + + state := (&ResourceGenieAgent{}).PrepareState(input) + require.Empty(t, state.Name) + require.Empty(t, state.Etag) + require.Empty(t, state.EffectiveParentPath) + require.Nil(t, state.CreateTime) + require.Nil(t, state.UpdateTime) + require.Equal(t, "name", state.DisplayName) + require.Equal(t, "agent-id", state.GenieAgentId) +} diff --git a/bundle/direct/dresources/permissions.go b/bundle/direct/dresources/permissions.go index 7f2eb0dbf04..e9657822218 100644 --- a/bundle/direct/dresources/permissions.go +++ b/bundle/direct/dresources/permissions.go @@ -21,6 +21,7 @@ var permissionResourceToObjectType = map[string]string{ "instance_pools": "/instance-pools/", "dashboards": "/dashboards/", "genie_spaces": "/genie/", + "genie_agents": "/genie/", "database_instances": "/database-instances/", "postgres_projects": "/database-projects/", "jobs": "/jobs/", diff --git a/bundle/internal/annotation/preview.go b/bundle/internal/annotation/preview.go index 33392256e48..b6b68f14f5f 100644 --- a/bundle/internal/annotation/preview.go +++ b/bundle/internal/annotation/preview.go @@ -27,6 +27,7 @@ func PreviewTag(stage clijson.LaunchStage) string { // fully-qualified Go type paths (PkgPath + "." + Name), matching getPath in // bundle/internal/schema. var launchStageOverrides = map[string]clijson.LaunchStage{ + "github.com/databricks/cli/bundle/config/resources.GenieAgent": clijson.LaunchStagePrivatePreview, // The Genie Agents API is at Private Preview. "github.com/databricks/cli/bundle/config/resources.PostgresBranch": clijson.LaunchStagePublicBeta, "github.com/databricks/cli/bundle/config/resources.PostgresCatalog": clijson.LaunchStagePublicBeta, "github.com/databricks/cli/bundle/config/resources.PostgresDataApi": clijson.LaunchStagePrivatePreview, // The Data API is at Private Preview, below its siblings' Beta. diff --git a/bundle/internal/schema/annotations.yml b/bundle/internal/schema/annotations.yml index db3cc5585e3..5317e3ce0a6 100644 --- a/bundle/internal/schema/annotations.yml +++ b/bundle/internal/schema/annotations.yml @@ -993,6 +993,48 @@ resources: "time_window": "description": |- PLACEHOLDER + "genie_agents": + "description": |- + The Genie agent definitions for the bundle, where each key is the name of the agent. + "$fields": + "definition": + "description": |- + The definition of the Genie Agent: its sample questions, data sources, instructions, and benchmarks. Must set at least one field. Replaced as a whole on update. + "description": + "description": |- + Description of the Genie Agent. The maximum length is 4,096 characters. + "display_name": + "description": |- + Display name of the Genie Agent. Must be unique within its folder. The maximum length is 63 characters. + "genie_agent_id": + "description": |- + Client-specified ID for the agent: 32 lowercase hexadecimal characters (a UUID without dashes), not all zeros. Assigned by the server if omitted. Immutable: changing this field recreates the resource. After bundle destroy or deletion, the agent remains in trash with its ID reserved until permanently removed. Omit this field to let the server assign an ID. + "lifecycle": + "description": |- + Settings that control the deployment lifecycle of the resource, such as preventing it from being destroyed. + "parent_path": + "description": |- + Workspace folder in which to create the Genie Agent. Defaults to the bundle's workspace resource path (${workspace.resource_path}). On update, setting it moves the agent and clearing it does not. + "permissions": + "description": |- + The permissions to apply to this resource. + "markdown_description": |- + A Sequence of permissions to apply to this resource, where each item grants a permission `level` to a single `user_name`, `group_name`, or `service_principal_name`. A principal cannot be set in both a resource's `permissions` and the top-level `permissions` mapping. + + See [\_](/dev-tools/bundles/settings.md#permissions) and [\_](/dev-tools/bundles/permissions.md). + "markdown_examples": |- + ```yaml + permissions: + - level: CAN_VIEW + group_name: test-group + - level: CAN_MANAGE + user_name: someone@example.com + - level: CAN_RUN + service_principal_name: 123456-abcdef + ``` + "warehouse_id": + "description": |- + ID of the SQL warehouse used by this Genie Agent. "genie_spaces": "description": |- PLACEHOLDER diff --git a/bundle/internal/schema/main.go b/bundle/internal/schema/main.go index 01a743933b2..aae148ecd28 100644 --- a/bundle/internal/schema/main.go +++ b/bundle/internal/schema/main.go @@ -120,6 +120,19 @@ func removeJobsFields(typ reflect.Type, s jsonschema.Schema) jsonschema.Schema { return s } +func removeGenieAgentFields(typ reflect.Type, s jsonschema.Schema) jsonschema.Schema { + switch typ { + case reflect.TypeFor[resources.GenieAgent](): + // The SDK does not mark name as output-only, but the server derives it from + // genie_agent_id, so it is not exposed to the user. + delete(s.Properties, "name") + default: + // Do nothing + } + + return s +} + func removePipelineFields(typ reflect.Type, s jsonschema.Schema) jsonschema.Schema { switch typ { case reflect.TypeFor[resources.Pipeline](): @@ -235,7 +248,7 @@ func main() { // only documents fields the generated schema actually contains. Both the // generator and the detached-annotation test use it to stay in lockstep. func configTypeGraph() (*typeGraph, error) { - return newTypeGraph(reflect.TypeFor[config.Root](), removeJobsFields, removePipelineFields) + return newTypeGraph(reflect.TypeFor[config.Root](), removeJobsFields, removePipelineFields, removeGenieAgentFields) } func generateSchema(workdir, outputFile, cliJSONFile string, docsMode bool) { @@ -284,6 +297,7 @@ func generateSchema(workdir, outputFile, cliJSONFile string, docsMode bool) { transforms := []func(reflect.Type, jsonschema.Schema) jsonschema.Schema{ removeJobsFields, removePipelineFields, + removeGenieAgentFields, removeDeploymentFields, makeVolumeTypeOptional, a.addAnnotations, diff --git a/bundle/internal/validation/generated/enum_fields.go b/bundle/internal/validation/generated/enum_fields.go index 879c5f475d7..8a29bd6de04 100644 --- a/bundle/internal/validation/generated/enum_fields.go +++ b/bundle/internal/validation/generated/enum_fields.go @@ -87,6 +87,10 @@ var EnumFields = map[string][]string{ "resources.features.*.source.request_source.flat_schema.fields[*].data_type": {"BINARY", "BOOLEAN", "DATE", "DECIMAL", "DOUBLE", "FLOAT", "INTEGER", "LONG", "SHORT", "STRING", "TIMESTAMP"}, "resources.features.*.source.sdp_source.pipeline_state": {"ERROR", "PENDING", "RESOLVED"}, + "resources.genie_agents.*.definition.benchmarks.questions[*].answer[*].format": {"GENIE_AGENT_BENCHMARK_ANSWER_FORMAT_SQL"}, + "resources.genie_agents.*.definition.instructions.join_specs[*].relationship_type": {"GENIE_AGENT_JOIN_RELATIONSHIP_TYPE_MANY_TO_MANY", "GENIE_AGENT_JOIN_RELATIONSHIP_TYPE_MANY_TO_ONE", "GENIE_AGENT_JOIN_RELATIONSHIP_TYPE_ONE_TO_MANY", "GENIE_AGENT_JOIN_RELATIONSHIP_TYPE_ONE_TO_ONE"}, + "resources.genie_agents.*.permissions[*].level": {"CAN_ATTACH_TO", "CAN_BIND", "CAN_CREATE", "CAN_CREATE_APP", "CAN_EDIT", "CAN_EDIT_METADATA", "CAN_MANAGE", "CAN_MANAGE_PRODUCTION_VERSIONS", "CAN_MANAGE_RUN", "CAN_MANAGE_STAGING_VERSIONS", "CAN_MONITOR", "CAN_MONITOR_ONLY", "CAN_QUERY", "CAN_READ", "CAN_RESTART", "CAN_RUN", "CAN_USE", "CAN_VIEW", "CAN_VIEW_METADATA", "IS_OWNER"}, + "resources.genie_spaces.*.permissions[*].level": {"CAN_ATTACH_TO", "CAN_BIND", "CAN_CREATE", "CAN_CREATE_APP", "CAN_EDIT", "CAN_EDIT_METADATA", "CAN_MANAGE", "CAN_MANAGE_PRODUCTION_VERSIONS", "CAN_MANAGE_RUN", "CAN_MANAGE_STAGING_VERSIONS", "CAN_MONITOR", "CAN_MONITOR_ONLY", "CAN_QUERY", "CAN_READ", "CAN_RESTART", "CAN_RUN", "CAN_USE", "CAN_VIEW", "CAN_VIEW_METADATA", "IS_OWNER"}, "resources.instance_pools.*.aws_attributes.availability": {"ON_DEMAND", "SPOT"}, diff --git a/bundle/internal/validation/generated/required_fields.go b/bundle/internal/validation/generated/required_fields.go index 78b761f02d7..79bdb884e47 100644 --- a/bundle/internal/validation/generated/required_fields.go +++ b/bundle/internal/validation/generated/required_fields.go @@ -152,6 +152,27 @@ var RequiredFields = map[string][]string{ "resources.features.*.time_window.tumbling": {"window_duration"}, "resources.features.*.timeseries_column": {"name"}, + "resources.genie_agents.*": {"definition", "display_name", "warehouse_id"}, + "resources.genie_agents.*.definition.benchmarks.questions[*]": {"id", "question"}, + "resources.genie_agents.*.definition.benchmarks.questions[*].answer[*]": {"content", "format"}, + "resources.genie_agents.*.definition.config.sample_questions[*]": {"id", "question"}, + "resources.genie_agents.*.definition.data_sources.mcp_connections[*]": {"mcp_connection"}, + "resources.genie_agents.*.definition.data_sources.tables[*]": {"identifier"}, + "resources.genie_agents.*.definition.data_sources.tables[*].column_configs[*]": {"column"}, + "resources.genie_agents.*.definition.data_sources.volumes[*]": {"path"}, + "resources.genie_agents.*.definition.instructions.example_question_sqls[*]": {"id", "question", "sql"}, + "resources.genie_agents.*.definition.instructions.example_question_sqls[*].parameters[*]": {"name"}, + "resources.genie_agents.*.definition.instructions.join_specs[*]": {"id", "left", "right", "sql"}, + "resources.genie_agents.*.definition.instructions.join_specs[*].left": {"identifier"}, + "resources.genie_agents.*.definition.instructions.join_specs[*].right": {"identifier"}, + "resources.genie_agents.*.definition.instructions.sql_functions[*]": {"id", "identifier"}, + "resources.genie_agents.*.definition.instructions.sql_snippets.expressions[*]": {"id", "sql"}, + "resources.genie_agents.*.definition.instructions.sql_snippets.filters[*]": {"id", "sql"}, + "resources.genie_agents.*.definition.instructions.sql_snippets.measures[*]": {"id", "sql"}, + "resources.genie_agents.*.definition.instructions.text_instructions[*]": {"content", "id"}, + "resources.genie_agents.*.lifecycle.depends_on[*]": {"resource"}, + "resources.genie_agents.*.permissions[*]": {"level"}, + "resources.genie_spaces.*.lifecycle.depends_on[*]": {"resource"}, "resources.genie_spaces.*.permissions[*]": {"level"}, diff --git a/bundle/phases/deploy.go b/bundle/phases/deploy.go index 1f6831281ea..6eb4d01248f 100644 --- a/bundle/phases/deploy.go +++ b/bundle/phases/deploy.go @@ -40,6 +40,7 @@ var deployApprovalGroups = []approvalGroup{ {group: "postgres_databases", message: deleteOrRecreatePostgresDatabaseMessage}, {group: "vector_search_indexes", message: deleteOrRecreateVectorSearchIndexMessage}, {group: "genie_spaces", message: deleteOrRecreateGenieSpaceMessage}, + {group: "genie_agents", message: deleteOrRecreateGenieAgentMessage}, {group: "materialization_sets", message: deleteOrRecreateMaterializationSetMessage}, {group: "features", message: deleteOrRecreateFeatureMessage}, {group: "feature_specs", message: deleteOrRecreateFeatureSpecMessage}, diff --git a/bundle/phases/destroy.go b/bundle/phases/destroy.go index c5d2de0980f..ba4ab4b9192 100644 --- a/bundle/phases/destroy.go +++ b/bundle/phases/destroy.go @@ -50,6 +50,7 @@ var destroyApprovalGroups = []approvalGroup{ {group: "postgres_databases", message: deletePostgresDatabaseMessage}, {group: "vector_search_indexes", message: deleteVectorSearchIndexMessage}, {group: "genie_spaces", message: deleteGenieSpaceMessage}, + {group: "genie_agents", message: deleteGenieAgentMessage}, {group: "features", message: deleteFeatureMessage}, {group: "feature_specs", message: deleteFeatureSpecMessage}, } diff --git a/bundle/phases/messages.go b/bundle/phases/messages.go index 535d8086b59..616f0ae5c12 100644 --- a/bundle/phases/messages.go +++ b/bundle/phases/messages.go @@ -50,6 +50,10 @@ index drops all upserted vectors. Both can be expensive to rebuild:` This action will result in the deletion or recreation of the following Genie spaces. The conversation history attached to a deleted space is permanently lost:` + deleteOrRecreateGenieAgentMessage = ` +This action will result in the deletion or recreation of the following Genie agents. +The conversation history attached to a deleted agent is permanently lost:` + deleteOrRecreateMaterializationSetMessage = ` This action will result in the deletion or recreation of the following materialization sets. Every materialized feature in a recreated set is dropped and recomputed from scratch, including @@ -117,6 +121,9 @@ For Direct Access indexes, all upserted vectors are permanently lost:` deleteGenieSpaceMessage = `This action will result in the deletion of the following Genie spaces. The conversation history attached to them is permanently lost:` + deleteGenieAgentMessage = `This action will result in the deletion of the following Genie agents. +The conversation history attached to them is permanently lost:` + deleteFeatureMessage = `This action will result in the deletion of the following Feature Views. Deleting a Feature View that a FeatureSpec serves is not blocked, and leaves the FeatureSpec stale:` diff --git a/bundle/schema/jsonschema.json b/bundle/schema/jsonschema.json index 14fcb5e83ad..7906e270e6a 100644 --- a/bundle/schema/jsonschema.json +++ b/bundle/schema/jsonschema.json @@ -1234,6 +1234,71 @@ } ] }, + "resources.GenieAgent": { + "oneOf": [ + { + "type": "object", + "description": "[Private Preview] A Genie Agent resource.", + "properties": { + "definition": { + "description": "[Private Preview] The definition of the Genie Agent: its sample questions, data sources, instructions, and benchmarks. Must set at least one field. Replaced as a whole on update.", + "$ref": "#/$defs/github.com/databricks/databricks-sdk-go/service/genieagents.GenieAgentDefinition", + "x-databricks-launch-stage": "PRIVATE_PREVIEW", + "doNotSuggest": true + }, + "description": { + "description": "[Private Preview] Description of the Genie Agent. The maximum length is 4,096 characters.", + "$ref": "#/$defs/string", + "x-databricks-launch-stage": "PRIVATE_PREVIEW", + "doNotSuggest": true + }, + "display_name": { + "description": "[Private Preview] Display name of the Genie Agent. Must be unique within its folder. The maximum length is 63 characters.", + "$ref": "#/$defs/string", + "x-databricks-launch-stage": "PRIVATE_PREVIEW", + "doNotSuggest": true + }, + "genie_agent_id": { + "description": "Client-specified ID for the agent: 32 lowercase hexadecimal characters (a UUID without dashes), not all zeros. Assigned by the server if omitted. Immutable: changing this field recreates the resource. After bundle destroy or deletion, the agent remains in trash with its ID reserved until permanently removed. Omit this field to let the server assign an ID.", + "$ref": "#/$defs/string" + }, + "lifecycle": { + "description": "Settings that control the deployment lifecycle of the resource, such as preventing it from being destroyed.", + "$ref": "#/$defs/github.com/databricks/cli/bundle/config/resources.Lifecycle" + }, + "parent_path": { + "description": "[Private Preview] Workspace folder in which to create the Genie Agent. Defaults to the bundle's workspace resource path (${workspace.resource_path}). On update, setting it moves the agent and clearing it does not.", + "$ref": "#/$defs/string", + "x-databricks-launch-stage": "PRIVATE_PREVIEW", + "doNotSuggest": true + }, + "permissions": { + "description": "The permissions to apply to this resource.", + "$ref": "#/$defs/slice/github.com/databricks/cli/bundle/config/resources.Permission", + "markdownDescription": "A Sequence of permissions to apply to this resource, where each item grants a permission `level` to a single `user_name`, `group_name`, or `service_principal_name`. A principal cannot be set in both a resource's `permissions` and the top-level `permissions` mapping.\n\nSee [permissions](https://docs.databricks.com/dev-tools/bundles/settings.html#permissions) and [link](https://docs.databricks.com/dev-tools/bundles/permissions.html)." + }, + "warehouse_id": { + "description": "[Private Preview] ID of the SQL warehouse used by this Genie Agent.", + "$ref": "#/$defs/string", + "x-databricks-launch-stage": "PRIVATE_PREVIEW", + "doNotSuggest": true + } + }, + "additionalProperties": false, + "required": [ + "definition", + "display_name", + "warehouse_id" + ], + "x-databricks-launch-stage": "PRIVATE_PREVIEW", + "doNotSuggest": true + }, + { + "type": "string", + "pattern": "\\$\\{(var(\\._*\\p{L}+([-_]*[\\p{L}\\p{N}]+)*(\\[[0-9]+\\])*)+)\\}" + } + ] + }, "resources.GenieSpace": { "oneOf": [ { @@ -4425,6 +4490,10 @@ "$ref": "#/$defs/map/github.com/databricks/cli/bundle/config/resources.Feature", "markdownDescription": "The feature definitions for the bundle, where each key is the name of the feature." }, + "genie_agents": { + "description": "The Genie agent definitions for the bundle, where each key is the name of the agent.", + "$ref": "#/$defs/map/github.com/databricks/cli/bundle/config/resources.GenieAgent" + }, "genie_spaces": { "$ref": "#/$defs/map/github.com/databricks/cli/bundle/config/resources.GenieSpace" }, @@ -9840,24 +9909,954 @@ } ] }, - "dataquality.NotificationSettings": { + "dataquality.NotificationSettings": { + "oneOf": [ + { + "type": "object", + "description": "Settings for sending notifications on the data quality monitoring.", + "properties": { + "on_failure": { + "description": "Destinations to send notifications on failure/timeout.", + "$ref": "#/$defs/github.com/databricks/databricks-sdk-go/service/dataquality.NotificationDestination", + "x-databricks-launch-stage": "GA" + }, + "on_unhealthy_table": { + "description": "Recipients to notify when anomaly detection finds unhealthy tables in the schema. Each\nrecipient gets one notification per important unhealthy table. Only supported on schema\nmonitors, via `anomaly_detection_config`.", + "$ref": "#/$defs/github.com/databricks/databricks-sdk-go/service/dataquality.NotificationDestination", + "x-databricks-launch-stage": "GA" + } + }, + "additionalProperties": false + }, + { + "type": "string", + "pattern": "\\$\\{(var(\\._*\\p{L}+([-_]*[\\p{L}\\p{N}]+)*(\\[[0-9]+\\])*)+)\\}" + } + ] + }, + "dataquality.SnapshotConfig": { + "oneOf": [ + { + "type": "object", + "description": "Snapshot analysis configuration.", + "additionalProperties": false + }, + { + "type": "string", + "pattern": "\\$\\{(var(\\._*\\p{L}+([-_]*[\\p{L}\\p{N}]+)*(\\[[0-9]+\\])*)+)\\}" + } + ] + }, + "dataquality.TimeSeriesConfig": { + "oneOf": [ + { + "type": "object", + "description": "Time series analysis configuration.", + "properties": { + "granularities": { + "description": "List of granularities to use when aggregating data into time windows based on their timestamp.", + "$ref": "#/$defs/slice/github.com/databricks/databricks-sdk-go/service/dataquality.AggregationGranularity", + "x-databricks-launch-stage": "GA" + }, + "timestamp_column": { + "description": "Column for the timestamp.", + "$ref": "#/$defs/string", + "x-databricks-launch-stage": "GA" + } + }, + "additionalProperties": false, + "required": [ + "granularities", + "timestamp_column" + ] + }, + { + "type": "string", + "pattern": "\\$\\{(var(\\._*\\p{L}+([-_]*[\\p{L}\\p{N}]+)*(\\[[0-9]+\\])*)+)\\}" + } + ] + }, + "genieagents.GenieAgentBenchmarkAnswer": { + "oneOf": [ + { + "type": "object", + "description": "The expected answer to a benchmark question.", + "properties": { + "content": { + "description": "[Private Preview] The answer.", + "$ref": "#/$defs/string", + "x-databricks-launch-stage": "PRIVATE_PREVIEW", + "doNotSuggest": true + }, + "format": { + "description": "[Private Preview] The format of the answer.", + "$ref": "#/$defs/github.com/databricks/databricks-sdk-go/service/genieagents.GenieAgentBenchmarkAnswerFormat", + "x-databricks-launch-stage": "PRIVATE_PREVIEW", + "doNotSuggest": true + } + }, + "additionalProperties": false, + "required": [ + "content", + "format" + ] + }, + { + "type": "string", + "pattern": "\\$\\{(var(\\._*\\p{L}+([-_]*[\\p{L}\\p{N}]+)*(\\[[0-9]+\\])*)+)\\}" + } + ] + }, + "genieagents.GenieAgentBenchmarkAnswerFormat": { + "oneOf": [ + { + "type": "string", + "description": "The format of a benchmark answer.", + "enum": [ + "GENIE_AGENT_BENCHMARK_ANSWER_FORMAT_SQL" + ], + "enumDescriptions": [ + "[Private Preview]" + ] + }, + { + "type": "string", + "pattern": "\\$\\{(var(\\._*\\p{L}+([-_]*[\\p{L}\\p{N}]+)*(\\[[0-9]+\\])*)+)\\}" + } + ] + }, + "genieagents.GenieAgentBenchmarkQuestion": { + "oneOf": [ + { + "type": "object", + "description": "A benchmark question with its expected answer.", + "properties": { + "answer": { + "description": "[Private Preview] The expected answer. At most one answer is supported; omit it when the question has no\nexpected answer.", + "$ref": "#/$defs/slice/github.com/databricks/databricks-sdk-go/service/genieagents.GenieAgentBenchmarkAnswer", + "x-databricks-launch-stage": "PRIVATE_PREVIEW", + "doNotSuggest": true + }, + "evaluation_note": { + "description": "[Private Preview] Notes on how to evaluate answers to the question.", + "$ref": "#/$defs/string", + "x-databricks-launch-stage": "PRIVATE_PREVIEW", + "doNotSuggest": true + }, + "id": { + "description": "[Private Preview] Identifier of the question: 32 lowercase hexadecimal characters, unique within the Genie\nAgent.", + "$ref": "#/$defs/string", + "x-databricks-launch-stage": "PRIVATE_PREVIEW", + "doNotSuggest": true + }, + "question": { + "description": "[Private Preview] The question.", + "$ref": "#/$defs/string", + "x-databricks-launch-stage": "PRIVATE_PREVIEW", + "doNotSuggest": true + } + }, + "additionalProperties": false, + "required": [ + "id", + "question" + ] + }, + { + "type": "string", + "pattern": "\\$\\{(var(\\._*\\p{L}+([-_]*[\\p{L}\\p{N}]+)*(\\[[0-9]+\\])*)+)\\}" + } + ] + }, + "genieagents.GenieAgentBenchmarks": { + "oneOf": [ + { + "type": "object", + "description": "Benchmarks for evaluating a Genie Agent.", + "properties": { + "questions": { + "description": "[Private Preview] The benchmark questions, sorted by `id` in descending order.", + "$ref": "#/$defs/slice/github.com/databricks/databricks-sdk-go/service/genieagents.GenieAgentBenchmarkQuestion", + "x-databricks-launch-stage": "PRIVATE_PREVIEW", + "doNotSuggest": true + } + }, + "additionalProperties": false + }, + { + "type": "string", + "pattern": "\\$\\{(var(\\._*\\p{L}+([-_]*[\\p{L}\\p{N}]+)*(\\[[0-9]+\\])*)+)\\}" + } + ] + }, + "genieagents.GenieAgentColumnConfig": { + "oneOf": [ + { + "type": "object", + "description": "Settings for one column of a table or metric view.", + "properties": { + "column": { + "description": "[Private Preview] The name of the column. Must exist in the table or metric view.", + "$ref": "#/$defs/string", + "x-databricks-launch-stage": "PRIVATE_PREVIEW", + "doNotSuggest": true + }, + "description": { + "description": "[Private Preview] Description of the column, overriding its Unity Catalog comment.", + "$ref": "#/$defs/string", + "x-databricks-launch-stage": "PRIVATE_PREVIEW", + "doNotSuggest": true + }, + "display_name": { + "description": "[Private Preview] Display name of the column in the Genie Agent. Accepted only where column display names are\nenabled for the workspace.", + "$ref": "#/$defs/string", + "x-databricks-launch-stage": "PRIVATE_PREVIEW", + "doNotSuggest": true + }, + "enable_entity_matching": { + "description": "[Private Preview] Whether the Genie Agent indexes the column's values to match them in questions.", + "$ref": "#/$defs/bool", + "x-databricks-launch-stage": "PRIVATE_PREVIEW", + "doNotSuggest": true + }, + "enable_format_assistance": { + "description": "[Private Preview] Whether the Genie Agent samples example values from the column to learn its format.", + "$ref": "#/$defs/bool", + "x-databricks-launch-stage": "PRIVATE_PREVIEW", + "doNotSuggest": true + }, + "exclude": { + "description": "[Private Preview] Whether the column is hidden from the Genie Agent.", + "$ref": "#/$defs/bool", + "x-databricks-launch-stage": "PRIVATE_PREVIEW", + "doNotSuggest": true + }, + "synonyms": { + "description": "[Private Preview] Synonyms for the column name.", + "$ref": "#/$defs/slice/string", + "x-databricks-launch-stage": "PRIVATE_PREVIEW", + "doNotSuggest": true + } + }, + "additionalProperties": false, + "required": [ + "column" + ] + }, + { + "type": "string", + "pattern": "\\$\\{(var(\\._*\\p{L}+([-_]*[\\p{L}\\p{N}]+)*(\\[[0-9]+\\])*)+)\\}" + } + ] + }, + "genieagents.GenieAgentConfig": { + "oneOf": [ + { + "type": "object", + "description": "General settings of a Genie Agent. The warehouse, display name, and description are separate\nfields of the Genie Agent.", + "properties": { + "sample_questions": { + "description": "[Private Preview] Sample questions shown to users of the Genie Agent, sorted by `id`.", + "$ref": "#/$defs/slice/github.com/databricks/databricks-sdk-go/service/genieagents.GenieAgentSampleQuestion", + "x-databricks-launch-stage": "PRIVATE_PREVIEW", + "doNotSuggest": true + } + }, + "additionalProperties": false + }, + { + "type": "string", + "pattern": "\\$\\{(var(\\._*\\p{L}+([-_]*[\\p{L}\\p{N}]+)*(\\[[0-9]+\\])*)+)\\}" + } + ] + }, + "genieagents.GenieAgentDataSources": { + "oneOf": [ + { + "type": "object", + "description": "The data a Genie Agent can access.", + "properties": { + "mcp_connections": { + "description": "[Private Preview] Unity Catalog MCP connections, sorted by `mcp_connection`.", + "$ref": "#/$defs/slice/github.com/databricks/databricks-sdk-go/service/genieagents.GenieAgentMcpConnection", + "x-databricks-launch-stage": "PRIVATE_PREVIEW", + "doNotSuggest": true + }, + "tables": { + "description": "[Private Preview] Unity Catalog tables, views, and metric views, in the order they were added.", + "$ref": "#/$defs/slice/github.com/databricks/databricks-sdk-go/service/genieagents.GenieAgentTable", + "x-databricks-launch-stage": "PRIVATE_PREVIEW", + "doNotSuggest": true + }, + "volumes": { + "description": "[Private Preview] Unity Catalog volumes, in the order they were added.", + "$ref": "#/$defs/slice/github.com/databricks/databricks-sdk-go/service/genieagents.GenieAgentVolume", + "x-databricks-launch-stage": "PRIVATE_PREVIEW", + "doNotSuggest": true + } + }, + "additionalProperties": false + }, + { + "type": "string", + "pattern": "\\$\\{(var(\\._*\\p{L}+([-_]*[\\p{L}\\p{N}]+)*(\\[[0-9]+\\])*)+)\\}" + } + ] + }, + "genieagents.GenieAgentDefinition": { + "oneOf": [ + { + "type": "object", + "description": "The definition of a Genie Agent.", + "properties": { + "benchmarks": { + "description": "[Private Preview] Benchmarks for evaluating the quality of the Genie Agent's answers.", + "$ref": "#/$defs/github.com/databricks/databricks-sdk-go/service/genieagents.GenieAgentBenchmarks", + "x-databricks-launch-stage": "PRIVATE_PREVIEW", + "doNotSuggest": true + }, + "config": { + "description": "[Private Preview] General settings of the Genie Agent.", + "$ref": "#/$defs/github.com/databricks/databricks-sdk-go/service/genieagents.GenieAgentConfig", + "x-databricks-launch-stage": "PRIVATE_PREVIEW", + "doNotSuggest": true + }, + "data_sources": { + "description": "[Private Preview] The data the Genie Agent can access.", + "$ref": "#/$defs/github.com/databricks/databricks-sdk-go/service/genieagents.GenieAgentDataSources", + "x-databricks-launch-stage": "PRIVATE_PREVIEW", + "doNotSuggest": true + }, + "instructions": { + "description": "[Private Preview] Instructions and SQL that guide how the Genie Agent answers questions.", + "$ref": "#/$defs/github.com/databricks/databricks-sdk-go/service/genieagents.GenieAgentInstructions", + "x-databricks-launch-stage": "PRIVATE_PREVIEW", + "doNotSuggest": true + } + }, + "additionalProperties": false + }, + { + "type": "string", + "pattern": "\\$\\{(var(\\._*\\p{L}+([-_]*[\\p{L}\\p{N}]+)*(\\[[0-9]+\\])*)+)\\}" + } + ] + }, + "genieagents.GenieAgentExampleQuestionSql": { + "oneOf": [ + { + "type": "object", + "description": "An example question paired with the SQL that answers it.", + "properties": { + "id": { + "description": "[Private Preview] Identifier of the example: 32 lowercase hexadecimal characters, unique within the Genie Agent.", + "$ref": "#/$defs/string", + "x-databricks-launch-stage": "PRIVATE_PREVIEW", + "doNotSuggest": true + }, + "parameters": { + "description": "[Private Preview] Parameters used in the SQL, in the order given.", + "$ref": "#/$defs/slice/github.com/databricks/databricks-sdk-go/service/genieagents.GenieAgentSqlParameter", + "x-databricks-launch-stage": "PRIVATE_PREVIEW", + "doNotSuggest": true + }, + "question": { + "description": "[Private Preview] The question.", + "$ref": "#/$defs/string", + "x-databricks-launch-stage": "PRIVATE_PREVIEW", + "doNotSuggest": true + }, + "sql": { + "description": "[Private Preview] The SQL that answers the question.", + "$ref": "#/$defs/string", + "x-databricks-launch-stage": "PRIVATE_PREVIEW", + "doNotSuggest": true + }, + "usage_guidance": { + "description": "[Private Preview] Guidance on when to use this example.", + "$ref": "#/$defs/string", + "x-databricks-launch-stage": "PRIVATE_PREVIEW", + "doNotSuggest": true + } + }, + "additionalProperties": false, + "required": [ + "id", + "question", + "sql" + ] + }, + { + "type": "string", + "pattern": "\\$\\{(var(\\._*\\p{L}+([-_]*[\\p{L}\\p{N}]+)*(\\[[0-9]+\\])*)+)\\}" + } + ] + }, + "genieagents.GenieAgentInstructions": { + "oneOf": [ + { + "type": "object", + "description": "Instructions and SQL that guide how a Genie Agent answers questions.", + "properties": { + "example_question_sqls": { + "description": "[Private Preview] Example questions paired with the SQL that answers them.", + "$ref": "#/$defs/slice/github.com/databricks/databricks-sdk-go/service/genieagents.GenieAgentExampleQuestionSql", + "x-databricks-launch-stage": "PRIVATE_PREVIEW", + "doNotSuggest": true + }, + "join_specs": { + "description": "[Private Preview] Predefined joins between tables or metric views.", + "$ref": "#/$defs/slice/github.com/databricks/databricks-sdk-go/service/genieagents.GenieAgentJoinSpec", + "x-databricks-launch-stage": "PRIVATE_PREVIEW", + "doNotSuggest": true + }, + "sql_functions": { + "description": "[Private Preview] Unity Catalog SQL functions the generated SQL may call.", + "$ref": "#/$defs/slice/github.com/databricks/databricks-sdk-go/service/genieagents.GenieAgentSqlFunction", + "x-databricks-launch-stage": "PRIVATE_PREVIEW", + "doNotSuggest": true + }, + "sql_snippets": { + "description": "[Private Preview] Reusable SQL filters, expressions, and measures.", + "$ref": "#/$defs/github.com/databricks/databricks-sdk-go/service/genieagents.GenieAgentSqlSnippets", + "x-databricks-launch-stage": "PRIVATE_PREVIEW", + "doNotSuggest": true + }, + "text_instructions": { + "description": "[Private Preview] General text instructions. At most one text instruction is supported.", + "$ref": "#/$defs/slice/github.com/databricks/databricks-sdk-go/service/genieagents.GenieAgentTextInstruction", + "x-databricks-launch-stage": "PRIVATE_PREVIEW", + "doNotSuggest": true + } + }, + "additionalProperties": false + }, + { + "type": "string", + "pattern": "\\$\\{(var(\\._*\\p{L}+([-_]*[\\p{L}\\p{N}]+)*(\\[[0-9]+\\])*)+)\\}" + } + ] + }, + "genieagents.GenieAgentJoinRelationshipType": { + "oneOf": [ + { + "type": "string", + "description": "How the rows of the two sides of a join relate.", + "enum": [ + "GENIE_AGENT_JOIN_RELATIONSHIP_TYPE_MANY_TO_ONE", + "GENIE_AGENT_JOIN_RELATIONSHIP_TYPE_ONE_TO_MANY", + "GENIE_AGENT_JOIN_RELATIONSHIP_TYPE_ONE_TO_ONE", + "GENIE_AGENT_JOIN_RELATIONSHIP_TYPE_MANY_TO_MANY" + ], + "enumDescriptions": [ + "[Private Preview]", + "[Private Preview]", + "[Private Preview]", + "[Private Preview]" + ] + }, + { + "type": "string", + "pattern": "\\$\\{(var(\\._*\\p{L}+([-_]*[\\p{L}\\p{N}]+)*(\\[[0-9]+\\])*)+)\\}" + } + ] + }, + "genieagents.GenieAgentJoinSource": { + "oneOf": [ + { + "type": "object", + "description": "One side of a join.", + "properties": { + "alias": { + "description": "[Private Preview] The alias the join condition uses for this side.", + "$ref": "#/$defs/string", + "x-databricks-launch-stage": "PRIVATE_PREVIEW", + "doNotSuggest": true + }, + "identifier": { + "description": "[Private Preview] The full three-level name of the table or metric view.", + "$ref": "#/$defs/string", + "x-databricks-launch-stage": "PRIVATE_PREVIEW", + "doNotSuggest": true + } + }, + "additionalProperties": false, + "required": [ + "identifier" + ] + }, + { + "type": "string", + "pattern": "\\$\\{(var(\\._*\\p{L}+([-_]*[\\p{L}\\p{N}]+)*(\\[[0-9]+\\])*)+)\\}" + } + ] + }, + "genieagents.GenieAgentJoinSpec": { + "oneOf": [ + { + "type": "object", + "description": "A predefined join between two tables or metric views.", + "properties": { + "comment": { + "description": "[Private Preview] Description of the join's purpose.", + "$ref": "#/$defs/string", + "x-databricks-launch-stage": "PRIVATE_PREVIEW", + "doNotSuggest": true + }, + "id": { + "description": "[Private Preview] Identifier of the join: 32 lowercase hexadecimal characters, unique within the Genie Agent.", + "$ref": "#/$defs/string", + "x-databricks-launch-stage": "PRIVATE_PREVIEW", + "doNotSuggest": true + }, + "instruction": { + "description": "[Private Preview] Guidance on when to use the join.", + "$ref": "#/$defs/string", + "x-databricks-launch-stage": "PRIVATE_PREVIEW", + "doNotSuggest": true + }, + "left": { + "description": "[Private Preview] The left side of the join.", + "$ref": "#/$defs/github.com/databricks/databricks-sdk-go/service/genieagents.GenieAgentJoinSource", + "x-databricks-launch-stage": "PRIVATE_PREVIEW", + "doNotSuggest": true + }, + "relationship_type": { + "description": "[Private Preview] How the rows of the two sides relate.", + "$ref": "#/$defs/github.com/databricks/databricks-sdk-go/service/genieagents.GenieAgentJoinRelationshipType", + "x-databricks-launch-stage": "PRIVATE_PREVIEW", + "doNotSuggest": true + }, + "right": { + "description": "[Private Preview] The right side of the join.", + "$ref": "#/$defs/github.com/databricks/databricks-sdk-go/service/genieagents.GenieAgentJoinSource", + "x-databricks-launch-stage": "PRIVATE_PREVIEW", + "doNotSuggest": true + }, + "sql": { + "description": "[Private Preview] The join condition, for example `orders.customer_id = customers.id`.", + "$ref": "#/$defs/string", + "x-databricks-launch-stage": "PRIVATE_PREVIEW", + "doNotSuggest": true + } + }, + "additionalProperties": false, + "required": [ + "id", + "left", + "right", + "sql" + ] + }, + { + "type": "string", + "pattern": "\\$\\{(var(\\._*\\p{L}+([-_]*[\\p{L}\\p{N}]+)*(\\[[0-9]+\\])*)+)\\}" + } + ] + }, + "genieagents.GenieAgentMcpConnection": { + "oneOf": [ + { + "type": "object", + "description": "A Unity Catalog MCP connection the Genie Agent can use.", + "properties": { + "mcp_connection": { + "description": "[Private Preview] The name of the Unity Catalog connection, for example `system.ai.google_calendar`.", + "$ref": "#/$defs/string", + "x-databricks-launch-stage": "PRIVATE_PREVIEW", + "doNotSuggest": true + } + }, + "additionalProperties": false, + "required": [ + "mcp_connection" + ] + }, + { + "type": "string", + "pattern": "\\$\\{(var(\\._*\\p{L}+([-_]*[\\p{L}\\p{N}]+)*(\\[[0-9]+\\])*)+)\\}" + } + ] + }, + "genieagents.GenieAgentSampleQuestion": { + "oneOf": [ + { + "type": "object", + "description": "A sample question shown to users of the Genie Agent.", + "properties": { + "id": { + "description": "[Private Preview] Identifier of the sample question: 32 lowercase hexadecimal characters, unique within the\nGenie Agent.", + "$ref": "#/$defs/string", + "x-databricks-launch-stage": "PRIVATE_PREVIEW", + "doNotSuggest": true + }, + "question": { + "description": "[Private Preview] The text of the question.", + "$ref": "#/$defs/string", + "x-databricks-launch-stage": "PRIVATE_PREVIEW", + "doNotSuggest": true + } + }, + "additionalProperties": false, + "required": [ + "id", + "question" + ] + }, + { + "type": "string", + "pattern": "\\$\\{(var(\\._*\\p{L}+([-_]*[\\p{L}\\p{N}]+)*(\\[[0-9]+\\])*)+)\\}" + } + ] + }, + "genieagents.GenieAgentSqlExpression": { + "oneOf": [ + { + "type": "object", + "description": "A reusable non-aggregated SQL expression (dimension).", + "properties": { + "alias": { + "description": "[Private Preview] The alias the Genie Agent uses for the expression in generated SQL.", + "$ref": "#/$defs/string", + "x-databricks-launch-stage": "PRIVATE_PREVIEW", + "doNotSuggest": true + }, + "display_name": { + "description": "[Private Preview] Display name of the expression.", + "$ref": "#/$defs/string", + "x-databricks-launch-stage": "PRIVATE_PREVIEW", + "doNotSuggest": true + }, + "id": { + "description": "[Private Preview] Identifier of the expression: 32 lowercase hexadecimal characters, unique within the Genie\nAgent.", + "$ref": "#/$defs/string", + "x-databricks-launch-stage": "PRIVATE_PREVIEW", + "doNotSuggest": true + }, + "instruction": { + "description": "[Private Preview] Guidance on when to use the expression.", + "$ref": "#/$defs/string", + "x-databricks-launch-stage": "PRIVATE_PREVIEW", + "doNotSuggest": true + }, + "sql": { + "description": "[Private Preview] The SQL of the expression.", + "$ref": "#/$defs/string", + "x-databricks-launch-stage": "PRIVATE_PREVIEW", + "doNotSuggest": true + }, + "synonyms": { + "description": "[Private Preview] Synonyms for the expression.", + "$ref": "#/$defs/slice/string", + "x-databricks-launch-stage": "PRIVATE_PREVIEW", + "doNotSuggest": true + } + }, + "additionalProperties": false, + "required": [ + "id", + "sql" + ] + }, + { + "type": "string", + "pattern": "\\$\\{(var(\\._*\\p{L}+([-_]*[\\p{L}\\p{N}]+)*(\\[[0-9]+\\])*)+)\\}" + } + ] + }, + "genieagents.GenieAgentSqlFilter": { + "oneOf": [ + { + "type": "object", + "description": "A reusable SQL filter.", + "properties": { + "display_name": { + "description": "[Private Preview] Display name of the filter.", + "$ref": "#/$defs/string", + "x-databricks-launch-stage": "PRIVATE_PREVIEW", + "doNotSuggest": true + }, + "id": { + "description": "[Private Preview] Identifier of the filter: 32 lowercase hexadecimal characters, unique within the Genie Agent.", + "$ref": "#/$defs/string", + "x-databricks-launch-stage": "PRIVATE_PREVIEW", + "doNotSuggest": true + }, + "instruction": { + "description": "[Private Preview] Guidance on when to use the filter.", + "$ref": "#/$defs/string", + "x-databricks-launch-stage": "PRIVATE_PREVIEW", + "doNotSuggest": true + }, + "sql": { + "description": "[Private Preview] The SQL of the filter.", + "$ref": "#/$defs/string", + "x-databricks-launch-stage": "PRIVATE_PREVIEW", + "doNotSuggest": true + }, + "synonyms": { + "description": "[Private Preview] Synonyms for the filter.", + "$ref": "#/$defs/slice/string", + "x-databricks-launch-stage": "PRIVATE_PREVIEW", + "doNotSuggest": true + } + }, + "additionalProperties": false, + "required": [ + "id", + "sql" + ] + }, + { + "type": "string", + "pattern": "\\$\\{(var(\\._*\\p{L}+([-_]*[\\p{L}\\p{N}]+)*(\\[[0-9]+\\])*)+)\\}" + } + ] + }, + "genieagents.GenieAgentSqlFunction": { + "oneOf": [ + { + "type": "object", + "description": "A Unity Catalog SQL function the generated SQL may call.", + "properties": { + "id": { + "description": "[Private Preview] Identifier of the entry: 32 lowercase hexadecimal characters, unique within the Genie Agent.", + "$ref": "#/$defs/string", + "x-databricks-launch-stage": "PRIVATE_PREVIEW", + "doNotSuggest": true + }, + "identifier": { + "description": "[Private Preview] The full three-level name of the function, for example `catalog.schema.function`.", + "$ref": "#/$defs/string", + "x-databricks-launch-stage": "PRIVATE_PREVIEW", + "doNotSuggest": true + } + }, + "additionalProperties": false, + "required": [ + "id", + "identifier" + ] + }, + { + "type": "string", + "pattern": "\\$\\{(var(\\._*\\p{L}+([-_]*[\\p{L}\\p{N}]+)*(\\[[0-9]+\\])*)+)\\}" + } + ] + }, + "genieagents.GenieAgentSqlMeasure": { + "oneOf": [ + { + "type": "object", + "description": "A reusable aggregated SQL measure.", + "properties": { + "alias": { + "description": "[Private Preview] The alias the Genie Agent uses for the measure in generated SQL.", + "$ref": "#/$defs/string", + "x-databricks-launch-stage": "PRIVATE_PREVIEW", + "doNotSuggest": true + }, + "display_name": { + "description": "[Private Preview] Display name of the measure.", + "$ref": "#/$defs/string", + "x-databricks-launch-stage": "PRIVATE_PREVIEW", + "doNotSuggest": true + }, + "id": { + "description": "[Private Preview] Identifier of the measure: 32 lowercase hexadecimal characters, unique within the Genie Agent.", + "$ref": "#/$defs/string", + "x-databricks-launch-stage": "PRIVATE_PREVIEW", + "doNotSuggest": true + }, + "instruction": { + "description": "[Private Preview] Guidance on when to use the measure.", + "$ref": "#/$defs/string", + "x-databricks-launch-stage": "PRIVATE_PREVIEW", + "doNotSuggest": true + }, + "sql": { + "description": "[Private Preview] The SQL of the measure.", + "$ref": "#/$defs/string", + "x-databricks-launch-stage": "PRIVATE_PREVIEW", + "doNotSuggest": true + }, + "synonyms": { + "description": "[Private Preview] Synonyms for the measure.", + "$ref": "#/$defs/slice/string", + "x-databricks-launch-stage": "PRIVATE_PREVIEW", + "doNotSuggest": true + } + }, + "additionalProperties": false, + "required": [ + "id", + "sql" + ] + }, + { + "type": "string", + "pattern": "\\$\\{(var(\\._*\\p{L}+([-_]*[\\p{L}\\p{N}]+)*(\\[[0-9]+\\])*)+)\\}" + } + ] + }, + "genieagents.GenieAgentSqlParameter": { + "oneOf": [ + { + "type": "object", + "description": "A parameter of a parameterized SQL example.", + "properties": { + "default_value": { + "description": "[Private Preview] The parameter's default value.", + "$ref": "#/$defs/github.com/databricks/databricks-sdk-go/service/genieagents.GenieAgentSqlParameterDefaultValue", + "x-databricks-launch-stage": "PRIVATE_PREVIEW", + "doNotSuggest": true + }, + "description": { + "description": "[Private Preview] Description of the parameter.", + "$ref": "#/$defs/string", + "x-databricks-launch-stage": "PRIVATE_PREVIEW", + "doNotSuggest": true + }, + "name": { + "description": "[Private Preview] The name of the parameter in the SQL.", + "$ref": "#/$defs/string", + "x-databricks-launch-stage": "PRIVATE_PREVIEW", + "doNotSuggest": true + }, + "type_hint": { + "description": "[Private Preview] The parameter's data type, for example `STRING` or `INTEGER`.", + "$ref": "#/$defs/string", + "x-databricks-launch-stage": "PRIVATE_PREVIEW", + "doNotSuggest": true + } + }, + "additionalProperties": false, + "required": [ + "name" + ] + }, + { + "type": "string", + "pattern": "\\$\\{(var(\\._*\\p{L}+([-_]*[\\p{L}\\p{N}]+)*(\\[[0-9]+\\])*)+)\\}" + } + ] + }, + "genieagents.GenieAgentSqlParameterDefaultRange": { + "oneOf": [ + { + "type": "object", + "description": "A range of default values for a SQL parameter.", + "properties": { + "max": { + "description": "[Private Preview] The upper end of the range.", + "$ref": "#/$defs/string", + "x-databricks-launch-stage": "PRIVATE_PREVIEW", + "doNotSuggest": true + }, + "min": { + "description": "[Private Preview] The lower end of the range.", + "$ref": "#/$defs/string", + "x-databricks-launch-stage": "PRIVATE_PREVIEW", + "doNotSuggest": true + } + }, + "additionalProperties": false + }, + { + "type": "string", + "pattern": "\\$\\{(var(\\._*\\p{L}+([-_]*[\\p{L}\\p{N}]+)*(\\[[0-9]+\\])*)+)\\}" + } + ] + }, + "genieagents.GenieAgentSqlParameterDefaultValue": { + "oneOf": [ + { + "type": "object", + "description": "The default value of a SQL parameter: a list of values or a range.", + "properties": { + "value_range": { + "description": "[Private Preview] The default range.", + "$ref": "#/$defs/github.com/databricks/databricks-sdk-go/service/genieagents.GenieAgentSqlParameterDefaultRange", + "x-databricks-launch-stage": "PRIVATE_PREVIEW", + "doNotSuggest": true + }, + "values": { + "description": "[Private Preview] The default values. A single default is a one-element list.", + "$ref": "#/$defs/slice/string", + "x-databricks-launch-stage": "PRIVATE_PREVIEW", + "doNotSuggest": true + } + }, + "additionalProperties": false + }, + { + "type": "string", + "pattern": "\\$\\{(var(\\._*\\p{L}+([-_]*[\\p{L}\\p{N}]+)*(\\[[0-9]+\\])*)+)\\}" + } + ] + }, + "genieagents.GenieAgentSqlSnippets": { + "oneOf": [ + { + "type": "object", + "description": "Reusable SQL snippets.", + "properties": { + "expressions": { + "description": "[Private Preview] Non-aggregated expressions (dimensions), such as `price * units`.", + "$ref": "#/$defs/slice/github.com/databricks/databricks-sdk-go/service/genieagents.GenieAgentSqlExpression", + "x-databricks-launch-stage": "PRIVATE_PREVIEW", + "doNotSuggest": true + }, + "filters": { + "description": "[Private Preview] Filters, such as `state = 'CA'`.", + "$ref": "#/$defs/slice/github.com/databricks/databricks-sdk-go/service/genieagents.GenieAgentSqlFilter", + "x-databricks-launch-stage": "PRIVATE_PREVIEW", + "doNotSuggest": true + }, + "measures": { + "description": "[Private Preview] Aggregated measures, such as `SUM(price * units)`.", + "$ref": "#/$defs/slice/github.com/databricks/databricks-sdk-go/service/genieagents.GenieAgentSqlMeasure", + "x-databricks-launch-stage": "PRIVATE_PREVIEW", + "doNotSuggest": true + } + }, + "additionalProperties": false + }, + { + "type": "string", + "pattern": "\\$\\{(var(\\._*\\p{L}+([-_]*[\\p{L}\\p{N}]+)*(\\[[0-9]+\\])*)+)\\}" + } + ] + }, + "genieagents.GenieAgentTable": { "oneOf": [ { "type": "object", - "description": "Settings for sending notifications on the data quality monitoring.", + "description": "A Unity Catalog table, view, or metric view the Genie Agent can access.", "properties": { - "on_failure": { - "description": "Destinations to send notifications on failure/timeout.", - "$ref": "#/$defs/github.com/databricks/databricks-sdk-go/service/dataquality.NotificationDestination", - "x-databricks-launch-stage": "GA" + "column_configs": { + "description": "[Private Preview] Column settings for the table, sorted by `column`.", + "$ref": "#/$defs/slice/github.com/databricks/databricks-sdk-go/service/genieagents.GenieAgentColumnConfig", + "x-databricks-launch-stage": "PRIVATE_PREVIEW", + "doNotSuggest": true }, - "on_unhealthy_table": { - "description": "Recipients to notify when anomaly detection finds unhealthy tables in the schema. Each\nrecipient gets one notification per important unhealthy table. Only supported on schema\nmonitors, via `anomaly_detection_config`.", - "$ref": "#/$defs/github.com/databricks/databricks-sdk-go/service/dataquality.NotificationDestination", - "x-databricks-launch-stage": "GA" + "description": { + "description": "[Private Preview] Description of the table.", + "$ref": "#/$defs/string", + "x-databricks-launch-stage": "PRIVATE_PREVIEW", + "doNotSuggest": true + }, + "identifier": { + "description": "[Private Preview] The full three-level name, for example `catalog.schema.table`.", + "$ref": "#/$defs/string", + "x-databricks-launch-stage": "PRIVATE_PREVIEW", + "doNotSuggest": true } }, - "additionalProperties": false + "additionalProperties": false, + "required": [ + "identifier" + ] }, { "type": "string", @@ -9865,12 +10864,30 @@ } ] }, - "dataquality.SnapshotConfig": { + "genieagents.GenieAgentTextInstruction": { "oneOf": [ { "type": "object", - "description": "Snapshot analysis configuration.", - "additionalProperties": false + "description": "A general text instruction for the Genie Agent.", + "properties": { + "content": { + "description": "[Private Preview] The text of the instruction.", + "$ref": "#/$defs/string", + "x-databricks-launch-stage": "PRIVATE_PREVIEW", + "doNotSuggest": true + }, + "id": { + "description": "[Private Preview] Identifier of the instruction: 32 lowercase hexadecimal characters, unique within the Genie\nAgent.", + "$ref": "#/$defs/string", + "x-databricks-launch-stage": "PRIVATE_PREVIEW", + "doNotSuggest": true + } + }, + "additionalProperties": false, + "required": [ + "content", + "id" + ] }, { "type": "string", @@ -9878,27 +10895,28 @@ } ] }, - "dataquality.TimeSeriesConfig": { + "genieagents.GenieAgentVolume": { "oneOf": [ { "type": "object", - "description": "Time series analysis configuration.", + "description": "A Unity Catalog volume the Genie Agent can access.", "properties": { - "granularities": { - "description": "List of granularities to use when aggregating data into time windows based on their timestamp.", - "$ref": "#/$defs/slice/github.com/databricks/databricks-sdk-go/service/dataquality.AggregationGranularity", - "x-databricks-launch-stage": "GA" + "description": { + "description": "[Private Preview] Description of the volume.", + "$ref": "#/$defs/string", + "x-databricks-launch-stage": "PRIVATE_PREVIEW", + "doNotSuggest": true }, - "timestamp_column": { - "description": "Column for the timestamp.", + "path": { + "description": "[Private Preview] The volume path, for example `/Volumes/catalog/schema/volume`. May name a directory or file\nwithin the volume.", "$ref": "#/$defs/string", - "x-databricks-launch-stage": "GA" + "x-databricks-launch-stage": "PRIVATE_PREVIEW", + "doNotSuggest": true } }, "additionalProperties": false, "required": [ - "granularities", - "timestamp_column" + "path" ] }, { @@ -22106,6 +23124,20 @@ } ] }, + "resources.GenieAgent": { + "oneOf": [ + { + "type": "object", + "additionalProperties": { + "$ref": "#/$defs/github.com/databricks/cli/bundle/config/resources.GenieAgent" + } + }, + { + "type": "string", + "pattern": "\\$\\{(var(\\._*\\p{L}+([-_]*[\\p{L}\\p{N}]+)*(\\[[0-9]+\\])*)+)\\}" + } + ] + }, "resources.GenieSpace": { "oneOf": [ { @@ -23145,6 +24177,216 @@ } ] }, + "genieagents.GenieAgentBenchmarkAnswer": { + "oneOf": [ + { + "type": "array", + "items": { + "$ref": "#/$defs/github.com/databricks/databricks-sdk-go/service/genieagents.GenieAgentBenchmarkAnswer" + } + }, + { + "type": "string", + "pattern": "\\$\\{(var(\\._*\\p{L}+([-_]*[\\p{L}\\p{N}]+)*(\\[[0-9]+\\])*)+)\\}" + } + ] + }, + "genieagents.GenieAgentBenchmarkQuestion": { + "oneOf": [ + { + "type": "array", + "items": { + "$ref": "#/$defs/github.com/databricks/databricks-sdk-go/service/genieagents.GenieAgentBenchmarkQuestion" + } + }, + { + "type": "string", + "pattern": "\\$\\{(var(\\._*\\p{L}+([-_]*[\\p{L}\\p{N}]+)*(\\[[0-9]+\\])*)+)\\}" + } + ] + }, + "genieagents.GenieAgentColumnConfig": { + "oneOf": [ + { + "type": "array", + "items": { + "$ref": "#/$defs/github.com/databricks/databricks-sdk-go/service/genieagents.GenieAgentColumnConfig" + } + }, + { + "type": "string", + "pattern": "\\$\\{(var(\\._*\\p{L}+([-_]*[\\p{L}\\p{N}]+)*(\\[[0-9]+\\])*)+)\\}" + } + ] + }, + "genieagents.GenieAgentExampleQuestionSql": { + "oneOf": [ + { + "type": "array", + "items": { + "$ref": "#/$defs/github.com/databricks/databricks-sdk-go/service/genieagents.GenieAgentExampleQuestionSql" + } + }, + { + "type": "string", + "pattern": "\\$\\{(var(\\._*\\p{L}+([-_]*[\\p{L}\\p{N}]+)*(\\[[0-9]+\\])*)+)\\}" + } + ] + }, + "genieagents.GenieAgentJoinSpec": { + "oneOf": [ + { + "type": "array", + "items": { + "$ref": "#/$defs/github.com/databricks/databricks-sdk-go/service/genieagents.GenieAgentJoinSpec" + } + }, + { + "type": "string", + "pattern": "\\$\\{(var(\\._*\\p{L}+([-_]*[\\p{L}\\p{N}]+)*(\\[[0-9]+\\])*)+)\\}" + } + ] + }, + "genieagents.GenieAgentMcpConnection": { + "oneOf": [ + { + "type": "array", + "items": { + "$ref": "#/$defs/github.com/databricks/databricks-sdk-go/service/genieagents.GenieAgentMcpConnection" + } + }, + { + "type": "string", + "pattern": "\\$\\{(var(\\._*\\p{L}+([-_]*[\\p{L}\\p{N}]+)*(\\[[0-9]+\\])*)+)\\}" + } + ] + }, + "genieagents.GenieAgentSampleQuestion": { + "oneOf": [ + { + "type": "array", + "items": { + "$ref": "#/$defs/github.com/databricks/databricks-sdk-go/service/genieagents.GenieAgentSampleQuestion" + } + }, + { + "type": "string", + "pattern": "\\$\\{(var(\\._*\\p{L}+([-_]*[\\p{L}\\p{N}]+)*(\\[[0-9]+\\])*)+)\\}" + } + ] + }, + "genieagents.GenieAgentSqlExpression": { + "oneOf": [ + { + "type": "array", + "items": { + "$ref": "#/$defs/github.com/databricks/databricks-sdk-go/service/genieagents.GenieAgentSqlExpression" + } + }, + { + "type": "string", + "pattern": "\\$\\{(var(\\._*\\p{L}+([-_]*[\\p{L}\\p{N}]+)*(\\[[0-9]+\\])*)+)\\}" + } + ] + }, + "genieagents.GenieAgentSqlFilter": { + "oneOf": [ + { + "type": "array", + "items": { + "$ref": "#/$defs/github.com/databricks/databricks-sdk-go/service/genieagents.GenieAgentSqlFilter" + } + }, + { + "type": "string", + "pattern": "\\$\\{(var(\\._*\\p{L}+([-_]*[\\p{L}\\p{N}]+)*(\\[[0-9]+\\])*)+)\\}" + } + ] + }, + "genieagents.GenieAgentSqlFunction": { + "oneOf": [ + { + "type": "array", + "items": { + "$ref": "#/$defs/github.com/databricks/databricks-sdk-go/service/genieagents.GenieAgentSqlFunction" + } + }, + { + "type": "string", + "pattern": "\\$\\{(var(\\._*\\p{L}+([-_]*[\\p{L}\\p{N}]+)*(\\[[0-9]+\\])*)+)\\}" + } + ] + }, + "genieagents.GenieAgentSqlMeasure": { + "oneOf": [ + { + "type": "array", + "items": { + "$ref": "#/$defs/github.com/databricks/databricks-sdk-go/service/genieagents.GenieAgentSqlMeasure" + } + }, + { + "type": "string", + "pattern": "\\$\\{(var(\\._*\\p{L}+([-_]*[\\p{L}\\p{N}]+)*(\\[[0-9]+\\])*)+)\\}" + } + ] + }, + "genieagents.GenieAgentSqlParameter": { + "oneOf": [ + { + "type": "array", + "items": { + "$ref": "#/$defs/github.com/databricks/databricks-sdk-go/service/genieagents.GenieAgentSqlParameter" + } + }, + { + "type": "string", + "pattern": "\\$\\{(var(\\._*\\p{L}+([-_]*[\\p{L}\\p{N}]+)*(\\[[0-9]+\\])*)+)\\}" + } + ] + }, + "genieagents.GenieAgentTable": { + "oneOf": [ + { + "type": "array", + "items": { + "$ref": "#/$defs/github.com/databricks/databricks-sdk-go/service/genieagents.GenieAgentTable" + } + }, + { + "type": "string", + "pattern": "\\$\\{(var(\\._*\\p{L}+([-_]*[\\p{L}\\p{N}]+)*(\\[[0-9]+\\])*)+)\\}" + } + ] + }, + "genieagents.GenieAgentTextInstruction": { + "oneOf": [ + { + "type": "array", + "items": { + "$ref": "#/$defs/github.com/databricks/databricks-sdk-go/service/genieagents.GenieAgentTextInstruction" + } + }, + { + "type": "string", + "pattern": "\\$\\{(var(\\._*\\p{L}+([-_]*[\\p{L}\\p{N}]+)*(\\[[0-9]+\\])*)+)\\}" + } + ] + }, + "genieagents.GenieAgentVolume": { + "oneOf": [ + { + "type": "array", + "items": { + "$ref": "#/$defs/github.com/databricks/databricks-sdk-go/service/genieagents.GenieAgentVolume" + } + }, + { + "type": "string", + "pattern": "\\$\\{(var(\\._*\\p{L}+([-_]*[\\p{L}\\p{N}]+)*(\\[[0-9]+\\])*)+)\\}" + } + ] + }, "jobs.AiClassifyFunctionLabel": { "oneOf": [ { diff --git a/bundle/statemgmt/state_load_test.go b/bundle/statemgmt/state_load_test.go index ac1c272d013..c418a86598b 100644 --- a/bundle/statemgmt/state_load_test.go +++ b/bundle/statemgmt/state_load_test.go @@ -49,6 +49,7 @@ func TestStateToBundleEmptyLocalResources(t *testing.T) { "resources.clusters.test_cluster": {ID: "1"}, "resources.dashboards.test_dashboard": {ID: "1"}, "resources.genie_spaces.test_genie_space": {ID: "1"}, + "resources.genie_agents.test_genie_agent": {ID: "1"}, "resources.apps.test_app": {ID: "app1"}, "resources.secret_scopes.test_secret_scope": {ID: "secret_scope1"}, "resources.sql_warehouses.test_sql_warehouse": {ID: "1"}, @@ -119,6 +120,9 @@ func TestStateToBundleEmptyLocalResources(t *testing.T) { assert.Equal(t, "1", config.Resources.GenieSpaces["test_genie_space"].ID) assert.Equal(t, resources.ModifiedStatusDeleted, config.Resources.GenieSpaces["test_genie_space"].ModifiedStatus) + assert.Equal(t, "1", config.Resources.GenieAgents["test_genie_agent"].ID) + assert.Equal(t, resources.ModifiedStatusDeleted, config.Resources.GenieAgents["test_genie_agent"].ModifiedStatus) + assert.Equal(t, "app1", config.Resources.Apps["test_app"].ID) assert.Empty(t, config.Resources.Apps["test_app"].Name) assert.Equal(t, resources.ModifiedStatusDeleted, config.Resources.Apps["test_app"].ModifiedStatus) @@ -323,6 +327,13 @@ func TestStateToBundleEmptyRemoteResources(t *testing.T) { }, }, }, + GenieAgents: map[string]*resources.GenieAgent{ + "test_genie_agent": { + GenieAgentConfig: resources.GenieAgentConfig{ + DisplayName: "test_genie_agent", + }, + }, + }, Apps: map[string]*resources.App{ "test_app": { App: apps.App{ @@ -557,6 +568,9 @@ func TestStateToBundleEmptyRemoteResources(t *testing.T) { assert.Empty(t, config.Resources.GenieSpaces["test_genie_space"].ID) assert.Equal(t, resources.ModifiedStatusCreated, config.Resources.GenieSpaces["test_genie_space"].ModifiedStatus) + assert.Empty(t, config.Resources.GenieAgents["test_genie_agent"].ID) + assert.Equal(t, resources.ModifiedStatusCreated, config.Resources.GenieAgents["test_genie_agent"].ModifiedStatus) + assert.Empty(t, config.Resources.Apps["test_app"].Name) assert.Equal(t, resources.ModifiedStatusCreated, config.Resources.Apps["test_app"].ModifiedStatus) @@ -846,6 +860,18 @@ func TestStateToBundleModifiedResources(t *testing.T) { }, }, }, + GenieAgents: map[string]*resources.GenieAgent{ + "test_genie_agent": { + GenieAgentConfig: resources.GenieAgentConfig{ + DisplayName: "test_genie_agent", + }, + }, + "test_genie_agent_new": { + GenieAgentConfig: resources.GenieAgentConfig{ + DisplayName: "test_genie_agent_new", + }, + }, + }, Apps: map[string]*resources.App{ "test_app": { App: apps.App{ @@ -1182,6 +1208,8 @@ func TestStateToBundleModifiedResources(t *testing.T) { "resources.dashboards.test_dashboard_old": {ID: "2"}, "resources.genie_spaces.test_genie_space": {ID: "1"}, "resources.genie_spaces.test_genie_space_old": {ID: "2"}, + "resources.genie_agents.test_genie_agent": {ID: "1"}, + "resources.genie_agents.test_genie_agent_old": {ID: "2"}, "resources.apps.test_app": {ID: "test_app"}, "resources.apps.test_app_old": {ID: "test_app_old"}, "resources.secret_scopes.test_secret_scope": {ID: "test_secret_scope"}, @@ -1338,6 +1366,13 @@ func TestStateToBundleModifiedResources(t *testing.T) { assert.Empty(t, config.Resources.GenieSpaces["test_genie_space_new"].ID) assert.Equal(t, resources.ModifiedStatusCreated, config.Resources.GenieSpaces["test_genie_space_new"].ModifiedStatus) + assert.Equal(t, "1", config.Resources.GenieAgents["test_genie_agent"].ID) + assert.Empty(t, config.Resources.GenieAgents["test_genie_agent"].ModifiedStatus) + assert.Equal(t, "2", config.Resources.GenieAgents["test_genie_agent_old"].ID) + assert.Equal(t, resources.ModifiedStatusDeleted, config.Resources.GenieAgents["test_genie_agent_old"].ModifiedStatus) + assert.Empty(t, config.Resources.GenieAgents["test_genie_agent_new"].ID) + assert.Equal(t, resources.ModifiedStatusCreated, config.Resources.GenieAgents["test_genie_agent_new"].ModifiedStatus) + assert.Equal(t, "test_app", config.Resources.Apps["test_app"].Name) assert.Empty(t, config.Resources.Apps["test_app"].ModifiedStatus) assert.Equal(t, "test_app_old", config.Resources.Apps["test_app_old"].ID) diff --git a/cmd/experimental/workspace_open_test.go b/cmd/experimental/workspace_open_test.go index dd62f40177a..0c4d917a7b3 100644 --- a/cmd/experimental/workspace_open_test.go +++ b/cmd/experimental/workspace_open_test.go @@ -69,7 +69,7 @@ func TestBuildWorkspaceURLFragmentBasedResources(t *testing.T) { func TestBuildWorkspaceURLUnknownResourceType(t *testing.T) { _, err := workspaceurls.BuildResourceURL("https://myworkspace.databricks.com", "unknown", "123", "") assert.ErrorContains(t, err, "unknown resource type \"unknown\"") - assert.ErrorContains(t, err, "alerts, apps, catalogs, cluster_policies, clusters, dashboards, database_catalogs, database_instances, experiments, feature_specs, features, genie_spaces, instance_pools, jobs, mcp_services, model_provider_services, model_services, model_serving_endpoints, models, notebooks, pipelines, postgres_catalogs, postgres_synced_tables, quality_monitors, queries, registered_models, schemas, secrets, synced_database_tables, vector_search_endpoints, vector_search_indexes, volumes, warehouses") + assert.ErrorContains(t, err, "alerts, apps, catalogs, cluster_policies, clusters, dashboards, database_catalogs, database_instances, experiments, feature_specs, features, genie_agents, genie_spaces, instance_pools, jobs, mcp_services, model_provider_services, model_services, model_serving_endpoints, models, notebooks, pipelines, postgres_catalogs, postgres_synced_tables, quality_monitors, queries, registered_models, schemas, secrets, synced_database_tables, vector_search_endpoints, vector_search_indexes, volumes, warehouses") } func TestBuildWorkspaceURLHostWithTrailingSlash(t *testing.T) { @@ -120,6 +120,7 @@ func TestWorkspaceOpenCommandCompletion(t *testing.T) { "experiments", "feature_specs", "features", + "genie_agents", "genie_spaces", "instance_pools", "jobs", @@ -156,7 +157,7 @@ func TestWorkspaceOpenCommandCompletionSecondArg(t *testing.T) { func TestWorkspaceOpenCommandHelpText(t *testing.T) { cmd := newWorkspaceOpenCommand() - assert.Contains(t, cmd.Long, "Supported resource types: alerts, apps, catalogs, cluster_policies, clusters, dashboards, database_catalogs, database_instances, experiments, feature_specs, features, genie_spaces, instance_pools, jobs, mcp_services, model_provider_services, model_services, model_serving_endpoints, models, notebooks, pipelines, postgres_catalogs, postgres_synced_tables, quality_monitors, queries, registered_models, schemas, secrets, synced_database_tables, vector_search_endpoints, vector_search_indexes, volumes, warehouses.") + assert.Contains(t, cmd.Long, "Supported resource types: alerts, apps, catalogs, cluster_policies, clusters, dashboards, database_catalogs, database_instances, experiments, feature_specs, features, genie_agents, genie_spaces, instance_pools, jobs, mcp_services, model_provider_services, model_services, model_serving_endpoints, models, notebooks, pipelines, postgres_catalogs, postgres_synced_tables, quality_monitors, queries, registered_models, schemas, secrets, synced_database_tables, vector_search_endpoints, vector_search_indexes, volumes, warehouses.") assert.Contains(t, cmd.Long, "databricks experimental open jobs 123456789") assert.Contains(t, cmd.Long, "databricks experimental open notebooks /Users/user@example.com/my-notebook") assert.Contains(t, cmd.Long, "databricks experimental open registered_models catalog.schema.my_model") diff --git a/libs/testserver/fake_workspace.go b/libs/testserver/fake_workspace.go index 5e8068b6d02..4c9295e9d52 100644 --- a/libs/testserver/fake_workspace.go +++ b/libs/testserver/fake_workspace.go @@ -23,6 +23,7 @@ import ( "github.com/databricks/databricks-sdk-go/service/dashboards" "github.com/databricks/databricks-sdk-go/service/database" "github.com/databricks/databricks-sdk-go/service/dataquality" + "github.com/databricks/databricks-sdk-go/service/genieagents" "github.com/databricks/databricks-sdk-go/service/postgres" "github.com/databricks/cli/libs/structs/structtag" @@ -232,6 +233,8 @@ type FakeWorkspace struct { Dashboards *EventualMap[string, *fakeDashboard] PublishedDashboards map[string]dashboards.PublishedDashboard GenieSpaces map[string]dashboards.GenieSpace + GenieAgents map[string]genieagents.GenieAgent + GenieAgentIDsInTrash map[string]bool SqlWarehouses map[string]sql.GetWarehouseResponse Alerts map[string]sql.AlertV2 PurgedAlertIDs map[string]bool @@ -553,6 +556,8 @@ func NewFakeWorkspace(url, token string) *FakeWorkspace { Dashboards: NewEventualMap[string, *fakeDashboard](eventualConsistency), PublishedDashboards: map[string]dashboards.PublishedDashboard{}, GenieSpaces: map[string]dashboards.GenieSpace{}, + GenieAgents: map[string]genieagents.GenieAgent{}, + GenieAgentIDsInTrash: map[string]bool{}, SqlWarehouses: map[string]sql.GetWarehouseResponse{ TestDefaultWarehouseId: { Id: TestDefaultWarehouseId, diff --git a/libs/testserver/genie_agents.go b/libs/testserver/genie_agents.go new file mode 100644 index 00000000000..ad7567876b1 --- /dev/null +++ b/libs/testserver/genie_agents.go @@ -0,0 +1,191 @@ +package testserver + +import ( + "encoding/json" + "reflect" + "strconv" + "strings" + "time" + + sdktime "github.com/databricks/databricks-sdk-go/common/types/time" + "github.com/databricks/databricks-sdk-go/service/genieagents" +) + +func (s *FakeWorkspace) GenieAgentCreate(req Request) Response { + defer s.LockUnlock()() + + var body genieagents.GenieAgent + if err := json.Unmarshal(req.Body, &body); err != nil { + return genieAgentInvalidRequest(err) + } + + // The client may pin the id via the genie_agent_id query parameter; the + // server assigns one otherwise. ALREADY_EXISTS when the id is in use. + agentId := req.URL.Query().Get("genie_agent_id") + if agentId == "" { + agentId, _ = generateGenieSpaceId() + } + if _, ok := s.GenieAgents[agentId]; ok || s.GenieAgentIDsInTrash[agentId] { + return Response{ + StatusCode: 409, + Body: map[string]string{ + "error_code": "ALREADY_EXISTS", + "message": "Genie Agent " + agentId + " already exists", + }, + } + } + + // Default to the caller's home folder when parent_path is omitted, + // matching the documented behavior and GenieSpaceCreate. + parentPath := body.ParentPath + if parentPath == "" { + parentPath = "/Users/" + s.CurrentUser().UserName + } + + // An explicitly submitted parent_path must exist as a workspace folder; the + // CLI's default is the bundle's resource folder, which its mkdirs retry + // creates. The home folder default needs no check. + if body.ParentPath != "" { + if _, ok := s.directories[parentPath]; !ok { + return Response{ + StatusCode: 404, + Body: map[string]string{ + "error_code": "RESOURCE_DOES_NOT_EXIST", + "message": "Parent folder " + parentPath + " does not exist", + }, + } + } + } + + agent := body + agent.Name = "agents/" + agentId + // The API echoes parent_path; effective_parent_path may omit /Workspace. + agent.ParentPath = body.ParentPath + agent.EffectiveParentPath = strings.TrimPrefix(parentPath, "/Workspace") + agent.CreateTime = sdktime.New(time.Now()) + agent.UpdateTime = sdktime.New(time.Now()) + agent.Etag = "1" + + s.GenieAgents[agentId] = agent + + return Response{ + Body: agent, + } +} + +func (s *FakeWorkspace) GenieAgentGet(req Request) Response { + defer s.LockUnlock()() + + agent, resp := s.getGenieAgent(req.Vars["genie_agent_id"]) + if resp != nil { + return *resp + } + + return Response{ + Body: agent, + } +} + +func (s *FakeWorkspace) GenieAgentUpdate(req Request) Response { + defer s.LockUnlock()() + + agent, resp := s.getGenieAgent(req.Vars["genie_agent_id"]) + if resp != nil { + return *resp + } + + if etag := req.URL.Query().Get("etag"); etag != "" && etag != agent.Etag { + return genieAgentEtagMismatch() + } + + var body genieagents.GenieAgent + if err := json.Unmarshal(req.Body, &body); err != nil { + return genieAgentInvalidRequest(err) + } + + // The etag covers the definition only, so a metadata-only update keeps it. + if !reflect.DeepEqual(agent.Definition, body.Definition) { + next, _ := strconv.Atoi(agent.Etag) + agent.Etag = strconv.Itoa(next + 1) + } + + // update_mask "*" replaces every updatable field with the body's value and + // keeps the server-assigned ones. Setting parent_path moves the agent; + // clearing it does not (the stored folder is untouched, only the field is + // cleared, matching the update_mask contract). + agent.DisplayName = body.DisplayName + agent.Description = body.Description + agent.Definition = body.Definition + agent.WarehouseId = body.WarehouseId + agent.ParentPath = body.ParentPath + if body.ParentPath != "" { + agent.EffectiveParentPath = strings.TrimPrefix(body.ParentPath, "/Workspace") + } + agent.UpdateTime = sdktime.New(time.Now()) + + s.GenieAgents[req.Vars["genie_agent_id"]] = agent + + return Response{ + Body: agent, + } +} + +func (s *FakeWorkspace) GenieAgentDelete(req Request) Response { + defer s.LockUnlock()() + + agentId := req.Vars["genie_agent_id"] + agent, ok := s.GenieAgents[agentId] + if !ok { + return genieAgentNotFound() + } + if etag := req.URL.Query().Get("etag"); etag != "" && etag != agent.Etag { + return genieAgentEtagMismatch() + } + + delete(s.GenieAgents, agentId) + s.GenieAgentIDsInTrash[agentId] = true + + return Response{ + StatusCode: 200, + } +} + +// getGenieAgent returns a copy of the stored agent, or a 404 response. +func (s *FakeWorkspace) getGenieAgent(agentId string) (genieagents.GenieAgent, *Response) { + agent, ok := s.GenieAgents[agentId] + if !ok { + resp := genieAgentNotFound() + return genieagents.GenieAgent{}, &resp + } + return agent, nil +} + +func genieAgentNotFound() Response { + return Response{ + StatusCode: 404, + Body: map[string]string{ + "error_code": "RESOURCE_DOES_NOT_EXIST", + "message": "Genie Agent not found", + }, + } +} + +func genieAgentEtagMismatch() Response { + return Response{ + StatusCode: 409, + Body: map[string]string{ + "error_code": "ABORTED", + "message": "Genie Agent definition changed; get the agent and retry", + }, + } +} + +func genieAgentInvalidRequest(err error) Response { + return Response{ + StatusCode: 400, + Body: map[string]string{ + "error_code": "INVALID_PARAMETER_VALUE", + "message": "Invalid request body: " + err.Error(), + }, + } +} diff --git a/libs/testserver/handlers.go b/libs/testserver/handlers.go index 20aac63e2b7..2ed4110d356 100644 --- a/libs/testserver/handlers.go +++ b/libs/testserver/handlers.go @@ -666,6 +666,20 @@ func AddDefaultHandlers(server *Server) { return req.Workspace.GenieSpaceTrash(req) }) + // Genie Agents: + server.Handle("GET", "/api/2.0/genie/agents/{genie_agent_id}", func(req Request) any { + return req.Workspace.GenieAgentGet(req) + }) + server.Handle("POST", "/api/2.0/genie/agents", func(req Request) any { + return req.Workspace.GenieAgentCreate(req) + }) + server.Handle("PATCH", "/api/2.0/genie/agents/{genie_agent_id}", func(req Request) any { + return req.Workspace.GenieAgentUpdate(req) + }) + server.Handle("DELETE", "/api/2.0/genie/agents/{genie_agent_id}", func(req Request) any { + return req.Workspace.GenieAgentDelete(req) + }) + // Pipelines: server.Handle("GET", "/api/2.0/pipelines/{pipeline_id}", func(req Request) any { diff --git a/libs/workspaceurls/urls.go b/libs/workspaceurls/urls.go index 2773cb792d8..b8593e5ef20 100644 --- a/libs/workspaceurls/urls.go +++ b/libs/workspaceurls/urls.go @@ -21,6 +21,7 @@ var resourceURLPatterns = map[string]string{ "features": "explore/data/features/%s", "feature_specs": "explore/data/functions/%s", "genie_spaces": "genie/rooms/%s", + "genie_agents": "genie/rooms/%s", "jobs": "jobs/%s", "mcp_services": "explore/data/mcp-services/%s", "models": "ml/models/%s",