Dear All,
As the number of Genie Agents grows, maintaining consistent instructions across multiple Genie Spaces becomes increasingly cumbersome. Updating the same instructions manually in each space requires significant effort and is both time-consuming and error-prone.
To simplify this process, we have created a notebook-based solution that automatically updates Genie instructions across multiple spaces. To use it, simply replace the following values in the notebook:
- Genie Space IDs
- Databricks Workspace URL
- Personal Access Token (PAT)
- Desired Instructions
Once configured, the notebook will automatically apply the same instructions to all specified Genie Spaces, eliminating the need for repetitive manual updates.
This should significantly reduce maintenance effort and ensure consistency across your Genie Agents.
Attached notebook code:
================================start here====================================
import requests
import json
workspace_url = "<your databricks workspace url"
token = "<your PAT token"
headers = {
"Authorization": f"Bearer {token}",
"Content-Type": "application/json"
}
space_ids = [
"<genie space id 1>",
"<genie space id 2>",
"<genie space id n>
]
NEW_INSTRUCTION = """
Your Role: Databricks SQL Analyst.
Rule 1: Use only tables, columns, joins, and logic defined in this Genie space. Never invent any.
Rule 2: Before generating a query, validate all rules.
<Your extended prompt Rules>
"""
for space_id in space_ids:
try:
# Get existing space
url = f"{workspace_url}/api/2.0/genie/spaces/{space_id}"
response = requests.get(
f"{url}?include_serialized_space=true",
headers=headers
)
response.raise_for_status()
space = response.json()
serialized = json.loads(space["serialized_space"])
# Replace instructions
serialized["instructions"]["text_instructions"] = [{
"content": [NEW_INSTRUCTION]
}]
payload = {
"serialized_space": json.dumps(serialized)
}
update_resp = requests.patch(
url,
headers=headers,
json=payload
)
print(
f"{space_id}: {update_resp.status_code}"
)
except requests.exceptions.RequestException as e:
print(f"{space_id}: Request failed - {e}")
except Exception as e:
print(f"{space_id}: Unexpected error - {e}")
=========================================end here================================