Databricks Genie consultations¶
The DatabricksGenieHook submits a question to a Genie space, waits for the message to finish,
and returns a bounded result with the space, conversation, and message IDs. It uses the
credentials in an Airflow databricks connection and implements Common AI’s public
BaseManagedAgentHook contract.
Install the optional Common AI integration when using its managed-agent toolset:
pip install 'apache-airflow-providers-databricks[common.ai]'
from airflow.providers.common.ai.toolsets import ManagedAgentToolset
from airflow.providers.databricks.hooks.genie import DatabricksGenieHook
hook = DatabricksGenieHook(databricks_conn_id=CONN_ID)
toolset = ManagedAgentToolset(
hook.agent(SPACE_ID),
tool_name="ask_analytics_genie",
description="Answers questions about the analytics tables in this Genie space.",
max_retries=0,
)
The hook can also be called directly without Common AI:
from airflow.providers.databricks.hooks.genie import DatabricksGenieHook
hook = DatabricksGenieHook(databricks_conn_id=CONN_ID)
result = hook.consult(SPACE_ID, QUESTION)
The result contains IDs and structured answer, generated query, and query-result fields. Large responses are capped. A request that starts a conversation or posts a message is sent once; after a timeout or server failure its outcome may be unknown, so inspect the conversation before submitting again. Message and query-result reads may be retried. A 403 can mean either that access was denied or that the resource is missing, because Genie may conceal missing resources this way.
Genie MCP through Unity Gateway is enough when an external model or MCP client should discover and call Genie directly through the organization’s governed MCP endpoint. The native Databricks API integration is useful when an Airflow-managed agent needs Genie as a typed tool backed by an Airflow Databricks connection, and when the caller needs the Genie space/conversation/message IDs and bounded query results in its response. Both paths still enforce Genie and Unity Catalog permissions.
This hook handles consultations only. To ask Genie as a standalone Airflow task that reconnects to
its message after a worker failure, use
DatabricksGenieOperator; see
Ask a Databricks Genie space.