Sub topic 12
Registering an Agent in Unity Catalog and Deploying It
This chapter covers the step between a working agent and a live endpoint. It assumes you can log a model with MLflow, you know what a Unity Catalog catalog and schema are, and you have built an agent like the RAG function from earlier chapters.
Why register before deploying
An agent you log with MLflow lives in an experiment run. That is good for testing and bad for production, because a run has no stable name, no access rules, and no version history.
Registering the logged agent in Unity Catalog fixes this. The agent becomes a model with a three-level name (catalog.schema.model). Each registration creates a numbered version. You control who can use it with the same grants you use for tables. Deployment then points an endpoint at one specific version, so you always know what is running.
Step 1: Register the logged agent
Point MLflow at Unity Catalog, then register the model from the run that logged it. The <run-id-of-the-logged-agent> value is the run ID from your logging step. The agent part of the URI is the artifact path you used when logging.
import mlflow
from databricks import agents
mlflow.set_registry_uri("databricks-uc")
uc_model_name = "main.genai.support_agent"
run_id = "<run-id-of-the-logged-agent>"
registered = mlflow.register_model(
model_uri=f"runs:/{run_id}/agent",
name=uc_model_name,
)
agents.deploy(uc_model_name, registered.version)mlflow.set_registry_uri("databricks-uc") is the line that matters most. Without it, MLflow uses the older workspace registry, which does not accept three-level names.
register_model returns an object with a version attribute. The last line passes that version to agents.deploy.
Step 2: What deployment creates
agents.deploy takes the model name and a version. It creates a model serving endpoint for that version and sets up supporting pieces, such as logging of requests and responses. Deployment can take several minutes, so expect to wait before the endpoint accepts requests.
To release a change, register a new version and deploy it. The version number lets you tell which code produced a given answer, and it gives you something to return to if a release goes wrong.
Permissions you need
Registration and deployment fail with permission errors more often than with code errors. Check these first:
| Need | Why |
|---|---|
| `USE CATALOG` and `USE SCHEMA` on the target | To reach the location of the model |
| `CREATE MODEL` on the schema | To register the model |
| `EXECUTE` on the model | To let others call or deploy it |
| Access to the resources the agent uses | The endpoint needs the chat model and the Vector Search index to run |
The last row is the common surprise. The agent calls a chat endpoint and a vector index. If it cannot reach them when deployed, requests fail even though the deployment succeeded. When you log the agent, declare these resources so Databricks can grant the endpoint access to them.
Common errors
- A name with fewer than three parts. Unity Catalog names must be
catalog.schema.model. - Forgetting the registry URI. Registration then goes to the wrong registry.
- A wrong artifact path. The
runs:/<run_id>/agentpath must match the name used at logging time. - Missing resource declarations. The endpoint starts but fails when it calls the model or index.
- Deploying an untested version. Always check the version number you pass.
Exercise
Your teammate registered a new agent version, but the endpoint still returns answers from the old behavior. What is the most likely cause, and what do you do?
Show answer
Registering a version does not change an existing endpoint. The endpoint serves the version it was deployed with. Call agents.deploy with the model name and the new version number to update it.
Exercise
Why does mlflow.registermodel fail with a three-level name if you skip mlflow.setregistry_uri("databricks-uc")?
Show answer
Without that call, MLflow targets the workspace model registry, which does not support catalog.schema.model names. Setting the registry URI to databricks-uc sends registration to Unity Catalog.