From 4c9552433f20408a0d6815e99cf6b760ad41251a Mon Sep 17 00:00:00 2001 From: Eric Cho Date: Fri, 13 Nov 2026 01:03:47 +0000 Subject: [PATCH 1/6] Add genie_agents bundle resource on the direct engine Add resources.genie_agents for managing AI/BI Genie agents through the Genie Agents API. The engine tracks the bare genie_agent_id (optional on create, server-assigned when omitted; changing it recreates the agent). Updates are in place with update_mask "*"; definition is replaced as a whole. The resource is private preview, so no Python package is generated. It manages the same backend object as genie_spaces; declaring the same object under both resource types is unsupported. Co-authored-by: Isaac --- .nextchanges/bundles/genie_agents.md | 1 + .../bind/genie_agent/databricks.yml | 14 + .../deployment/bind/genie_agent/out.test.toml | 2 + .../deployment/bind/genie_agent/output.txt | 48 + .../bundle/deployment/bind/genie_agent/script | 20 + .../bind/genie_agent/script.prepare | 4 + .../deployment/bind/genie_agent/test.toml | 6 + .../bundle/invariant/auto-migrate/test.toml | 2 + .../invariant/configs/genie_agent.yml.tmpl | 20 + .../bundle/invariant/continue_293/test.toml | 3 + .../invariant/delete_idempotent/out.test.toml | 1 + .../destroy_idempotent/out.test.toml | 1 + acceptance/bundle/invariant/migrate/test.toml | 2 + .../bundle/invariant/no_drift/out.test.toml | 1 + acceptance/bundle/invariant/test.toml | 3 + .../bundle/refschema/output/genie_agents.txt | 123 ++ .../genie_agents/basic/databricks.yml | 19 + .../genie_agents/basic/out.test.toml | 2 + .../resources/genie_agents/basic/output.txt | 280 ++++ .../resources/genie_agents/basic/script | 35 + .../resources/genie_agents/basic/test.toml | 7 + .../lifecycle/databricks.yml.tmpl | 17 + .../genie_agents/lifecycle/out.test.toml | 2 + .../genie_agents/lifecycle/output.txt | 52 + .../resources/genie_agents/lifecycle/script | 25 + .../genie_agents/lifecycle/test.toml | 9 + .../genie_agents/remote-delete/databricks.yml | 14 + .../genie_agents/remote-delete/out.test.toml | 2 + .../genie_agents/remote-delete/output.txt | 22 + .../genie_agents/remote-delete/script | 9 + .../genie_agents/remote-delete/test.toml | 9 + .../resources/genie_agents/script.prepare | 4 + .../bundle/resources/genie_agents/test.toml | 7 + .../without-definition/databricks.yml.tmpl | 8 + .../without-definition/out.test.toml | 2 + .../without-definition/output.txt | 13 + .../genie_agents/without-definition/script | 3 + .../genie_agents/without-definition/test.toml | 8 + acceptance/experimental/open/output.txt | 3 +- .../apply_bundle_permissions.go | 4 + .../mutator/resourcemutator/apply_presets.go | 8 + .../resourcemutator/apply_target_mode_test.go | 10 + .../resourcemutator/resource_mutator.go | 1 + .../mutator/resourcemutator/run_as_test.go | 2 + bundle/config/resources.go | 3 + bundle/config/resources/genie_agent.go | 111 ++ bundle/config/resources_test.go | 4 + bundle/direct/dresources/all.go | 2 + bundle/direct/dresources/all_test.go | 53 + .../direct/dresources/apitypes.generated.yml | 2 + bundle/direct/dresources/apitypes.yml | 9 + .../dresources/configs/genie_agents.yml | 6 + bundle/direct/dresources/genie_agent.go | 164 +++ bundle/direct/dresources/permissions.go | 1 + bundle/internal/annotation/preview.go | 1 + bundle/internal/schema/annotations.yml | 42 + .../validation/generated/enum_fields.go | 4 + .../validation/generated/required_fields.go | 21 + bundle/phases/deploy.go | 1 + bundle/phases/destroy.go | 1 + bundle/phases/messages.go | 7 + bundle/schema/jsonschema.json | 1282 ++++++++++++++++- bundle/statemgmt/state_load_test.go | 35 + cmd/experimental/workspace_open_test.go | 5 +- libs/testserver/fake_workspace.go | 3 + libs/testserver/genie_agents.go | 162 +++ libs/testserver/handlers.go | 14 + libs/workspaceurls/urls.go | 1 + 68 files changed, 2734 insertions(+), 28 deletions(-) create mode 100644 .nextchanges/bundles/genie_agents.md create mode 100644 acceptance/bundle/deployment/bind/genie_agent/databricks.yml create mode 100644 acceptance/bundle/deployment/bind/genie_agent/out.test.toml create mode 100644 acceptance/bundle/deployment/bind/genie_agent/output.txt create mode 100644 acceptance/bundle/deployment/bind/genie_agent/script create mode 100644 acceptance/bundle/deployment/bind/genie_agent/script.prepare create mode 100644 acceptance/bundle/deployment/bind/genie_agent/test.toml create mode 100644 acceptance/bundle/invariant/configs/genie_agent.yml.tmpl create mode 100644 acceptance/bundle/refschema/output/genie_agents.txt create mode 100644 acceptance/bundle/resources/genie_agents/basic/databricks.yml create mode 100644 acceptance/bundle/resources/genie_agents/basic/out.test.toml create mode 100644 acceptance/bundle/resources/genie_agents/basic/output.txt create mode 100644 acceptance/bundle/resources/genie_agents/basic/script create mode 100644 acceptance/bundle/resources/genie_agents/basic/test.toml create mode 100644 acceptance/bundle/resources/genie_agents/lifecycle/databricks.yml.tmpl create mode 100644 acceptance/bundle/resources/genie_agents/lifecycle/out.test.toml create mode 100644 acceptance/bundle/resources/genie_agents/lifecycle/output.txt create mode 100644 acceptance/bundle/resources/genie_agents/lifecycle/script create mode 100644 acceptance/bundle/resources/genie_agents/lifecycle/test.toml create mode 100644 acceptance/bundle/resources/genie_agents/remote-delete/databricks.yml create mode 100644 acceptance/bundle/resources/genie_agents/remote-delete/out.test.toml create mode 100644 acceptance/bundle/resources/genie_agents/remote-delete/output.txt create mode 100644 acceptance/bundle/resources/genie_agents/remote-delete/script create mode 100644 acceptance/bundle/resources/genie_agents/remote-delete/test.toml create mode 100644 acceptance/bundle/resources/genie_agents/script.prepare create mode 100644 acceptance/bundle/resources/genie_agents/test.toml create mode 100644 acceptance/bundle/resources/genie_agents/without-definition/databricks.yml.tmpl create mode 100644 acceptance/bundle/resources/genie_agents/without-definition/out.test.toml create mode 100644 acceptance/bundle/resources/genie_agents/without-definition/output.txt create mode 100644 acceptance/bundle/resources/genie_agents/without-definition/script create mode 100644 acceptance/bundle/resources/genie_agents/without-definition/test.toml create mode 100644 bundle/config/resources/genie_agent.go create mode 100644 bundle/direct/dresources/configs/genie_agents.yml create mode 100644 bundle/direct/dresources/genie_agent.go create mode 100644 libs/testserver/genie_agents.go diff --git a/.nextchanges/bundles/genie_agents.md b/.nextchanges/bundles/genie_agents.md new file mode 100644 index 00000000000..ca5f10a3d89 --- /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. diff --git a/acceptance/bundle/deployment/bind/genie_agent/databricks.yml b/acceptance/bundle/deployment/bind/genie_agent/databricks.yml new file mode 100644 index 00000000000..ca373223061 --- /dev/null +++ b/acceptance/bundle/deployment/bind/genie_agent/databricks.yml @@ -0,0 +1,14 @@ +bundle: + name: test-bundle + +resources: + genie_agents: + agent1: + genie_agent_id: "01f0a1b2c3d4e5f60718293a4b5c6d7e" + display_name: bound-agent + warehouse_id: test-warehouse-id + definition: + config: + sample_questions: + - id: "01f0a1b2c3d4e5f60718293a4b5c6d7f" + question: What were total sales 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..ef44e06497c --- /dev/null +++ b/acceptance/bundle/deployment/bind/genie_agent/output.txt @@ -0,0 +1,48 @@ + +>>> [CLI] genie-agents create-genie-agent --json { + "display_name": "bound-agent", + "warehouse_id": "test-warehouse-id", + "definition": { + "config": { + "sample_questions": [ + {"id": "01f0a1b2c3d4e5f60718293a4b5c6d7f", "question": "What were total sales last month?"} + ] + } + } +} --genie-agent-id 01f0a1b2c3d4e5f60718293a4b5c6d7e +{ + "name": "agents/01f0a1b2c3d4e5f60718293a4b5c6d7e", + "display_name": "bound-agent", + "warehouse_id": "test-warehouse-id", + "etag": "1" +} + +>>> [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 summary +Name: test-bundle +Target: default +Workspace: + User: [USERNAME] + Path: /Workspace/Users/[USERNAME]/.bundle/test-bundle/default +Resources: + Genie Agents: + agent1: + Name: bound-agent + URL: [DATABRICKS_URL]/genie/rooms/01f0a1b2c3d4e5f60718293a4b5c6d7e?w=[WORKSPACE_ID] + +>>> [CLI] bundle deployment unbind agent1 + +>>> [CLI] bundle summary +Name: test-bundle +Target: default +Workspace: + User: [USERNAME] + Path: /Workspace/Users/[USERNAME]/.bundle/test-bundle/default +Resources: + Genie Agents: + agent1: + Name: bound-agent + URL: (not deployed) diff --git a/acceptance/bundle/deployment/bind/genie_agent/script b/acceptance/bundle/deployment/bind/genie_agent/script new file mode 100644 index 00000000000..73ae2b63c87 --- /dev/null +++ b/acceptance/bundle/deployment/bind/genie_agent/script @@ -0,0 +1,20 @@ +AGENT="01f0a1b2c3d4e5f60718293a4b5c6d7e" + +# Create the object outside the bundle with the CLI's own create command. +trace $CLI genie-agents create-genie-agent --json '{ + "display_name": "bound-agent", + "warehouse_id": "test-warehouse-id", + "definition": { + "config": { + "sample_questions": [ + {"id": "01f0a1b2c3d4e5f60718293a4b5c6d7f", "question": "What were total sales last month?"} + ] + } + } +}' --genie-agent-id "$AGENT" | agent_fields + +trace $CLI bundle deployment bind agent1 "$AGENT" --auto-approve +trace $CLI bundle summary + +trace $CLI bundle deployment unbind agent1 +trace $CLI bundle summary diff --git a/acceptance/bundle/deployment/bind/genie_agent/script.prepare b/acceptance/bundle/deployment/bind/genie_agent/script.prepare new file mode 100644 index 00000000000..96d3dc77ef2 --- /dev/null +++ b/acceptance/bundle/deployment/bind/genie_agent/script.prepare @@ -0,0 +1,4 @@ +# Project a genie agent read to the fields the test asserts. +agent_fields() { + jq '{name, display_name, warehouse_id, etag}' +} diff --git a/acceptance/bundle/deployment/bind/genie_agent/test.toml b/acceptance/bundle/deployment/bind/genie_agent/test.toml new file mode 100644 index 00000000000..4f5f1962a36 --- /dev/null +++ b/acceptance/bundle/deployment/bind/genie_agent/test.toml @@ -0,0 +1,6 @@ +# Genie agents are managed by the direct deployment engine. +Cloud = false + +Ignore = [ + ".databricks", +] diff --git a/acceptance/bundle/invariant/auto-migrate/test.toml b/acceptance/bundle/invariant/auto-migrate/test.toml index ee0a30ed9da..bc397416e18 100644 --- a/acceptance/bundle/invariant/auto-migrate/test.toml +++ b/acceptance/bundle/invariant/auto-migrate/test.toml @@ -31,6 +31,8 @@ EnvMatrixExclude.no_external_location = ["INPUT_CONFIG=external_location.yml.tmp EnvMatrixExclude.no_uc_trailing_slash = ["INPUT_CONFIG=uc_trailing_slash.yml.tmpl"] # Genie spaces are direct-only too; the terraform deploy that seeds the migration fails for them. EnvMatrixExclude.no_genie_space = ["INPUT_CONFIG=genie_space.yml.tmpl"] +# Genie agents are direct-only too; the terraform deploy that seeds the migration fails for them. +EnvMatrixExclude.no_genie_agent = ["INPUT_CONFIG=genie_agent.yml.tmpl"] # Instance pools are direct-only; the terraform deploy that seeds the migration fails for them. EnvMatrixExclude.no_instance_pool = ["INPUT_CONFIG=instance_pool.yml.tmpl"] # Cluster policies are direct-only; the terraform deploy that seeds the migration fails for them. diff --git a/acceptance/bundle/invariant/configs/genie_agent.yml.tmpl b/acceptance/bundle/invariant/configs/genie_agent.yml.tmpl new file mode 100644 index 00000000000..9de3b1120f2 --- /dev/null +++ b/acceptance/bundle/invariant/configs/genie_agent.yml.tmpl @@ -0,0 +1,20 @@ +bundle: + name: test-bundle-$UNIQUE_NAME + +resources: + genie_agents: + foo: + warehouse_id: $TEST_DEFAULT_WAREHOUSE_ID + display_name: test-genie-agent-$UNIQUE_NAME + description: This is a test genie agent # CAN_REMOVE + definition: + config: + sample_questions: + - id: "01f0a1b2c3d4e5f60718293a4b5c6d7e" + question: What were total sales last month? + data_sources: + tables: + - identifier: main.sales.orders + permissions: + - level: CAN_READ + group_name: users diff --git a/acceptance/bundle/invariant/continue_293/test.toml b/acceptance/bundle/invariant/continue_293/test.toml index 150d61a2c4b..b07e4191632 100644 --- a/acceptance/bundle/invariant/continue_293/test.toml +++ b/acceptance/bundle/invariant/continue_293/test.toml @@ -17,6 +17,9 @@ EnvMatrixExclude.no_vector_search_index = ["INPUT_CONFIG=vector_search_index.yml # genie_spaces resource is not supported on v0.293.0 EnvMatrixExclude.no_genie_space = ["INPUT_CONFIG=genie_space.yml.tmpl"] +# genie_agents resource is not supported on v0.293.0 +EnvMatrixExclude.no_genie_agent = ["INPUT_CONFIG=genie_agent.yml.tmpl"] + # instance_pools resource is not supported on v0.293.0 EnvMatrixExclude.no_instance_pool = ["INPUT_CONFIG=instance_pool.yml.tmpl"] diff --git a/acceptance/bundle/invariant/delete_idempotent/out.test.toml b/acceptance/bundle/invariant/delete_idempotent/out.test.toml index 9de4b5dba9b..ca880de3340 100644 --- a/acceptance/bundle/invariant/delete_idempotent/out.test.toml +++ b/acceptance/bundle/invariant/delete_idempotent/out.test.toml @@ -20,6 +20,7 @@ EnvMatrix.INPUT_CONFIG = [ "external_location.yml.tmpl", "feature.yml.tmpl", "feature_spec.yml.tmpl", + "genie_agent.yml.tmpl", "genie_space.yml.tmpl", "instance_pool.yml.tmpl", "job.yml.tmpl", diff --git a/acceptance/bundle/invariant/destroy_idempotent/out.test.toml b/acceptance/bundle/invariant/destroy_idempotent/out.test.toml index 9de4b5dba9b..ca880de3340 100644 --- a/acceptance/bundle/invariant/destroy_idempotent/out.test.toml +++ b/acceptance/bundle/invariant/destroy_idempotent/out.test.toml @@ -20,6 +20,7 @@ EnvMatrix.INPUT_CONFIG = [ "external_location.yml.tmpl", "feature.yml.tmpl", "feature_spec.yml.tmpl", + "genie_agent.yml.tmpl", "genie_space.yml.tmpl", "instance_pool.yml.tmpl", "job.yml.tmpl", diff --git a/acceptance/bundle/invariant/migrate/test.toml b/acceptance/bundle/invariant/migrate/test.toml index 71e5463fa01..b99138c8c7e 100644 --- a/acceptance/bundle/invariant/migrate/test.toml +++ b/acceptance/bundle/invariant/migrate/test.toml @@ -31,6 +31,8 @@ EnvMatrixExclude.no_external_location = ["INPUT_CONFIG=external_location.yml.tmp EnvMatrixExclude.no_uc_trailing_slash = ["INPUT_CONFIG=uc_trailing_slash.yml.tmpl"] # Genie spaces are direct-only too; the terraform deploy that seeds the migration fails for them. EnvMatrixExclude.no_genie_space = ["INPUT_CONFIG=genie_space.yml.tmpl"] +# Genie agents are direct-only too; the terraform deploy that seeds the migration fails for them. +EnvMatrixExclude.no_genie_agent = ["INPUT_CONFIG=genie_agent.yml.tmpl"] # Instance pools are direct-only; the terraform deploy that seeds the migration fails for them. EnvMatrixExclude.no_instance_pool = ["INPUT_CONFIG=instance_pool.yml.tmpl"] # Cluster policies are direct-only; the terraform deploy that seeds the migration fails for them. diff --git a/acceptance/bundle/invariant/no_drift/out.test.toml b/acceptance/bundle/invariant/no_drift/out.test.toml index a2856e6353d..68487df60f0 100644 --- a/acceptance/bundle/invariant/no_drift/out.test.toml +++ b/acceptance/bundle/invariant/no_drift/out.test.toml @@ -20,6 +20,7 @@ EnvMatrix.INPUT_CONFIG = [ "external_location.yml.tmpl", "feature.yml.tmpl", "feature_spec.yml.tmpl", + "genie_agent.yml.tmpl", "genie_space.yml.tmpl", "instance_pool.yml.tmpl", "job.yml.tmpl", diff --git a/acceptance/bundle/invariant/test.toml b/acceptance/bundle/invariant/test.toml index dccac6ed8bc..1e120a1631e 100644 --- a/acceptance/bundle/invariant/test.toml +++ b/acceptance/bundle/invariant/test.toml @@ -34,6 +34,7 @@ EnvMatrix.INPUT_CONFIG = [ "external_location.yml.tmpl", "feature.yml.tmpl", "feature_spec.yml.tmpl", + "genie_agent.yml.tmpl", "genie_space.yml.tmpl", "instance_pool.yml.tmpl", "job.yml.tmpl", @@ -128,6 +129,8 @@ EnvMatrixExclude.no_data_quality_monitor_on_cloud = ["CONFIG_Cloud=true", "INPUT EnvMatrixExclude.no_feature_spec_dms = ["DMS=true", "INPUT_CONFIG=feature_spec.yml.tmpl"] # Same for the "postgres_data_apis." prefix. EnvMatrixExclude.no_postgres_data_api_dms = ["DMS=true", "INPUT_CONFIG=postgres_data_api.yml.tmpl"] +# Same for the "genie_agents." prefix. +EnvMatrixExclude.no_genie_agent_dms = ["DMS=true", "INPUT_CONFIG=genie_agent.yml.tmpl"] # Fake SQL endpoint for local tests [[Server]] diff --git a/acceptance/bundle/refschema/output/genie_agents.txt b/acceptance/bundle/refschema/output/genie_agents.txt new file mode 100644 index 00000000000..55f432ff7de --- /dev/null +++ b/acceptance/bundle/refschema/output/genie_agents.txt @@ -0,0 +1,123 @@ +resources.genie_agents.*.definition *genieagents.GenieAgentDefinition ALL +resources.genie_agents.*.definition.benchmarks *genieagents.GenieAgentBenchmarks ALL +resources.genie_agents.*.definition.benchmarks.questions []genieagents.GenieAgentBenchmarkQuestion ALL +resources.genie_agents.*.definition.benchmarks.questions[*] genieagents.GenieAgentBenchmarkQuestion ALL +resources.genie_agents.*.definition.benchmarks.questions[*].answer []genieagents.GenieAgentBenchmarkAnswer ALL +resources.genie_agents.*.definition.benchmarks.questions[*].answer[*] genieagents.GenieAgentBenchmarkAnswer ALL +resources.genie_agents.*.definition.benchmarks.questions[*].answer[*].content string ALL +resources.genie_agents.*.definition.benchmarks.questions[*].answer[*].format genieagents.GenieAgentBenchmarkAnswerFormat ALL +resources.genie_agents.*.definition.benchmarks.questions[*].evaluation_note string ALL +resources.genie_agents.*.definition.benchmarks.questions[*].id string ALL +resources.genie_agents.*.definition.benchmarks.questions[*].question string ALL +resources.genie_agents.*.definition.config *genieagents.GenieAgentConfig ALL +resources.genie_agents.*.definition.config.sample_questions []genieagents.GenieAgentSampleQuestion ALL +resources.genie_agents.*.definition.config.sample_questions[*] genieagents.GenieAgentSampleQuestion ALL +resources.genie_agents.*.definition.config.sample_questions[*].id string ALL +resources.genie_agents.*.definition.config.sample_questions[*].question string ALL +resources.genie_agents.*.definition.data_sources *genieagents.GenieAgentDataSources ALL +resources.genie_agents.*.definition.data_sources.mcp_connections []genieagents.GenieAgentMcpConnection ALL +resources.genie_agents.*.definition.data_sources.mcp_connections[*] genieagents.GenieAgentMcpConnection ALL +resources.genie_agents.*.definition.data_sources.mcp_connections[*].mcp_connection string ALL +resources.genie_agents.*.definition.data_sources.tables []genieagents.GenieAgentTable ALL +resources.genie_agents.*.definition.data_sources.tables[*] genieagents.GenieAgentTable ALL +resources.genie_agents.*.definition.data_sources.tables[*].column_configs []genieagents.GenieAgentColumnConfig ALL +resources.genie_agents.*.definition.data_sources.tables[*].column_configs[*] genieagents.GenieAgentColumnConfig ALL +resources.genie_agents.*.definition.data_sources.tables[*].column_configs[*].column string ALL +resources.genie_agents.*.definition.data_sources.tables[*].column_configs[*].description string ALL +resources.genie_agents.*.definition.data_sources.tables[*].column_configs[*].display_name string ALL +resources.genie_agents.*.definition.data_sources.tables[*].column_configs[*].enable_entity_matching bool ALL +resources.genie_agents.*.definition.data_sources.tables[*].column_configs[*].enable_format_assistance bool ALL +resources.genie_agents.*.definition.data_sources.tables[*].column_configs[*].exclude bool ALL +resources.genie_agents.*.definition.data_sources.tables[*].column_configs[*].synonyms []string ALL +resources.genie_agents.*.definition.data_sources.tables[*].column_configs[*].synonyms[*] string ALL +resources.genie_agents.*.definition.data_sources.tables[*].description string ALL +resources.genie_agents.*.definition.data_sources.tables[*].identifier string ALL +resources.genie_agents.*.definition.data_sources.volumes []genieagents.GenieAgentVolume ALL +resources.genie_agents.*.definition.data_sources.volumes[*] genieagents.GenieAgentVolume ALL +resources.genie_agents.*.definition.data_sources.volumes[*].description string ALL +resources.genie_agents.*.definition.data_sources.volumes[*].path string ALL +resources.genie_agents.*.definition.instructions *genieagents.GenieAgentInstructions ALL +resources.genie_agents.*.definition.instructions.example_question_sqls []genieagents.GenieAgentExampleQuestionSql ALL +resources.genie_agents.*.definition.instructions.example_question_sqls[*] genieagents.GenieAgentExampleQuestionSql ALL +resources.genie_agents.*.definition.instructions.example_question_sqls[*].id string ALL +resources.genie_agents.*.definition.instructions.example_question_sqls[*].parameters []genieagents.GenieAgentSqlParameter ALL +resources.genie_agents.*.definition.instructions.example_question_sqls[*].parameters[*] genieagents.GenieAgentSqlParameter ALL +resources.genie_agents.*.definition.instructions.example_question_sqls[*].parameters[*].default_value *genieagents.GenieAgentSqlParameterDefaultValue ALL +resources.genie_agents.*.definition.instructions.example_question_sqls[*].parameters[*].default_value.value_range *genieagents.GenieAgentSqlParameterDefaultRange ALL +resources.genie_agents.*.definition.instructions.example_question_sqls[*].parameters[*].default_value.value_range.max string ALL +resources.genie_agents.*.definition.instructions.example_question_sqls[*].parameters[*].default_value.value_range.min string ALL +resources.genie_agents.*.definition.instructions.example_question_sqls[*].parameters[*].default_value.values []string ALL +resources.genie_agents.*.definition.instructions.example_question_sqls[*].parameters[*].default_value.values[*] string ALL +resources.genie_agents.*.definition.instructions.example_question_sqls[*].parameters[*].description string ALL +resources.genie_agents.*.definition.instructions.example_question_sqls[*].parameters[*].name string ALL +resources.genie_agents.*.definition.instructions.example_question_sqls[*].parameters[*].type_hint string ALL +resources.genie_agents.*.definition.instructions.example_question_sqls[*].question string ALL +resources.genie_agents.*.definition.instructions.example_question_sqls[*].sql string ALL +resources.genie_agents.*.definition.instructions.example_question_sqls[*].usage_guidance string ALL +resources.genie_agents.*.definition.instructions.join_specs []genieagents.GenieAgentJoinSpec ALL +resources.genie_agents.*.definition.instructions.join_specs[*] genieagents.GenieAgentJoinSpec ALL +resources.genie_agents.*.definition.instructions.join_specs[*].comment string ALL +resources.genie_agents.*.definition.instructions.join_specs[*].id string ALL +resources.genie_agents.*.definition.instructions.join_specs[*].instruction string ALL +resources.genie_agents.*.definition.instructions.join_specs[*].left genieagents.GenieAgentJoinSource ALL +resources.genie_agents.*.definition.instructions.join_specs[*].left.alias string ALL +resources.genie_agents.*.definition.instructions.join_specs[*].left.identifier string ALL +resources.genie_agents.*.definition.instructions.join_specs[*].relationship_type genieagents.GenieAgentJoinRelationshipType ALL +resources.genie_agents.*.definition.instructions.join_specs[*].right genieagents.GenieAgentJoinSource ALL +resources.genie_agents.*.definition.instructions.join_specs[*].right.alias string ALL +resources.genie_agents.*.definition.instructions.join_specs[*].right.identifier string ALL +resources.genie_agents.*.definition.instructions.join_specs[*].sql string ALL +resources.genie_agents.*.definition.instructions.sql_functions []genieagents.GenieAgentSqlFunction ALL +resources.genie_agents.*.definition.instructions.sql_functions[*] genieagents.GenieAgentSqlFunction ALL +resources.genie_agents.*.definition.instructions.sql_functions[*].id string ALL +resources.genie_agents.*.definition.instructions.sql_functions[*].identifier string ALL +resources.genie_agents.*.definition.instructions.sql_snippets *genieagents.GenieAgentSqlSnippets ALL +resources.genie_agents.*.definition.instructions.sql_snippets.expressions []genieagents.GenieAgentSqlExpression ALL +resources.genie_agents.*.definition.instructions.sql_snippets.expressions[*] genieagents.GenieAgentSqlExpression ALL +resources.genie_agents.*.definition.instructions.sql_snippets.expressions[*].alias string ALL +resources.genie_agents.*.definition.instructions.sql_snippets.expressions[*].display_name string ALL +resources.genie_agents.*.definition.instructions.sql_snippets.expressions[*].id string ALL +resources.genie_agents.*.definition.instructions.sql_snippets.expressions[*].instruction string ALL +resources.genie_agents.*.definition.instructions.sql_snippets.expressions[*].sql string ALL +resources.genie_agents.*.definition.instructions.sql_snippets.expressions[*].synonyms []string ALL +resources.genie_agents.*.definition.instructions.sql_snippets.expressions[*].synonyms[*] string ALL +resources.genie_agents.*.definition.instructions.sql_snippets.filters []genieagents.GenieAgentSqlFilter ALL +resources.genie_agents.*.definition.instructions.sql_snippets.filters[*] genieagents.GenieAgentSqlFilter ALL +resources.genie_agents.*.definition.instructions.sql_snippets.filters[*].display_name string ALL +resources.genie_agents.*.definition.instructions.sql_snippets.filters[*].id string ALL +resources.genie_agents.*.definition.instructions.sql_snippets.filters[*].instruction string ALL +resources.genie_agents.*.definition.instructions.sql_snippets.filters[*].sql string ALL +resources.genie_agents.*.definition.instructions.sql_snippets.filters[*].synonyms []string ALL +resources.genie_agents.*.definition.instructions.sql_snippets.filters[*].synonyms[*] string ALL +resources.genie_agents.*.definition.instructions.sql_snippets.measures []genieagents.GenieAgentSqlMeasure ALL +resources.genie_agents.*.definition.instructions.sql_snippets.measures[*] genieagents.GenieAgentSqlMeasure ALL +resources.genie_agents.*.definition.instructions.sql_snippets.measures[*].alias string ALL +resources.genie_agents.*.definition.instructions.sql_snippets.measures[*].display_name string ALL +resources.genie_agents.*.definition.instructions.sql_snippets.measures[*].id string ALL +resources.genie_agents.*.definition.instructions.sql_snippets.measures[*].instruction string ALL +resources.genie_agents.*.definition.instructions.sql_snippets.measures[*].sql string ALL +resources.genie_agents.*.definition.instructions.sql_snippets.measures[*].synonyms []string ALL +resources.genie_agents.*.definition.instructions.sql_snippets.measures[*].synonyms[*] string ALL +resources.genie_agents.*.definition.instructions.text_instructions []genieagents.GenieAgentTextInstruction ALL +resources.genie_agents.*.definition.instructions.text_instructions[*] genieagents.GenieAgentTextInstruction ALL +resources.genie_agents.*.definition.instructions.text_instructions[*].content string ALL +resources.genie_agents.*.definition.instructions.text_instructions[*].id string ALL +resources.genie_agents.*.description string ALL +resources.genie_agents.*.display_name string ALL +resources.genie_agents.*.genie_agent_id string ALL +resources.genie_agents.*.id string INPUT +resources.genie_agents.*.lifecycle resources.Lifecycle INPUT +resources.genie_agents.*.lifecycle.depends_on []resources.DependsOn INPUT +resources.genie_agents.*.lifecycle.depends_on[*] resources.DependsOn INPUT +resources.genie_agents.*.lifecycle.depends_on[*].resource string INPUT +resources.genie_agents.*.lifecycle.prevent_destroy bool INPUT +resources.genie_agents.*.modified_status string INPUT +resources.genie_agents.*.parent_path string ALL +resources.genie_agents.*.url string INPUT +resources.genie_agents.*.warehouse_id string ALL +resources.genie_agents.*.permissions.object_id string ALL +resources.genie_agents.*.permissions[*] dresources.StatePermission ALL +resources.genie_agents.*.permissions[*].group_name string ALL +resources.genie_agents.*.permissions[*].level iam.PermissionLevel ALL +resources.genie_agents.*.permissions[*].service_principal_name string ALL +resources.genie_agents.*.permissions[*].user_name string ALL diff --git a/acceptance/bundle/resources/genie_agents/basic/databricks.yml b/acceptance/bundle/resources/genie_agents/basic/databricks.yml new file mode 100644 index 00000000000..44973c3dbea --- /dev/null +++ b/acceptance/bundle/resources/genie_agents/basic/databricks.yml @@ -0,0 +1,19 @@ +bundle: + name: test-bundle + +resources: + genie_agents: + agent1: + genie_agent_id: "01f0a1b2c3d4e5f60718293a4b5c6d7e" + display_name: my-agent + description: COMMENT1 + warehouse_id: test-warehouse-id + definition: + config: + sample_questions: + - id: "01f0a1b2c3d4e5f60718293a4b5c6d7f" + question: What were total sales last month? + data_sources: + tables: + - identifier: main.sales.orders + description: One row per order, with order date and amount. diff --git a/acceptance/bundle/resources/genie_agents/basic/out.test.toml b/acceptance/bundle/resources/genie_agents/basic/out.test.toml new file mode 100644 index 00000000000..19b5b15d11f --- /dev/null +++ b/acceptance/bundle/resources/genie_agents/basic/out.test.toml @@ -0,0 +1,2 @@ +Cloud = false +EnvMatrix.DMS = [""] diff --git a/acceptance/bundle/resources/genie_agents/basic/output.txt b/acceptance/bundle/resources/genie_agents/basic/output.txt new file mode 100644 index 00000000000..4b706794a66 --- /dev/null +++ b/acceptance/bundle/resources/genie_agents/basic/output.txt @@ -0,0 +1,280 @@ + +=== Initial summary before deploy + +>>> [CLI] bundle summary -o json +{ + "definition": { + "config": { + "sample_questions": [ + { + "id": "01f0a1b2c3d4e5f60718293a4b5c6d7f", + "question": "What were total sales last month?" + } + ] + }, + "data_sources": { + "tables": [ + { + "description": "One row per order, with order date and amount.", + "identifier": "main.sales.orders" + } + ] + } + }, + "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 were total sales last month?" + } + ] + }, + "data_sources": { + "tables": [ + { + "description": "One row per order, with order date and amount.", + "identifier": "main.sales.orders" + } + ] + } + }, + "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 were total sales last month?" + } + ] + }, + "data_sources": { + "tables": [ + { + "description": "One row per order, with order date and amount.", + "identifier": "main.sales.orders" + } + ] + } + }, + "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", + "etag": "1" +} + +=== 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": { + "update_mask": "*" + }, + "body": { + "definition": { + "config": { + "sample_questions": [ + { + "id": "01f0a1b2c3d4e5f60718293a4b5c6d7f", + "question": "What were total sales last month?" + } + ] + }, + "data_sources": { + "tables": [ + { + "description": "One row per order, with order date and amount.", + "identifier": "main.sales.orders" + } + ] + } + }, + "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", + "etag": "1" +} + +=== 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 were total sales last month?" + } + ] + }, + "data_sources": { + "tables": [ + { + "description": "One row per order, with order date and amount.", + "identifier": "main.sales.orders" + } + ] + } + }, + "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..36fa6e5b3ac --- /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 sales tables" + warehouse_id: $TEST_DEFAULT_WAREHOUSE_ID + definition: + config: + sample_questions: + - id: "01f0a1b2c3d4e5f60718293a4b5c6d7e" + question: What were total sales last month? + data_sources: + tables: + - identifier: main.sales.orders 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..15f92edf306 --- /dev/null +++ b/acceptance/bundle/resources/genie_agents/lifecycle/output.txt @@ -0,0 +1,52 @@ + +>>> [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 sales tables", + "warehouse_id": "[TEST_DEFAULT_WAREHOUSE_ID]", + "etag": "1" +} + +>>> [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 sales tables Agent grounded in sales tables, 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 sales tables, updated", + "warehouse_id": "[TEST_DEFAULT_WAREHOUSE_ID]", + "etag": "1" +} + +>>> [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..e67adbb3910 --- /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 sales tables" "Agent grounded in sales tables, 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..1bff6d9b2ce --- /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 were total sales 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..35811a847af --- /dev/null +++ b/acceptance/bundle/resources/genie_agents/remote-delete/output.txt @@ -0,0 +1,22 @@ + +>>> [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 should detect the resource is gone and re-create it + +>>> [CLI] bundle plan +create genie_agents.agent1 + +Plan: 1 to add, 0 to change, 0 to delete, 0 unchanged + +>>> [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..f1790035ec6 --- /dev/null +++ b/acceptance/bundle/resources/genie_agents/remote-delete/script @@ -0,0 +1,9 @@ +trace $CLI bundle deploy + +title "Delete the resource out of band" +trace $CLI genie-agents delete-genie-agent agents/01f0a1b2c3d4e5f60718293a4b5c6d7e + +title "Plan should detect the resource is gone and re-create it" +trace $CLI bundle plan + +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..2d9bd50f07f --- /dev/null +++ b/acceptance/bundle/resources/genie_agents/script.prepare @@ -0,0 +1,4 @@ +# Project a genie agent read to the fields the test asserts. +agent_fields() { + jq '{name, display_name, description, warehouse_id, etag}' +} 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 2c20366f5fc..2ff8f7488e5 100644 --- a/bundle/config/mutator/resourcemutator/apply_presets.go +++ b/bundle/config/mutator/resourcemutator/apply_presets.go @@ -281,6 +281,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..813bfe33c60 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) 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..f0b9bb034db --- /dev/null +++ b/bundle/config/resources/genie_agent.go @@ -0,0 +1,111 @@ +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 mirrors ResourceMcpService: the SDK models the create input `genie_agent_id` +// as a URL parameter (`json:"-"`) outside the GenieAgent body and derives the +// resource `name` (`agents/{genie_agent_id}`) server-side, so we expose a flat +// struct with the identity plus the mutable body. The server-derived `name`, +// `etag`, timestamps and `effective_parent_path` stay out of the config type; +// the engine tracks the bare `genie_agent_id` as the resource id. +type GenieAgentConfig struct { + // 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. + GenieAgentId string `json:"genie_agent_id,omitempty"` + // Display name of the Genie Agent. Must be unique within its folder. The + // maximum length is 63 characters. + DisplayName string `json:"display_name"` + // Description of the Genie Agent. The maximum length is 4,096 characters. + Description string `json:"description,omitempty"` + // Warehouse associated with the Genie Agent. + WarehouseId string `json:"warehouse_id"` + // The workspace folder to create the Genie Agent in. If omitted, the + // caller's home folder is used. On update, setting it moves the agent and + // clearing it does not. + ParentPath string `json:"parent_path,omitempty"` + // 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. + Definition *genieagents.GenieAgentDefinition `json:"definition"` + + ForceSendFields []string `json:"-" url:"-"` +} + +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 b835dd78948..1726090c2c2 100644 --- a/bundle/direct/dresources/all_test.go +++ b/bundle/direct/dresources/all_test.go @@ -27,6 +27,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" @@ -321,6 +322,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, @@ -624,6 +650,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 db57a08bc8d..a10a72cfbc2 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.CreateGenieAgentRequest + genie_spaces: dashboards.GenieUpdateSpaceRequest instance_pools: compute.CreateInstancePool diff --git a/bundle/direct/dresources/apitypes.yml b/bundle/direct/dresources/apitypes.yml index 7832c70e58f..26a519ae822 100644 --- a/bundle/direct/dresources/apitypes.yml +++ b/bundle/direct/dresources/apitypes.yml @@ -13,6 +13,15 @@ genie_spaces: dashboards.GenieSpace mcp_services: catalog.McpService +# The heuristic picks CreateGenieAgentRequest because the config's identity +# field genie_agent_id exists only on the create request, and the field-overlap +# score weights that rare field name heavily. Pin the resource type: the +# generated rules describe the read shape, and GenieAgent is what GET returns. +# If the API carried the create-time genie_agent_id input on the resource +# message itself, the resource type would win the overlap and this pin could be +# dropped. +genie_agents: genieagents.GenieAgent + model_provider_services: catalog.ModelProviderService model_services: catalog.ModelService diff --git a/bundle/direct/dresources/configs/genie_agents.yml b/bundle/direct/dresources/configs/genie_agents.yml new file mode 100644 index 00000000000..6bbc649b648 --- /dev/null +++ b/bundle/direct/dresources/configs/genie_agents.yml @@ -0,0 +1,6 @@ +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 diff --git a/bundle/direct/dresources/genie_agent.go b/bundle/direct/dresources/genie_agent.go new file mode 100644 index 00000000000..37896de2a91 --- /dev/null +++ b/bundle/direct/dresources/genie_agent.go @@ -0,0 +1,164 @@ +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 { + return &input.GenieAgentConfig +} + +// genieAgentBody builds the GenieAgent write payload from the bundle config. +// `name` is server-derived and the create/update paths carry the id, so it is +// never sent; the remaining fields are output-only and stay zero. +func genieAgentBody(config *resources.GenieAgentConfig) genieagents.GenieAgent { + body := genieagents.GenieAgent{ + DisplayName: config.DisplayName, + Description: config.Description, + WarehouseId: config.WarehouseId, + ParentPath: config.ParentPath, + + // A nil config definition marshals as the zero value, which the API + // rejects (the definition must set at least one field). + Definition: genieagents.GenieAgentDefinition{ + Benchmarks: nil, + Config: nil, + DataSources: nil, + Instructions: nil, + }, + + // Output-only fields; `name` is carried by the request path. + Name: "", + Etag: "", + CreateTime: nil, + UpdateTime: nil, + EffectiveParentPath: "", + ForceSendFields: nil, + } + if config.Definition != nil { + body.Definition = *config.Definition + } + return body +} + +// responseToGenieAgentConfig converts a returned GenieAgent into the bundle +// state. The server-derived name, etag, timestamps and effective_parent_path +// have no config counterpart and are dropped here. +func responseToGenieAgentConfig(agent *genieagents.GenieAgent) *resources.GenieAgentConfig { + definition := agent.Definition + return &resources.GenieAgentConfig{ + GenieAgentId: strings.TrimPrefix(agent.Name, genieAgentNamePrefix), + DisplayName: agent.DisplayName, + Description: agent.Description, + Definition: &definition, + WarehouseId: agent.WarehouseId, + ParentPath: agent.ParentPath, + ForceSendFields: nil, + } +} + +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. That +// the Agents API surfaces one of those shapes is confirmed by the lifecycle +// test's cloud run. +func (r *ResourceGenieAgent) DoCreate(ctx context.Context, config *resources.GenieAgentConfig) (string, *resources.GenieAgentConfig, error) { + req := genieagents.CreateGenieAgentRequest{ + GenieAgent: genieAgentBody(config), + 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 lifecycle acceptance test exercises +// this mask against a real workspace. +// +// Etag is intentionally left empty (here and in DoDelete): it guards concurrent +// definition edits, which a serial bundle deploy does not have. Drift is +// detected on read by comparing the full config against the GET response, +// matching ResourceMcpService. +func (r *ResourceGenieAgent) DoUpdate(ctx context.Context, id string, config *resources.GenieAgentConfig, _ *PlanEntry) (*resources.GenieAgentConfig, error) { + resp, err := r.client.GenieAgents.UpdateGenieAgent(ctx, genieagents.UpdateGenieAgentRequest{ + GenieAgent: genieAgentBody(config), + Name: genieAgentNamePrefix + id, + UpdateMask: fieldmask.FieldMask{Paths: []string{"*"}}, + Etag: "", + ForceSendFields: nil, + }) + if err != nil { + return nil, err + } + return responseToGenieAgentConfig(resp), nil +} + +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/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 230a7459dd7..e694af98083 100644 --- a/bundle/internal/schema/annotations.yml +++ b/bundle/internal/schema/annotations.yml @@ -1038,6 +1038,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. + "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. If omitted, the caller's home folder is used. 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/validation/generated/enum_fields.go b/bundle/internal/validation/generated/enum_fields.go index c2b7a092791..982286be034 100644 --- a/bundle/internal/validation/generated/enum_fields.go +++ b/bundle/internal/validation/generated/enum_fields.go @@ -76,6 +76,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 760d14d9178..f1fa1cfb2e5 100644 --- a/bundle/internal/validation/generated/required_fields.go +++ b/bundle/internal/validation/generated/required_fields.go @@ -143,6 +143,27 @@ var RequiredFields = map[string][]string{ "resources.features.*.time_window.tumbling": {"window_duration"}, "resources.features.*.timeseries_column": {"name"}, + "resources.genie_agents.*": {"display_name", "warehouse_id", "definition"}, + "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 9c4d4b178cb..996de042aef 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 07fed65ba80..2f1a49a59a4 100644 --- a/bundle/phases/destroy.go +++ b/bundle/phases/destroy.go @@ -45,6 +45,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 0e7a29a9c82..ede135a93f4 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 @@ -116,6 +120,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 afb5a80db72..1a3a55325d7 100644 --- a/bundle/schema/jsonschema.json +++ b/bundle/schema/jsonschema.json @@ -1231,6 +1231,61 @@ } ] }, + "resources.GenieAgent": { + "oneOf": [ + { + "type": "object", + "description": "[Private Preview]", + "properties": { + "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.", + "$ref": "#/$defs/github.com/databricks/databricks-sdk-go/service/genieagents.GenieAgentDefinition" + }, + "description": { + "description": "Description of the Genie Agent. The maximum length is 4,096 characters.", + "$ref": "#/$defs/string" + }, + "display_name": { + "description": "Display name of the Genie Agent. Must be unique within its folder. The maximum length is 63 characters.", + "$ref": "#/$defs/string" + }, + "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.", + "$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": "Workspace folder in which to create the Genie Agent. If omitted, the caller's home folder is used. On update, setting it moves the agent and clearing it does not.", + "$ref": "#/$defs/string" + }, + "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": "ID of the SQL warehouse used by this Genie Agent.", + "$ref": "#/$defs/string" + } + }, + "additionalProperties": false, + "required": [ + "display_name", + "warehouse_id", + "definition" + ], + "x-databricks-launch-stage": "PRIVATE_PREVIEW", + "doNotSuggest": true + }, + { + "type": "string", + "pattern": "\\$\\{(var(\\._*\\p{L}+([-_]*[\\p{L}\\p{N}]+)*(\\[[0-9]+\\])*)+)\\}" + } + ] + }, "resources.GenieSpace": { "oneOf": [ { @@ -4421,6 +4476,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" }, @@ -9836,24 +9895,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", @@ -9861,12 +10850,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", @@ -9874,27 +10881,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" ] }, { @@ -22082,6 +23090,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": [ { @@ -23121,6 +24143,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..beec4ab1128 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,7 @@ type FakeWorkspace struct { Dashboards *EventualMap[string, *fakeDashboard] PublishedDashboards map[string]dashboards.PublishedDashboard GenieSpaces map[string]dashboards.GenieSpace + GenieAgents map[string]genieagents.GenieAgent SqlWarehouses map[string]sql.GetWarehouseResponse Alerts map[string]sql.AlertV2 PurgedAlertIDs map[string]bool @@ -553,6 +555,7 @@ 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{}, 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..d85c8bd4439 --- /dev/null +++ b/libs/testserver/genie_agents.go @@ -0,0 +1,162 @@ +package testserver + +import ( + "encoding/json" + "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 { + 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 + agent.ParentPath = parentPath + agent.EffectiveParentPath = parentPath + 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 + } + + var body genieagents.GenieAgent + if err := json.Unmarshal(req.Body, &body); err != nil { + return genieAgentInvalidRequest(err) + } + + // 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 = body.ParentPath + } + 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"] + if _, ok := s.GenieAgents[agentId]; !ok { + return genieAgentNotFound() + } + + delete(s.GenieAgents, agentId) + + 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 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 293066caf3c..d8cad6cca0e 100644 --- a/libs/testserver/handlers.go +++ b/libs/testserver/handlers.go @@ -664,6 +664,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", From 919cf9f8c4856218639c6e6420c5e9915a0507b0 Mon Sep 17 00:00:00 2001 From: Eric Cho Date: Mon, 16 Nov 2026 21:04:29 +0000 Subject: [PATCH 2/6] Fix genie_agents test configs and parent_path handling - Point the genie_agents acceptance and invariant configs at samples.nyctaxi.trips instead of the example sales table so cloud runs can read the referenced data, and adjust the sample questions and descriptions to match. - Normalize genie agent parent_path like genie_spaces: add the /Workspace prefix on read and to the bundle config, and strip it before storing in the fake server, so GET responses match the local configuration. - Drop the fake server's etag from the genie_agents acceptance goldens since it cannot match a real backend, and extend the genie_agent bind test with plan/deploy/unbind/destroy coverage. - Document the bundle parent_path default (${workspace.resource_path}) instead of the raw API default, and regenerate the bundle JSON schema. Co-authored-by: Isaac --- .nextchanges/bundles/genie_agents.md | 2 +- .../{databricks.yml => databricks.yml.tmpl} | 5 +- .../deployment/bind/genie_agent/output.txt | 52 ++++++++++--------- .../bundle/deployment/bind/genie_agent/script | 19 +++++-- .../bind/genie_agent/script.prepare | 2 +- .../invariant/configs/genie_agent.yml.tmpl | 4 +- .../genie_agents/basic/databricks.yml | 6 +-- .../resources/genie_agents/basic/output.txt | 36 ++++++------- .../lifecycle/databricks.yml.tmpl | 6 +-- .../genie_agents/lifecycle/output.txt | 12 ++--- .../resources/genie_agents/lifecycle/script | 2 +- .../genie_agents/remote-delete/databricks.yml | 2 +- .../resources/genie_agents/script.prepare | 6 ++- .../resourcemutator/genie_agent_fixups.go | 30 +++++++++++ .../resourcemutator/resource_mutator.go | 5 ++ bundle/config/resources/genie_agent.go | 6 +-- bundle/direct/dresources/genie_agent.go | 16 +++--- bundle/internal/schema/annotations.yml | 2 +- bundle/schema/jsonschema.json | 2 +- libs/testserver/genie_agents.go | 25 +++++++-- 20 files changed, 154 insertions(+), 86 deletions(-) rename acceptance/bundle/deployment/bind/genie_agent/{databricks.yml => databricks.yml.tmpl} (54%) create mode 100644 bundle/config/mutator/resourcemutator/genie_agent_fixups.go diff --git a/.nextchanges/bundles/genie_agents.md b/.nextchanges/bundles/genie_agents.md index ca5f10a3d89..55b7bade691 100644 --- a/.nextchanges/bundles/genie_agents.md +++ b/.nextchanges/bundles/genie_agents.md @@ -1 +1 @@ -* Add the `genie_agents` resource for managing AI/BI Genie agents on the direct deployment engine. +* 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 b/acceptance/bundle/deployment/bind/genie_agent/databricks.yml.tmpl similarity index 54% rename from acceptance/bundle/deployment/bind/genie_agent/databricks.yml rename to acceptance/bundle/deployment/bind/genie_agent/databricks.yml.tmpl index ca373223061..93c16f1ef3c 100644 --- a/acceptance/bundle/deployment/bind/genie_agent/databricks.yml +++ b/acceptance/bundle/deployment/bind/genie_agent/databricks.yml.tmpl @@ -7,8 +7,11 @@ resources: 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 were total sales last month? + question: What was the average trip distance last month? diff --git a/acceptance/bundle/deployment/bind/genie_agent/output.txt b/acceptance/bundle/deployment/bind/genie_agent/output.txt index ef44e06497c..89723ba93d7 100644 --- a/acceptance/bundle/deployment/bind/genie_agent/output.txt +++ b/acceptance/bundle/deployment/bind/genie_agent/output.txt @@ -5,7 +5,7 @@ "definition": { "config": { "sample_questions": [ - {"id": "01f0a1b2c3d4e5f60718293a4b5c6d7f", "question": "What were total sales last month?"} + {"id": "01f0a1b2c3d4e5f60718293a4b5c6d7f", "question": "What was the average trip distance last month?"} ] } } @@ -13,36 +13,38 @@ { "name": "agents/01f0a1b2c3d4e5f60718293a4b5c6d7e", "display_name": "bound-agent", - "warehouse_id": "test-warehouse-id", - "etag": "1" + "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 summary -Name: test-bundle -Target: default -Workspace: - User: [USERNAME] - Path: /Workspace/Users/[USERNAME]/.bundle/test-bundle/default -Resources: - Genie Agents: - agent1: - Name: bound-agent - URL: [DATABRICKS_URL]/genie/rooms/01f0a1b2c3d4e5f60718293a4b5c6d7e?w=[WORKSPACE_ID] +>>> [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 summary -Name: test-bundle -Target: default -Workspace: - User: [USERNAME] - Path: /Workspace/Users/[USERNAME]/.bundle/test-bundle/default -Resources: - Genie Agents: - agent1: - Name: bound-agent - URL: (not deployed) +>>> [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 index 73ae2b63c87..24339b540d9 100644 --- a/acceptance/bundle/deployment/bind/genie_agent/script +++ b/acceptance/bundle/deployment/bind/genie_agent/script @@ -1,5 +1,7 @@ AGENT="01f0a1b2c3d4e5f60718293a4b5c6d7e" +envsubst < databricks.yml.tmpl > databricks.yml + # Create the object outside the bundle with the CLI's own create command. trace $CLI genie-agents create-genie-agent --json '{ "display_name": "bound-agent", @@ -7,14 +9,25 @@ trace $CLI genie-agents create-genie-agent --json '{ "definition": { "config": { "sample_questions": [ - {"id": "01f0a1b2c3d4e5f60718293a4b5c6d7f", "question": "What were total sales last month?"} + {"id": "01f0a1b2c3d4e5f60718293a4b5c6d7f", "question": "What was the average trip distance last month?"} ] } } }' --genie-agent-id "$AGENT" | agent_fields trace $CLI bundle deployment bind agent1 "$AGENT" --auto-approve -trace $CLI bundle summary + +# Bind copies the remote object into state, so the first plan after bind must +# be clean (no recreate). +trace $CLI bundle plan + +trace $CLI bundle deploy + +trace $CLI genie-agents get-genie-agent "agents/$AGENT" | agent_fields trace $CLI bundle deployment unbind agent1 -trace $CLI bundle summary + +trace $CLI bundle destroy --auto-approve + +# Read the Genie agent again (expecting it still exists and is not deleted): +trace $CLI genie-agents get-genie-agent "agents/$AGENT" | agent_fields diff --git a/acceptance/bundle/deployment/bind/genie_agent/script.prepare b/acceptance/bundle/deployment/bind/genie_agent/script.prepare index 96d3dc77ef2..421de05e29d 100644 --- a/acceptance/bundle/deployment/bind/genie_agent/script.prepare +++ b/acceptance/bundle/deployment/bind/genie_agent/script.prepare @@ -1,4 +1,4 @@ # Project a genie agent read to the fields the test asserts. agent_fields() { - jq '{name, display_name, warehouse_id, etag}' + jq '{name, display_name, warehouse_id}' } diff --git a/acceptance/bundle/invariant/configs/genie_agent.yml.tmpl b/acceptance/bundle/invariant/configs/genie_agent.yml.tmpl index 9de3b1120f2..c392aee915e 100644 --- a/acceptance/bundle/invariant/configs/genie_agent.yml.tmpl +++ b/acceptance/bundle/invariant/configs/genie_agent.yml.tmpl @@ -11,10 +11,10 @@ resources: config: sample_questions: - id: "01f0a1b2c3d4e5f60718293a4b5c6d7e" - question: What were total sales last month? + question: What was the average trip distance last month? data_sources: tables: - - identifier: main.sales.orders + - identifier: samples.nyctaxi.trips permissions: - level: CAN_READ group_name: users diff --git a/acceptance/bundle/resources/genie_agents/basic/databricks.yml b/acceptance/bundle/resources/genie_agents/basic/databricks.yml index 44973c3dbea..23be0b1bbce 100644 --- a/acceptance/bundle/resources/genie_agents/basic/databricks.yml +++ b/acceptance/bundle/resources/genie_agents/basic/databricks.yml @@ -12,8 +12,8 @@ resources: config: sample_questions: - id: "01f0a1b2c3d4e5f60718293a4b5c6d7f" - question: What were total sales last month? + question: What was the average trip distance last month? data_sources: tables: - - identifier: main.sales.orders - description: One row per order, with order date and amount. + - identifier: samples.nyctaxi.trips + description: One row per taxi trip, with pickup and drop-off times. diff --git a/acceptance/bundle/resources/genie_agents/basic/output.txt b/acceptance/bundle/resources/genie_agents/basic/output.txt index 4b706794a66..9f82435cca2 100644 --- a/acceptance/bundle/resources/genie_agents/basic/output.txt +++ b/acceptance/bundle/resources/genie_agents/basic/output.txt @@ -8,15 +8,15 @@ "sample_questions": [ { "id": "01f0a1b2c3d4e5f60718293a4b5c6d7f", - "question": "What were total sales last month?" + "question": "What was the average trip distance last month?" } ] }, "data_sources": { "tables": [ { - "description": "One row per order, with order date and amount.", - "identifier": "main.sales.orders" + "description": "One row per taxi trip, with pickup and drop-off times.", + "identifier": "samples.nyctaxi.trips" } ] } @@ -74,15 +74,15 @@ Resources: 1 created, 0 changed, 0 deleted, 0 unchanged "sample_questions": [ { "id": "01f0a1b2c3d4e5f60718293a4b5c6d7f", - "question": "What were total sales last month?" + "question": "What was the average trip distance last month?" } ] }, "data_sources": { "tables": [ { - "description": "One row per order, with order date and amount.", - "identifier": "main.sales.orders" + "description": "One row per taxi trip, with pickup and drop-off times.", + "identifier": "samples.nyctaxi.trips" } ] } @@ -112,15 +112,15 @@ Resources: 1 created, 0 changed, 0 deleted, 0 unchanged "sample_questions": [ { "id": "01f0a1b2c3d4e5f60718293a4b5c6d7f", - "question": "What were total sales last month?" + "question": "What was the average trip distance last month?" } ] }, "data_sources": { "tables": [ { - "description": "One row per order, with order date and amount.", - "identifier": "main.sales.orders" + "description": "One row per taxi trip, with pickup and drop-off times.", + "identifier": "samples.nyctaxi.trips" } ] } @@ -147,8 +147,7 @@ Resources: 1 created, 0 changed, 0 deleted, 0 unchanged "name": "agents/01f0a1b2c3d4e5f60718293a4b5c6d7e", "display_name": "my-agent", "description": "COMMENT1", - "warehouse_id": "test-warehouse-id", - "etag": "1" + "warehouse_id": "test-warehouse-id" } === Update description (should update in place, not recreate) @@ -174,15 +173,15 @@ Resources: 0 created, 1 changed, 0 deleted, 0 unchanged "sample_questions": [ { "id": "01f0a1b2c3d4e5f60718293a4b5c6d7f", - "question": "What were total sales last month?" + "question": "What was the average trip distance last month?" } ] }, "data_sources": { "tables": [ { - "description": "One row per order, with order date and amount.", - "identifier": "main.sales.orders" + "description": "One row per taxi trip, with pickup and drop-off times.", + "identifier": "samples.nyctaxi.trips" } ] } @@ -199,8 +198,7 @@ Resources: 0 created, 1 changed, 0 deleted, 0 unchanged "name": "agents/01f0a1b2c3d4e5f60718293a4b5c6d7e", "display_name": "my-agent", "description": "COMMENT2", - "warehouse_id": "test-warehouse-id", - "etag": "1" + "warehouse_id": "test-warehouse-id" } === Change the identity field (should plan a recreate) @@ -239,15 +237,15 @@ Resources: 1 created, 0 changed, 1 deleted, 0 unchanged "sample_questions": [ { "id": "01f0a1b2c3d4e5f60718293a4b5c6d7f", - "question": "What were total sales last month?" + "question": "What was the average trip distance last month?" } ] }, "data_sources": { "tables": [ { - "description": "One row per order, with order date and amount.", - "identifier": "main.sales.orders" + "description": "One row per taxi trip, with pickup and drop-off times.", + "identifier": "samples.nyctaxi.trips" } ] } diff --git a/acceptance/bundle/resources/genie_agents/lifecycle/databricks.yml.tmpl b/acceptance/bundle/resources/genie_agents/lifecycle/databricks.yml.tmpl index 36fa6e5b3ac..3f590b69165 100644 --- a/acceptance/bundle/resources/genie_agents/lifecycle/databricks.yml.tmpl +++ b/acceptance/bundle/resources/genie_agents/lifecycle/databricks.yml.tmpl @@ -5,13 +5,13 @@ resources: genie_agents: agent: display_name: test_agent_$UNIQUE_NAME - description: "Agent grounded in sales tables" + description: "Agent grounded in taxi trip data" warehouse_id: $TEST_DEFAULT_WAREHOUSE_ID definition: config: sample_questions: - id: "01f0a1b2c3d4e5f60718293a4b5c6d7e" - question: What were total sales last month? + question: What was the average trip distance last month? data_sources: tables: - - identifier: main.sales.orders + - identifier: samples.nyctaxi.trips diff --git a/acceptance/bundle/resources/genie_agents/lifecycle/output.txt b/acceptance/bundle/resources/genie_agents/lifecycle/output.txt index 15f92edf306..6fb773b4dba 100644 --- a/acceptance/bundle/resources/genie_agents/lifecycle/output.txt +++ b/acceptance/bundle/resources/genie_agents/lifecycle/output.txt @@ -9,9 +9,8 @@ Resources: 1 created, 0 changed, 0 deleted, 0 unchanged { "name": "agents/[AGENT_ID]", "display_name": "test_agent_[UNIQUE_NAME]", - "description": "Agent grounded in sales tables", - "warehouse_id": "[TEST_DEFAULT_WAREHOUSE_ID]", - "etag": "1" + "description": "Agent grounded in taxi trip data", + "warehouse_id": "[TEST_DEFAULT_WAREHOUSE_ID]" } >>> [CLI] bundle plan @@ -19,7 +18,7 @@ Plan: 0 to add, 0 to change, 0 to delete, 1 unchanged === Update description in place ->>> update_file.py databricks.yml Agent grounded in sales tables Agent grounded in sales tables, updated +>>> 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... @@ -31,9 +30,8 @@ Resources: 0 created, 1 changed, 0 deleted, 0 unchanged { "name": "agents/[AGENT_ID]", "display_name": "test_agent_[UNIQUE_NAME]", - "description": "Agent grounded in sales tables, updated", - "warehouse_id": "[TEST_DEFAULT_WAREHOUSE_ID]", - "etag": "1" + "description": "Agent grounded in taxi trip data, updated", + "warehouse_id": "[TEST_DEFAULT_WAREHOUSE_ID]" } >>> [CLI] bundle plan diff --git a/acceptance/bundle/resources/genie_agents/lifecycle/script b/acceptance/bundle/resources/genie_agents/lifecycle/script index e67adbb3910..418009c0690 100644 --- a/acceptance/bundle/resources/genie_agents/lifecycle/script +++ b/acceptance/bundle/resources/genie_agents/lifecycle/script @@ -18,7 +18,7 @@ trace $CLI genie-agents get-genie-agent "agents/$AGENT" | agent_fields trace $CLI bundle plan title "Update description in place" -trace update_file.py databricks.yml "Agent grounded in sales tables" "Agent grounded in sales tables, updated" +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 diff --git a/acceptance/bundle/resources/genie_agents/remote-delete/databricks.yml b/acceptance/bundle/resources/genie_agents/remote-delete/databricks.yml index 1bff6d9b2ce..307d256ea38 100644 --- a/acceptance/bundle/resources/genie_agents/remote-delete/databricks.yml +++ b/acceptance/bundle/resources/genie_agents/remote-delete/databricks.yml @@ -11,4 +11,4 @@ resources: config: sample_questions: - id: "01f0a1b2c3d4e5f60718293a4b5c6d7f" - question: What were total sales last month? + question: What was the average trip distance last month? diff --git a/acceptance/bundle/resources/genie_agents/script.prepare b/acceptance/bundle/resources/genie_agents/script.prepare index 2d9bd50f07f..661fb3b8f30 100644 --- a/acceptance/bundle/resources/genie_agents/script.prepare +++ b/acceptance/bundle/resources/genie_agents/script.prepare @@ -1,4 +1,6 @@ -# Project a genie agent read to the fields the test asserts. +# 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, etag}' + jq '{name, display_name, description, warehouse_id}' } diff --git a/bundle/config/mutator/resourcemutator/genie_agent_fixups.go b/bundle/config/mutator/resourcemutator/genie_agent_fixups.go new file mode 100644 index 00000000000..7984f8342c2 --- /dev/null +++ b/bundle/config/mutator/resourcemutator/genie_agent_fixups.go @@ -0,0 +1,30 @@ +package resourcemutator + +import ( + "context" + + "github.com/databricks/cli/bundle" + "github.com/databricks/cli/libs/diag" +) + +type genieAgentFixups struct{} + +func GenieAgentFixups() bundle.Mutator { + return &genieAgentFixups{} +} + +func (m *genieAgentFixups) Name() string { + return "GenieAgentFixups" +} + +func (m *genieAgentFixups) Apply(ctx context.Context, b *bundle.Bundle) diag.Diagnostics { + for _, genieAgent := range b.Config.Resources.GenieAgents { + if genieAgent == nil { + continue + } + + genieAgent.ParentPath = ensureWorkspacePrefix(genieAgent.ParentPath) + } + + return nil +} diff --git a/bundle/config/mutator/resourcemutator/resource_mutator.go b/bundle/config/mutator/resourcemutator/resource_mutator.go index 16fb6555fdf..e8baecff12d 100644 --- a/bundle/config/mutator/resourcemutator/resource_mutator.go +++ b/bundle/config/mutator/resourcemutator/resource_mutator.go @@ -118,6 +118,11 @@ func applyInitializeMutators(ctx context.Context, b *bundle.Bundle) { // Ensures genie space parent paths have the required /Workspace prefix GenieSpaceFixups(), + // Reads (typed): b.Config.Resources.GenieAgents (checks genie agent configurations) + // Updates (typed): b.Config.Resources.GenieAgents[].ParentPath (ensures /Workspace prefix is present) + // Ensures genie agent parent paths have the required /Workspace prefix + GenieAgentFixups(), + // Reads (typed): b.Config.Permissions (validates permission levels) // Reads (dynamic): resources.{jobs,pipelines,experiments,models,model_serving_endpoints,dashboards,apps,vector_search_endpoints,...}.*.permissions (reads existing permissions) // Updates (dynamic): resources.{jobs,pipelines,experiments,models,model_serving_endpoints,dashboards,apps,vector_search_endpoints,...}.*.permissions (adds permissions from bundle-level configuration) diff --git a/bundle/config/resources/genie_agent.go b/bundle/config/resources/genie_agent.go index f0b9bb034db..0c668f69a4f 100644 --- a/bundle/config/resources/genie_agent.go +++ b/bundle/config/resources/genie_agent.go @@ -32,9 +32,9 @@ type GenieAgentConfig struct { Description string `json:"description,omitempty"` // Warehouse associated with the Genie Agent. WarehouseId string `json:"warehouse_id"` - // The workspace folder to create the Genie Agent in. If omitted, the - // caller's home folder is used. On update, setting it moves the agent and - // clearing it does not. + // The workspace folder to create the Genie Agent in. Defaults to the + // bundle's workspace resource path (${workspace.resource_path}). On update, + // setting it moves the agent and clearing it does not. ParentPath string `json:"parent_path,omitempty"` // The definition of the Genie Agent: its sample questions, data sources, // instructions, and benchmarks. Must set at least one field. Replaced as a diff --git a/bundle/direct/dresources/genie_agent.go b/bundle/direct/dresources/genie_agent.go index 37896de2a91..15dd8c5cfd5 100644 --- a/bundle/direct/dresources/genie_agent.go +++ b/bundle/direct/dresources/genie_agent.go @@ -73,7 +73,9 @@ func genieAgentBody(config *resources.GenieAgentConfig) genieagents.GenieAgent { // responseToGenieAgentConfig converts a returned GenieAgent into the bundle // state. The server-derived name, etag, timestamps and effective_parent_path -// have no config counterpart and are dropped here. +// have no config counterpart and are dropped here. GET returns the parent path +// without the /Workspace prefix, so ensureWorkspacePrefix re-adds it to match +// the local configuration (same handling as ResourceGenieSpace). func responseToGenieAgentConfig(agent *genieagents.GenieAgent) *resources.GenieAgentConfig { definition := agent.Definition return &resources.GenieAgentConfig{ @@ -82,7 +84,7 @@ func responseToGenieAgentConfig(agent *genieagents.GenieAgent) *resources.GenieA Description: agent.Description, Definition: &definition, WarehouseId: agent.WarehouseId, - ParentPath: agent.ParentPath, + ParentPath: ensureWorkspacePrefix(agent.ParentPath), ForceSendFields: nil, } } @@ -103,9 +105,10 @@ func (r *ResourceGenieAgent) DoRead(ctx context.Context, id string) (*resources. // 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. That -// the Agents API surfaces one of those shapes is confirmed by the lifecycle -// test's cloud run. +// 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: genieAgentBody(config), @@ -132,8 +135,7 @@ func (r *ResourceGenieAgent) DoCreate(ctx context.Context, config *resources.Gen // 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 lifecycle acceptance test exercises -// this mask against a real workspace. +// paths within it are not supported. // // Etag is intentionally left empty (here and in DoDelete): it guards concurrent // definition edits, which a serial bundle deploy does not have. Drift is diff --git a/bundle/internal/schema/annotations.yml b/bundle/internal/schema/annotations.yml index 1bec75bb7a4..e39b5001f2b 100644 --- a/bundle/internal/schema/annotations.yml +++ b/bundle/internal/schema/annotations.yml @@ -1014,7 +1014,7 @@ resources: 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. If omitted, the caller's home folder is used. On update, setting it moves the agent and clearing it does not. + 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. diff --git a/bundle/schema/jsonschema.json b/bundle/schema/jsonschema.json index 564c15792ec..e1a40bf26f3 100644 --- a/bundle/schema/jsonschema.json +++ b/bundle/schema/jsonschema.json @@ -1261,7 +1261,7 @@ "$ref": "#/$defs/github.com/databricks/cli/bundle/config/resources.Lifecycle" }, "parent_path": { - "description": "Workspace folder in which to create the Genie Agent. If omitted, the caller's home folder is used. On update, setting it moves the agent and clearing it does not.", + "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.", "$ref": "#/$defs/string" }, "permissions": { diff --git a/libs/testserver/genie_agents.go b/libs/testserver/genie_agents.go index d85c8bd4439..c0ca3b7d692 100644 --- a/libs/testserver/genie_agents.go +++ b/libs/testserver/genie_agents.go @@ -2,6 +2,7 @@ package testserver import ( "encoding/json" + "strings" "time" sdktime "github.com/databricks/databricks-sdk-go/common/types/time" @@ -56,8 +57,11 @@ func (s *FakeWorkspace) GenieAgentCreate(req Request) Response { agent := body agent.Name = "agents/" + agentId - agent.ParentPath = parentPath - agent.EffectiveParentPath = parentPath + // Strip the /Workspace prefix from parent_path before storing. This matches + // the remote behavior: the GET API returns parent_path without the prefix, + // mirroring GenieSpaceCreate. + agent.ParentPath = trimWorkspacePrefix(parentPath) + agent.EffectiveParentPath = agent.ParentPath agent.CreateTime = sdktime.New(time.Now()) agent.UpdateTime = sdktime.New(time.Now()) agent.Etag = "1" @@ -98,14 +102,15 @@ func (s *FakeWorkspace) GenieAgentUpdate(req Request) Response { // 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). + // cleared, matching the update_mask contract). The stored path drops the + // /Workspace prefix, mirroring GenieSpaceUpdate. agent.DisplayName = body.DisplayName agent.Description = body.Description agent.Definition = body.Definition agent.WarehouseId = body.WarehouseId - agent.ParentPath = body.ParentPath + agent.ParentPath = trimWorkspacePrefix(body.ParentPath) if body.ParentPath != "" { - agent.EffectiveParentPath = body.ParentPath + agent.EffectiveParentPath = agent.ParentPath } agent.UpdateTime = sdktime.New(time.Now()) @@ -131,6 +136,16 @@ func (s *FakeWorkspace) GenieAgentDelete(req Request) Response { } } +// trimWorkspacePrefix drops the /Workspace prefix from a parent_path before it +// is stored, matching GenieSpaceCreate/GenieSpaceUpdate: the GET API returns +// parent_path without the prefix. +func trimWorkspacePrefix(parentPath string) string { + if strings.HasPrefix(parentPath, "/Workspace/") { + return strings.TrimPrefix(parentPath, "/Workspace") + } + return parentPath +} + // 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] From d1f61740709ce376b6db5668124b923bab9a1427 Mon Sep 17 00:00:00 2001 From: Eric Cho Date: Mon, 16 Nov 2026 23:33:19 +0000 Subject: [PATCH 3/6] Reserve trashed genie agent IDs and echo parent_path - Deleting an agent moves it to trash, where its ID stays reserved, so a create with a pinned genie_agent_id returns ALREADY_EXISTS. The test server now models this, the remote-delete test records the failing redeploy, and the genie_agent_id docs warn about reusing a pinned ID after bundle destroy. - The Agents API returns parent_path exactly as submitted. Stop adding the /Workspace prefix on read, drop the prefix-only config fixup, and have the test server echo parent_path unchanged. Only effective_parent_path, which the adapter does not read, may omit /Workspace. Co-authored-by: Isaac --- .../deployment/bind/genie_agent/output.txt | 1 + .../bundle/deployment/bind/genie_agent/script | 11 +++++-- .../genie_agents/remote-delete/output.txt | 27 ++++++++++++++++- .../genie_agents/remote-delete/script | 11 ++++++- .../resourcemutator/genie_agent_fixups.go | 30 ------------------- .../resourcemutator/resource_mutator.go | 5 ---- bundle/config/resources/genie_agent.go | 4 ++- bundle/direct/dresources/genie_agent.go | 7 ++--- bundle/internal/schema/annotations.yml | 2 +- bundle/schema/jsonschema.json | 2 +- libs/testserver/fake_workspace.go | 2 ++ libs/testserver/genie_agents.go | 28 +++++------------ 12 files changed, 63 insertions(+), 67 deletions(-) delete mode 100644 bundle/config/mutator/resourcemutator/genie_agent_fixups.go diff --git a/acceptance/bundle/deployment/bind/genie_agent/output.txt b/acceptance/bundle/deployment/bind/genie_agent/output.txt index 89723ba93d7..bbab2ef84dd 100644 --- a/acceptance/bundle/deployment/bind/genie_agent/output.txt +++ b/acceptance/bundle/deployment/bind/genie_agent/output.txt @@ -2,6 +2,7 @@ >>> [CLI] genie-agents create-genie-agent --json { "display_name": "bound-agent", "warehouse_id": "test-warehouse-id", + "parent_path": "/Users/[USERNAME]", "definition": { "config": { "sample_questions": [ diff --git a/acceptance/bundle/deployment/bind/genie_agent/script b/acceptance/bundle/deployment/bind/genie_agent/script index 24339b540d9..1fe7ca8504f 100644 --- a/acceptance/bundle/deployment/bind/genie_agent/script +++ b/acceptance/bundle/deployment/bind/genie_agent/script @@ -2,10 +2,12 @@ AGENT="01f0a1b2c3d4e5f60718293a4b5c6d7e" envsubst < databricks.yml.tmpl > databricks.yml -# Create the object outside the bundle with the CLI's own create command. -trace $CLI genie-agents create-genie-agent --json '{ +# Create the object outside the bundle in the same folder as its local config. +AGENT_CONFIG=$(cat <>> [CLI] genie-agents delete-genie-agent agents/01f0a1b2c3d4e5f60718293a4b5c6d7e -=== Plan should detect the resource is gone and re-create it +=== 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 +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 +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 diff --git a/acceptance/bundle/resources/genie_agents/remote-delete/script b/acceptance/bundle/resources/genie_agents/remote-delete/script index f1790035ec6..714bc673470 100644 --- a/acceptance/bundle/resources/genie_agents/remote-delete/script +++ b/acceptance/bundle/resources/genie_agents/remote-delete/script @@ -3,7 +3,16 @@ trace $CLI bundle deploy title "Delete the resource out of band" trace $CLI genie-agents delete-genie-agent agents/01f0a1b2c3d4e5f60718293a4b5c6d7e -title "Plan should detect the resource is gone and re-create it" +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" +musterr $CLI bundle deploy + +trace $CLI bundle destroy --auto-approve + +# Destroy clears bundle state, but the trashed agent still reserves its ID. +musterr $CLI bundle deploy + trace $CLI bundle destroy --auto-approve diff --git a/bundle/config/mutator/resourcemutator/genie_agent_fixups.go b/bundle/config/mutator/resourcemutator/genie_agent_fixups.go deleted file mode 100644 index 7984f8342c2..00000000000 --- a/bundle/config/mutator/resourcemutator/genie_agent_fixups.go +++ /dev/null @@ -1,30 +0,0 @@ -package resourcemutator - -import ( - "context" - - "github.com/databricks/cli/bundle" - "github.com/databricks/cli/libs/diag" -) - -type genieAgentFixups struct{} - -func GenieAgentFixups() bundle.Mutator { - return &genieAgentFixups{} -} - -func (m *genieAgentFixups) Name() string { - return "GenieAgentFixups" -} - -func (m *genieAgentFixups) Apply(ctx context.Context, b *bundle.Bundle) diag.Diagnostics { - for _, genieAgent := range b.Config.Resources.GenieAgents { - if genieAgent == nil { - continue - } - - genieAgent.ParentPath = ensureWorkspacePrefix(genieAgent.ParentPath) - } - - return nil -} diff --git a/bundle/config/mutator/resourcemutator/resource_mutator.go b/bundle/config/mutator/resourcemutator/resource_mutator.go index e8baecff12d..16fb6555fdf 100644 --- a/bundle/config/mutator/resourcemutator/resource_mutator.go +++ b/bundle/config/mutator/resourcemutator/resource_mutator.go @@ -118,11 +118,6 @@ func applyInitializeMutators(ctx context.Context, b *bundle.Bundle) { // Ensures genie space parent paths have the required /Workspace prefix GenieSpaceFixups(), - // Reads (typed): b.Config.Resources.GenieAgents (checks genie agent configurations) - // Updates (typed): b.Config.Resources.GenieAgents[].ParentPath (ensures /Workspace prefix is present) - // Ensures genie agent parent paths have the required /Workspace prefix - GenieAgentFixups(), - // Reads (typed): b.Config.Permissions (validates permission levels) // Reads (dynamic): resources.{jobs,pipelines,experiments,models,model_serving_endpoints,dashboards,apps,vector_search_endpoints,...}.*.permissions (reads existing permissions) // Updates (dynamic): resources.{jobs,pipelines,experiments,models,model_serving_endpoints,dashboards,apps,vector_search_endpoints,...}.*.permissions (adds permissions from bundle-level configuration) diff --git a/bundle/config/resources/genie_agent.go b/bundle/config/resources/genie_agent.go index 0c668f69a4f..3b03475f239 100644 --- a/bundle/config/resources/genie_agent.go +++ b/bundle/config/resources/genie_agent.go @@ -23,7 +23,9 @@ import ( type GenieAgentConfig struct { // 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. + // 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"` // Display name of the Genie Agent. Must be unique within its folder. The // maximum length is 63 characters. diff --git a/bundle/direct/dresources/genie_agent.go b/bundle/direct/dresources/genie_agent.go index 15dd8c5cfd5..d61a5503fe1 100644 --- a/bundle/direct/dresources/genie_agent.go +++ b/bundle/direct/dresources/genie_agent.go @@ -73,9 +73,8 @@ func genieAgentBody(config *resources.GenieAgentConfig) genieagents.GenieAgent { // responseToGenieAgentConfig converts a returned GenieAgent into the bundle // state. The server-derived name, etag, timestamps and effective_parent_path -// have no config counterpart and are dropped here. GET returns the parent path -// without the /Workspace prefix, so ensureWorkspacePrefix re-adds it to match -// the local configuration (same handling as ResourceGenieSpace). +// have no config counterpart and are dropped here. The API returns parent_path +// exactly as submitted; effective_parent_path may omit /Workspace and is ignored. func responseToGenieAgentConfig(agent *genieagents.GenieAgent) *resources.GenieAgentConfig { definition := agent.Definition return &resources.GenieAgentConfig{ @@ -84,7 +83,7 @@ func responseToGenieAgentConfig(agent *genieagents.GenieAgent) *resources.GenieA Description: agent.Description, Definition: &definition, WarehouseId: agent.WarehouseId, - ParentPath: ensureWorkspacePrefix(agent.ParentPath), + ParentPath: agent.ParentPath, ForceSendFields: nil, } } diff --git a/bundle/internal/schema/annotations.yml b/bundle/internal/schema/annotations.yml index e39b5001f2b..5317e3ce0a6 100644 --- a/bundle/internal/schema/annotations.yml +++ b/bundle/internal/schema/annotations.yml @@ -1008,7 +1008,7 @@ resources: 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. + 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. diff --git a/bundle/schema/jsonschema.json b/bundle/schema/jsonschema.json index e1a40bf26f3..8e24970e284 100644 --- a/bundle/schema/jsonschema.json +++ b/bundle/schema/jsonschema.json @@ -1253,7 +1253,7 @@ "$ref": "#/$defs/string" }, "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.", + "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": { diff --git a/libs/testserver/fake_workspace.go b/libs/testserver/fake_workspace.go index beec4ab1128..4c9295e9d52 100644 --- a/libs/testserver/fake_workspace.go +++ b/libs/testserver/fake_workspace.go @@ -234,6 +234,7 @@ type FakeWorkspace struct { 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 @@ -556,6 +557,7 @@ func NewFakeWorkspace(url, token string) *FakeWorkspace { 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 index c0ca3b7d692..2a6a24a4497 100644 --- a/libs/testserver/genie_agents.go +++ b/libs/testserver/genie_agents.go @@ -23,7 +23,7 @@ func (s *FakeWorkspace) GenieAgentCreate(req Request) Response { if agentId == "" { agentId, _ = generateGenieSpaceId() } - if _, ok := s.GenieAgents[agentId]; ok { + if _, ok := s.GenieAgents[agentId]; ok || s.GenieAgentIDsInTrash[agentId] { return Response{ StatusCode: 409, Body: map[string]string{ @@ -57,11 +57,9 @@ func (s *FakeWorkspace) GenieAgentCreate(req Request) Response { agent := body agent.Name = "agents/" + agentId - // Strip the /Workspace prefix from parent_path before storing. This matches - // the remote behavior: the GET API returns parent_path without the prefix, - // mirroring GenieSpaceCreate. - agent.ParentPath = trimWorkspacePrefix(parentPath) - agent.EffectiveParentPath = agent.ParentPath + // 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" @@ -102,15 +100,14 @@ func (s *FakeWorkspace) GenieAgentUpdate(req Request) Response { // 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). The stored path drops the - // /Workspace prefix, mirroring GenieSpaceUpdate. + // cleared, matching the update_mask contract). agent.DisplayName = body.DisplayName agent.Description = body.Description agent.Definition = body.Definition agent.WarehouseId = body.WarehouseId - agent.ParentPath = trimWorkspacePrefix(body.ParentPath) + agent.ParentPath = body.ParentPath if body.ParentPath != "" { - agent.EffectiveParentPath = agent.ParentPath + agent.EffectiveParentPath = strings.TrimPrefix(body.ParentPath, "/Workspace") } agent.UpdateTime = sdktime.New(time.Now()) @@ -130,22 +127,13 @@ func (s *FakeWorkspace) GenieAgentDelete(req Request) Response { } delete(s.GenieAgents, agentId) + s.GenieAgentIDsInTrash[agentId] = true return Response{ StatusCode: 200, } } -// trimWorkspacePrefix drops the /Workspace prefix from a parent_path before it -// is stored, matching GenieSpaceCreate/GenieSpaceUpdate: the GET API returns -// parent_path without the prefix. -func trimWorkspacePrefix(parentPath string) string { - if strings.HasPrefix(parentPath, "/Workspace/") { - return strings.TrimPrefix(parentPath, "/Workspace") - } - return parentPath -} - // 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] From fcf1cea6414ab8367f6ee7057ad28dd88a6b5e09 Mon Sep 17 00:00:00 2001 From: Eric Cho Date: Tue, 17 Nov 2026 00:34:44 +0000 Subject: [PATCH 4/6] Trace the failing redeploys in the genie_agents remote-delete test Co-authored-by: Isaac --- .../bundle/resources/genie_agents/remote-delete/output.txt | 4 ++++ acceptance/bundle/resources/genie_agents/remote-delete/script | 4 ++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/acceptance/bundle/resources/genie_agents/remote-delete/output.txt b/acceptance/bundle/resources/genie_agents/remote-delete/output.txt index 88a31d94283..4b571f5d287 100644 --- a/acceptance/bundle/resources/genie_agents/remote-delete/output.txt +++ b/acceptance/bundle/resources/genie_agents/remote-delete/output.txt @@ -17,6 +17,8 @@ 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) @@ -31,6 +33,8 @@ Files: 0 uploaded, 0 deleted 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) diff --git a/acceptance/bundle/resources/genie_agents/remote-delete/script b/acceptance/bundle/resources/genie_agents/remote-delete/script index 714bc673470..5584a67e29c 100644 --- a/acceptance/bundle/resources/genie_agents/remote-delete/script +++ b/acceptance/bundle/resources/genie_agents/remote-delete/script @@ -8,11 +8,11 @@ trace $CLI bundle plan # Deleting an agent moves it to trash, where its pinned ID remains reserved. title "Deploy cannot reuse the pinned ID" -musterr $CLI bundle deploy +trace musterr $CLI bundle deploy trace $CLI bundle destroy --auto-approve # Destroy clears bundle state, but the trashed agent still reserves its ID. -musterr $CLI bundle deploy +trace musterr $CLI bundle deploy trace $CLI bundle destroy --auto-approve From f53ce63581e581a5ede7a74cbf1ded72b648a360 Mon Sep 17 00:00:00 2001 From: Eric Cho Date: Tue, 17 Nov 2026 22:19:00 +0000 Subject: [PATCH 5/6] Embed the SDK GenieAgent body in genie_agents and guard updates by etag GenieAgentConfig now embeds genieagents.GenieAgent instead of mirroring its fields, so the bundle schema and direct config follow the API body. The server-derived name is hidden from the schema and declared as a stable output field. Output-only fields are zeroed in PrepareState, so saved state and local diffs carry only the authored body. DoUpdate sends the etag from the plan's remote read as an optimistic concurrency precondition, so a definition edit made after planning fails the deploy instead of being overwritten. DoDelete sends no etag because it only receives the persisted state, and an etag saved at the last deploy would block destroy after any later definition edit. The fake server enforces the etag on update and delete, and bumps it when the definition changes. Co-authored-by: Isaac --- .../bundle/refschema/output/genie_agents.txt | 7 +- .../resources/genie_agents/basic/output.txt | 1 + .../resourcemutator/apply_target_mode_test.go | 1 + bundle/config/resources/genie_agent.go | 30 ++---- bundle/direct/dresources/all_test.go | 2 +- .../direct/dresources/apitypes.generated.yml | 2 +- .../configs/genie_agents.generated.yml | 11 +++ .../dresources/configs/genie_agents.yml | 10 ++ bundle/direct/dresources/genie_agent.go | 94 ++++++++----------- bundle/direct/dresources/genie_agent_test.go | 85 +++++++++++++++++ bundle/internal/schema/main.go | 16 +++- .../validation/generated/required_fields.go | 2 +- bundle/schema/jsonschema.json | 36 ++++--- libs/testserver/genie_agents.go | 28 +++++- 14 files changed, 229 insertions(+), 96 deletions(-) create mode 100644 bundle/direct/dresources/configs/genie_agents.generated.yml create mode 100644 bundle/direct/dresources/genie_agent_test.go diff --git a/acceptance/bundle/refschema/output/genie_agents.txt b/acceptance/bundle/refschema/output/genie_agents.txt index 55f432ff7de..7f5791b2ad2 100644 --- a/acceptance/bundle/refschema/output/genie_agents.txt +++ b/acceptance/bundle/refschema/output/genie_agents.txt @@ -1,4 +1,5 @@ -resources.genie_agents.*.definition *genieagents.GenieAgentDefinition ALL +resources.genie_agents.*.create_time *time.Time ALL +resources.genie_agents.*.definition genieagents.GenieAgentDefinition ALL resources.genie_agents.*.definition.benchmarks *genieagents.GenieAgentBenchmarks ALL resources.genie_agents.*.definition.benchmarks.questions []genieagents.GenieAgentBenchmarkQuestion ALL resources.genie_agents.*.definition.benchmarks.questions[*] genieagents.GenieAgentBenchmarkQuestion ALL @@ -104,6 +105,8 @@ resources.genie_agents.*.definition.instructions.text_instructions[*].content st resources.genie_agents.*.definition.instructions.text_instructions[*].id string ALL resources.genie_agents.*.description string ALL resources.genie_agents.*.display_name string ALL +resources.genie_agents.*.effective_parent_path string ALL +resources.genie_agents.*.etag string ALL resources.genie_agents.*.genie_agent_id string ALL resources.genie_agents.*.id string INPUT resources.genie_agents.*.lifecycle resources.Lifecycle INPUT @@ -112,7 +115,9 @@ resources.genie_agents.*.lifecycle.depends_on[*] resources.DependsOn INPUT resources.genie_agents.*.lifecycle.depends_on[*].resource string INPUT resources.genie_agents.*.lifecycle.prevent_destroy bool INPUT resources.genie_agents.*.modified_status string INPUT +resources.genie_agents.*.name string ALL resources.genie_agents.*.parent_path string ALL +resources.genie_agents.*.update_time *time.Time ALL resources.genie_agents.*.url string INPUT resources.genie_agents.*.warehouse_id string ALL resources.genie_agents.*.permissions.object_id string ALL diff --git a/acceptance/bundle/resources/genie_agents/basic/output.txt b/acceptance/bundle/resources/genie_agents/basic/output.txt index 9f82435cca2..815a0ea8273 100644 --- a/acceptance/bundle/resources/genie_agents/basic/output.txt +++ b/acceptance/bundle/resources/genie_agents/basic/output.txt @@ -165,6 +165,7 @@ Resources: 0 created, 1 changed, 0 deleted, 0 unchanged "method": "PATCH", "path": "/api/2.0/genie/agents/01f0a1b2c3d4e5f60718293a4b5c6d7e", "q": { + "etag": "1", "update_mask": "*" }, "body": { diff --git a/bundle/config/mutator/resourcemutator/apply_target_mode_test.go b/bundle/config/mutator/resourcemutator/apply_target_mode_test.go index 813bfe33c60..9c6d393cff3 100644 --- a/bundle/config/mutator/resourcemutator/apply_target_mode_test.go +++ b/bundle/config/mutator/resourcemutator/apply_target_mode_test.go @@ -584,6 +584,7 @@ func TestAppropriateResourcesAreRenamed(t *testing.T) { notUserNamed := []string{ "Apps", "Features", + "GenieAgents", "FeatureSpecs", "SecretScopes", "Secrets", diff --git a/bundle/config/resources/genie_agent.go b/bundle/config/resources/genie_agent.go index 3b03475f239..e7cde2501be 100644 --- a/bundle/config/resources/genie_agent.go +++ b/bundle/config/resources/genie_agent.go @@ -14,36 +14,20 @@ import ( // GenieAgentConfig is the bundle-authored state for a Genie Agent. // -// It mirrors ResourceMcpService: the SDK models the create input `genie_agent_id` -// as a URL parameter (`json:"-"`) outside the GenieAgent body and derives the -// resource `name` (`agents/{genie_agent_id}`) server-side, so we expose a flat -// struct with the identity plus the mutable body. The server-derived `name`, -// `etag`, timestamps and `effective_parent_path` stay out of the config type; -// the engine tracks the bare `genie_agent_id` as the resource id. +// 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"` - // Display name of the Genie Agent. Must be unique within its folder. The - // maximum length is 63 characters. - DisplayName string `json:"display_name"` - // Description of the Genie Agent. The maximum length is 4,096 characters. - Description string `json:"description,omitempty"` - // Warehouse associated with the Genie Agent. - WarehouseId string `json:"warehouse_id"` - // The workspace folder to create the Genie Agent in. Defaults to the - // bundle's workspace resource path (${workspace.resource_path}). On update, - // setting it moves the agent and clearing it does not. - ParentPath string `json:"parent_path,omitempty"` - // 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. - Definition *genieagents.GenieAgentDefinition `json:"definition"` - - ForceSendFields []string `json:"-" url:"-"` } func (c *GenieAgentConfig) UnmarshalJSON(b []byte) error { diff --git a/bundle/direct/dresources/all_test.go b/bundle/direct/dresources/all_test.go index 2981b9bdc8f..05d29ba2b49 100644 --- a/bundle/direct/dresources/all_test.go +++ b/bundle/direct/dresources/all_test.go @@ -343,7 +343,7 @@ var testConfig map[string]any = map[string]any{ Description: "Test genie agent", WarehouseId: "test-warehouse-id", ParentPath: "/Workspace/Users/user@example.com", - Definition: &genieagents.GenieAgentDefinition{ + Definition: genieagents.GenieAgentDefinition{ Config: &genieagents.GenieAgentConfig{ SampleQuestions: []genieagents.GenieAgentSampleQuestion{ {Id: "01f0a1b2c3d4e5f60718293a4b5c6d7e", Question: "What were total sales?"}, diff --git a/bundle/direct/dresources/apitypes.generated.yml b/bundle/direct/dresources/apitypes.generated.yml index 192325a8a13..d6f851317c4 100644 --- a/bundle/direct/dresources/apitypes.generated.yml +++ b/bundle/direct/dresources/apitypes.generated.yml @@ -26,7 +26,7 @@ feature_specs: ml.FeatureSpec features: ml.Feature -genie_agents: genieagents.CreateGenieAgentRequest +genie_agents: genieagents.GenieAgent genie_spaces: dashboards.GenieUpdateSpaceRequest 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 index 6bbc649b648..8db16a6834b 100644 --- a/bundle/direct/dresources/configs/genie_agents.yml +++ b/bundle/direct/dresources/configs/genie_agents.yml @@ -4,3 +4,13 @@ provided_id_fields: # 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 index d61a5503fe1..02a84cb8110 100644 --- a/bundle/direct/dresources/genie_agent.go +++ b/bundle/direct/dresources/genie_agent.go @@ -35,56 +35,25 @@ func (*ResourceGenieAgent) New(client *databricks.WorkspaceClient) *ResourceGeni } func (*ResourceGenieAgent) PrepareState(input *resources.GenieAgent) *resources.GenieAgentConfig { - return &input.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 } -// genieAgentBody builds the GenieAgent write payload from the bundle config. -// `name` is server-derived and the create/update paths carry the id, so it is -// never sent; the remaining fields are output-only and stay zero. -func genieAgentBody(config *resources.GenieAgentConfig) genieagents.GenieAgent { - body := genieagents.GenieAgent{ - DisplayName: config.DisplayName, - Description: config.Description, - WarehouseId: config.WarehouseId, - ParentPath: config.ParentPath, - - // A nil config definition marshals as the zero value, which the API - // rejects (the definition must set at least one field). - Definition: genieagents.GenieAgentDefinition{ - Benchmarks: nil, - Config: nil, - DataSources: nil, - Instructions: nil, - }, - - // Output-only fields; `name` is carried by the request path. - Name: "", - Etag: "", - CreateTime: nil, - UpdateTime: nil, - EffectiveParentPath: "", - ForceSendFields: nil, - } - if config.Definition != nil { - body.Definition = *config.Definition - } - return body -} - -// responseToGenieAgentConfig converts a returned GenieAgent into the bundle -// state. The server-derived name, etag, timestamps and effective_parent_path -// have no config counterpart and are dropped here. The API returns parent_path -// exactly as submitted; effective_parent_path may omit /Workspace and is ignored. +// 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 { - definition := agent.Definition return &resources.GenieAgentConfig{ - GenieAgentId: strings.TrimPrefix(agent.Name, genieAgentNamePrefix), - DisplayName: agent.DisplayName, - Description: agent.Description, - Definition: &definition, - WarehouseId: agent.WarehouseId, - ParentPath: agent.ParentPath, - ForceSendFields: nil, + GenieAgent: *agent, + GenieAgentId: strings.TrimPrefix(agent.Name, genieAgentNamePrefix), } } @@ -110,7 +79,7 @@ func (r *ResourceGenieAgent) DoRead(ctx context.Context, id string) (*resources. // 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: genieAgentBody(config), + GenieAgent: config.GenieAgent, GenieAgentId: config.GenieAgentId, ForceSendFields: nil, } @@ -136,16 +105,16 @@ func (r *ResourceGenieAgent) DoCreate(ctx context.Context, config *resources.Gen // so removing a field from config clears it. definition is replaced as a whole; // paths within it are not supported. // -// Etag is intentionally left empty (here and in DoDelete): it guards concurrent -// definition edits, which a serial bundle deploy does not have. Drift is -// detected on read by comparing the full config against the GET response, -// matching ResourceMcpService. -func (r *ResourceGenieAgent) DoUpdate(ctx context.Context, id string, config *resources.GenieAgentConfig, _ *PlanEntry) (*resources.GenieAgentConfig, error) { +// 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: genieAgentBody(config), + GenieAgent: config.GenieAgent, Name: genieAgentNamePrefix + id, UpdateMask: fieldmask.FieldMask{Paths: []string{"*"}}, - Etag: "", + Etag: plannedGenieAgentEtag(planEntry), ForceSendFields: nil, }) if err != nil { @@ -154,6 +123,23 @@ func (r *ResourceGenieAgent) DoUpdate(ctx context.Context, id string, config *re 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). 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/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/required_fields.go b/bundle/internal/validation/generated/required_fields.go index 826553c5ad3..79bdb884e47 100644 --- a/bundle/internal/validation/generated/required_fields.go +++ b/bundle/internal/validation/generated/required_fields.go @@ -152,7 +152,7 @@ var RequiredFields = map[string][]string{ "resources.features.*.time_window.tumbling": {"window_duration"}, "resources.features.*.timeseries_column": {"name"}, - "resources.genie_agents.*": {"display_name", "warehouse_id", "definition"}, + "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"}, diff --git a/bundle/schema/jsonschema.json b/bundle/schema/jsonschema.json index 8e24970e284..7906e270e6a 100644 --- a/bundle/schema/jsonschema.json +++ b/bundle/schema/jsonschema.json @@ -1238,19 +1238,25 @@ "oneOf": [ { "type": "object", - "description": "[Private Preview]", + "description": "[Private Preview] A Genie Agent resource.", "properties": { "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.", - "$ref": "#/$defs/github.com/databricks/databricks-sdk-go/service/genieagents.GenieAgentDefinition" + "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": "Description of the Genie Agent. The maximum length is 4,096 characters.", - "$ref": "#/$defs/string" + "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": "Display name of the Genie Agent. Must be unique within its folder. The maximum length is 63 characters.", - "$ref": "#/$defs/string" + "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.", @@ -1261,8 +1267,10 @@ "$ref": "#/$defs/github.com/databricks/cli/bundle/config/resources.Lifecycle" }, "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.", - "$ref": "#/$defs/string" + "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.", @@ -1270,15 +1278,17 @@ "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": "ID of the SQL warehouse used by this Genie Agent.", - "$ref": "#/$defs/string" + "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", - "definition" + "warehouse_id" ], "x-databricks-launch-stage": "PRIVATE_PREVIEW", "doNotSuggest": true diff --git a/libs/testserver/genie_agents.go b/libs/testserver/genie_agents.go index 2a6a24a4497..ad7567876b1 100644 --- a/libs/testserver/genie_agents.go +++ b/libs/testserver/genie_agents.go @@ -2,6 +2,8 @@ package testserver import ( "encoding/json" + "reflect" + "strconv" "strings" "time" @@ -92,11 +94,21 @@ func (s *FakeWorkspace) GenieAgentUpdate(req Request) Response { 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 @@ -122,9 +134,13 @@ func (s *FakeWorkspace) GenieAgentDelete(req Request) Response { defer s.LockUnlock()() agentId := req.Vars["genie_agent_id"] - if _, ok := s.GenieAgents[agentId]; !ok { + 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 @@ -154,6 +170,16 @@ func genieAgentNotFound() Response { } } +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, From 3794b32ce308b3b0e2c61c97c14ae769691dfe57 Mon Sep 17 00:00:00 2001 From: Eric Cho Date: Tue, 17 Nov 2026 23:49:42 +0000 Subject: [PATCH 6/6] Drop the redundant genie_agents apitypes pin Co-authored-by: Isaac --- bundle/direct/dresources/apitypes.yml | 9 --------- 1 file changed, 9 deletions(-) diff --git a/bundle/direct/dresources/apitypes.yml b/bundle/direct/dresources/apitypes.yml index 26a519ae822..7832c70e58f 100644 --- a/bundle/direct/dresources/apitypes.yml +++ b/bundle/direct/dresources/apitypes.yml @@ -13,15 +13,6 @@ genie_spaces: dashboards.GenieSpace mcp_services: catalog.McpService -# The heuristic picks CreateGenieAgentRequest because the config's identity -# field genie_agent_id exists only on the create request, and the field-overlap -# score weights that rare field name heavily. Pin the resource type: the -# generated rules describe the read shape, and GenieAgent is what GET returns. -# If the API carried the create-time genie_agent_id input on the resource -# message itself, the resource type would win the overlap and this pin could be -# dropped. -genie_agents: genieagents.GenieAgent - model_provider_services: catalog.ModelProviderService model_services: catalog.ModelService