Databricks Field Guide

Generative AI · Chapter 20

Databricks AI agents: Agent Bricks, evals and governance

Reviewed by TechFabric engineers. How we write this guide →

A Databricks AI agent is a program that uses a language model to answer questions or take steps by calling tools over your governed data, such as Unity Catalog functions, AI Search indexes, Genie Agents and MCP servers. As of October 2026 you build one either low-code as a Genie Agent or in code with the Agent Bricks CLI, which deploys it to Agent Runtime with MLflow tracing on; the older Knowledge Assistant, Supervisor Agent and Model Serving routes are legacy.

Getting an agent running is an afternoon's work. Proving it answers only what the person asking may see, and that it's still right next month, is the project, and that's most of this chapter. It moves faster than any other part of the guide, so every product name and stage below is dated to the documentation we read in October 2026.

The short version

An agent is software that uses a language model to answer questions or carry out tasks, usually by looking things up in your own data first. The hard part is almost never the model, which you rent by the token from several vendors who are all roughly comparable. The hard part is making sure the agent looks at the right information, that it only sees what the person asking is allowed to see, and that you can prove afterwards what it was told and what it said. Building it next to the data, inside the permission and audit system that already governs that data, removes most of that difficulty rather than deferring it. The rest of the work is measurement, meaning somebody decides what a good answer looks like and writes down enough real questions to test it.

Why agents belong next to the data #

The case for building agents on Databricks rather than beside it is governance and lineage. An agent that retrieves from governed tables inherits the access model that already exists, its retrievals are audited, and the relationship between what it read and what it said is traceable. An agent built against a separate vector store fed by a nightly export inherits none of that, and its security review starts from scratch on infrastructure that can't say who was allowed to see which chunk. Where a team already runs a mature agent stack elsewhere, we'd integrate the retrieval into the catalog rather than relocate the agent (the objection below).

What are the pieces of a Databricks agent? #

Piece What it does Status, October 2026
Agent Bricks CLI (databricks-agentbricks) Scaffolds, runs and deploys a code agent, LangGraph or the OpenAI Agents SDK Beta
Agent Runtime Runs the deployed agent on Databricks Apps behind an authenticated endpoint, with DurableAgentServer as the recommended server Recommended for new agents; Model Serving deployment is legacy
Unity Gateway Governs the agent's model and MCP calls, with rate limits, service policies, budgets and a usage table Generally available; some MCP services in Beta
AI Search Indexes text from Unity Catalog tables and keeps the index in sync Generally available
MLflow 3 Traces every run, holds prompts, and runs evaluation with scorers Generally available
Agent memory and sessions Long-term memory and conversation history in Lakebase Beta

An agent's tools are governed in Unity Catalog as MCP services, functions and connections. How the agent itself is governed depends on how it's deployed: one deployed with the Agent Bricks CLI to Agent Runtime runs as an app with its own service principal, so its permissions are that principal's grants, while one logged with MLflow and served from Model Serving is a Unity Catalog model with model grants and the promotion path described in CI/CD. Traffic through Unity Gateway can land in the unified trace table (Beta), one Unity Catalog table in OpenTelemetry format, which Databricks recommends over per-endpoint inference tables for new deployments. Two details we'd plan for. Only the metastore admin who creates the trace table can read it until they grant access, so the GRANT SELECT to the security group belongs in the same change, and delivery is best-effort, so the audit log stays the compliance record.

The framework matters less than whether it produces something that can be registered, versioned and evaluated. Our own Fabric Harness, an Apache-2.0 TypeScript framework, exists because we wanted a TypeScript option with durable execution underneath tool calls. Databricks' answer to the durability half is DurableAgentServer, from databricks_agentkit, which runs invocations that share a session one at a time, treats the client's invocation id as an idempotency key, and restarts a run whose heartbeats stop.

User asks a question

Agent on
Agent Runtime

Retrieval
as the user

AI Search index
synced from UC

Governed tables

Grounded answer
plus citations

Trace table
and MLflow traces

How a governed retrieval request flows, and where identity is enforced

Agent Bricks, or code #

Databricks offers two routes to the same governed agent, and the low-code one changed in October. For a new low-code agent over your documents and data, Databricks now points you to Genie Agents. The legacy offerings page (updated 13 October 2026) lists the earlier builders as "no longer best practice": Knowledge Assistant and Supervisor Agent, plus the Supervisor API, custom agents on Model Serving, the custom LLM builder (replaced by AI Functions such as ai_query) and AI Playground. Existing ones keep running.

The code route is the Agent Bricks CLI, which is also how Databricks now suggests coordinating several agents. A project starts like this:

pip install databricks-agentbricks
agentbricks init --framework langgraph servicing-agent
cd servicing-agent
agentbricks dev                      # runs the agent locally on port 8000
agentbricks deploy servicing-agent   # deploys to Agent Runtime

deploy reads the project's agent.toml, provisions any memory and session stores it binds, grants the agent's service principal access to them, and rolls the agent out; init binds an MLflow experiment, so traces from dev and deploy land there by default. A Genie Agent can be added to a code agent as a tool with agentbricks tools add genie-agent.

Our default is to start a document question-answering agent as a Genie Agent, because it's the quickest route to something the evaluation set can run against, and to move to code when the agent needs control flow the builder can't express. We wouldn't start anything new on Knowledge Assistant, Supervisor Agent or a Model Serving agent endpoint. Either way, everything below about evaluation still applies, because no builder writes your evaluation set for you.

The first month, in the order we'd build it #

Week What we'd build What it proves
1 Fifty real questions with agreed answers, written by the people who'll use the agent, including ones it should refuse What "good" means, before anything exists to argue about
1 The retrieval tools as Unity Catalog functions, run on behalf of the user The agent can't see more than the person asking
2 A Genie Agent or a small code agent, registered in Unity Catalog, traced with MLflow Something the evaluation set can score
2 The two-identity test in CI (below) Entitlements hold through the agent, not only in direct queries
3 Retrieval fixes in the order Context and Retrieval sets out Scores move for a reason you can name
4 Production traces scored by the same scorers, a Unity Gateway budget with a blocking threshold The agent stays good, and its cost stays bounded, after launch

Nothing in that table depends on which model you pick. The model is the easiest component to swap, so we'd choose it last and expect to change it.

Evaluation is the whole job #

We'd have the set written by the people who will use the agent rather than the people building it. Builders write questions the system can answer. Users write the question with an ambiguous premise, the one requiring data the agent can't see, and the one that's really two questions in a single sentence.

Each run reports correctness against the known answer, groundedness in retrieved context, refusal rate on questions that should be refused, latency, and cost per query. Refusal is the metric we'd least want to skip, because an agent that never refuses will confidently answer a question about data it doesn't have. In MLflow 3 these become scorers passed to mlflow.genai.evaluate, which calls your predict_fn with each row's inputs as keyword arguments. The same scorers can run against production traces, so the offline set and production monitoring share one definition of good:

evals/run.pypython
# pip install "mlflow[databricks]>=3.1"
import mlflow
from mlflow.genai.scorers import Correctness, RelevanceToQuery, RetrievalGroundedness, Safety

from servicing_agent.agent import answer   # your agent's entry point: answer(question) -> str

eval_set = [
    {
        "inputs": {"question": "What is the hardship grace period for a missed payment?"},
        "expectations": {"expected_response": "Thirty days from the missed due date."},
    },
    # ... the other forty-nine, written by the people who will use the agent
]

results = mlflow.genai.evaluate(
    data=eval_set,
    predict_fn=answer,
    scorers=[Correctness(), RetrievalGroundedness(), RelevanceToQuery(), Safety()],
)

Correctness needs the expectations; the other three judge without ground truth, and RetrievalGroundedness needs a trace with a retriever span, which is why the agent runs through predict_fn rather than being scored from a static table (predefined scorers). Refusal has no built-in scorer we'd trust as is, so we'd write it as a custom scorer against the questions the set marks as "should refuse".

Retrieval, and the identity it runs as #

When an agent answers wrongly, the first thing we'd check is what it retrieved, because the model is usually fine and was handed the wrong three paragraphs. Chunking, hybrid search, the reranker, structured retrieval for countable questions and recall at k are all in Context and Retrieval, and we'd fix retrieval in the order that chapter's table sets out.

The identity is the part that belongs here. Sushruth Aeluguri, a Databricks Engineer at TechFabric, wrote up the failure as an illustrative scenario on a FHIR lakehouse design; it's a design, not a client engagement, and Security covers the identity paths in general. A care coordinator asks an agent for a patient summary and gets back a substance use record covered by 42 CFR Part 2, which they aren't cleared to see. The row filter worked and the SSN mask worked. Both evaluated against the identity that ran the query, and that identity was the agent's service principal, granted broad read access so it could serve every coordinator.

A worked design: the two-identity test #

The check he recommends takes an afternoon. Call the same tool twice against the same patient, once through the agent running on behalf of a coordinator outside the consented group and once as the service principal. In his design the second call succeeds with no error and no empty result. It returns the rows the service principal may see, Part 2 conditions and unmasked SSNs included, so there's nothing to alert on. His checklist puts that comparison in CI, asserting that the agent's answer for a user matches what the user gets querying directly, and runs interactive agents on behalf of the user by default.

The Part 2 row filter is deliberately closed as well. A row whose sensitivity label is NULL is hidden from anyone outside the consented group, because a missing label means the normalisation job failed and the safe reading is that the row might be Part 2. That makes the job writing the label from meta.security part of the access control rather than a convenience field. An AI Search index built over the same data needs its own grants and its own negative test, because the table's row filters don't travel into it; the worked design in Context and Retrieval sets out the three ways round that.

Advanced: what separates a working agent from a durable one #

The material above gets a useful agent into production. What follows is where we'd spend the second month.

Online evaluation from production traces. The offline set proves a change didn't regress the questions you thought of; production traces tell you about the ones you didn't. We'd sample production traffic, score it with the same scorers as the offline set, and route low scores into a review queue that feeds new cases back into the offline set. That loop is what stops an evaluation set ageing into irrelevance.

Managed memory and sessions. Since 16 September 2026 Databricks has offered managed agent memory (long-term, with semantic search) and managed sessions (conversation history read at the start of a turn), both in Beta, both backed by Lakebase and usable from any framework through the AgentKit SDK or the REST API (/api/2.0/agents/memory-stores for memory, /api/2.0/agents/session-stores for sessions). During the Beta you pay for the Lakebase instance underneath and nothing for memory itself. That's the state layer teams otherwise build by hand, and we'd try it before writing a session store, behind our own interface while it's in Beta. Three limits shape the design. Access control is per store, never per user or per entry, and any workspace user can list stores, so the code that sets actor_id must take it from the verified caller, never from the model. Search returns at most 100 entries without pagination. And forgetting a user means listing their entries by actor_id and path and deleting each one, which is worth building and testing before the first deletion request arrives. What to remember stays our decision, because an agent that recalls everything is worse than one that recalls the right five things. Our MemCurrent note covers the design behind it.

Prompt and index versioning. A prompt change is a production change. Registering prompts alongside models, so that an inference record names the prompt revision, the index revision, and the model version behind it, is what makes an incident investigable months later.

Cost-aware routing. Not every question needs the largest model. Routing by classified difficulty, with a cheaper model handling the easy majority and escalating on low confidence, is where we'd look for savings once the evaluation set exists, because the set is what tells you the threshold costs no quality. Without it, routing is a guess that saves money until the day it doesn't. Foundation Models covers the gateway that makes the switch a configuration change, and ai_decide there is a cheap first-stage router for the SQL side.

MCP tools through the gateway. Databricks' built-in MCP services are model services in system.ai: system.ai.genie_one_mcp is generally available, while system.ai.dbsql, system.ai.web_search and system.ai.sandbox are Unity Gateway Beta (built-in MCP services). We'd reach tools through those and registered MCP services rather than the legacy workspace endpoints (below).

Building a governed retrieval agent on each platform

Capability Databricks AWS Azure GCP
Foundation and custom models Foundation Model APIs and custom models, both behind Unity Gateway Bedrock plus SageMaker, two services Azure AI Foundry plus Azure ML Vertex AI
Index synced from source tables Managed, from Unity Catalog Build it into OpenSearch or pgvector Build it into AI Search Build it into Vertex AI Vector Search
Access control on the index Unity Catalog grants on the index itself; ABAC policies on the source table do not carry over Lake Formation governs tables, not the index Purview labels data, index is separate Dataplex governs tables, index is separate
Request logging into governed tables Trace and inference tables, queryable in SQL CloudWatch and S3, wire it up Log Analytics, wire it up Cloud Logging, wire it up
Lineage from source table to answer Inherited from the catalog Assemble it Assemble it Assemble it

Every one of these platforms can build the same agent, and the difference is how much governance is inherited rather than assembled. On the other three the index is a separate system with a separate access model, so the claim that the agent sees only what the user can see is something your team implements and defends.

What we saw: the call loop and the data loop #

Preetham Reddy, TechFabric's founder, wrote up the voice agents we're building for auto refinance on Databricks, and the design decision that shaped it applies to most agents. A voice agent runs a hard real-time loop, audio in, transcription, a model turn, speech out, and people notice silence at around a second. Around that loop sits everything that makes the call worth making: who to call, whether you may, the payoff balance, the vehicle's value, what happened on the last three calls. The second loop is the lakehouse. Keeping them separate is the whole design: the carrier and the speech layer stay outside Databricks, while the agent, its tools, the governed data and every trace live on it.

Two choices follow that we'd copy for any latency-bound agent. Features the agent needs mid-call (payoff, rate, term, vehicle value) come from an online feature store backed by Lakebase, synced from the same offline Unity Catalog feature tables that trained the propensity model, because reading Delta at call time is too slow. And the decision about whether the call may happen at all is a deterministic gate in code before the dial, never a line in the prompt, which is Governed Actions in practice.

The same write-up is specific about what to score, and it's the clearest example we know of domain scorers written before prompts. For an outbound refinance call the checks run against each trace: did the agent make the AI disclosure in its opening turn, did it honour a stop request on the turn it was spoken, did every quoted figure match the tool output, and did it hand off to a person when asked. None of those is a built-in judge, and all four are cheap code-based scorers. Here's the third, checked against MLflow 3.17; it reads the tool spans of the same trace, so it compares what the agent said with what its pricing tool actually returned:

evals/scorers.pypython
import re

from mlflow.entities import SpanType
from mlflow.genai.scorers import scorer

PERCENT = re.compile(r"(\d+(?:\.\d+)?)\s?%")
# Only the fields a pricing tool returns a rate in; a term or a balance is never a rate.
RATE_FIELDS = {"apr", "rate", "interest_rate"}


def _rates(value):
    """Every number under a rate field, anywhere in a tool's output."""
    if isinstance(value, dict):
        for key, item in value.items():
            if key in RATE_FIELDS and isinstance(item, (int, float)):
                yield round(float(item), 4)
            else:
                yield from _rates(item)
    elif isinstance(value, list):
        for item in value:
            yield from _rates(item)


@scorer
def quoted_rate_matches_tool(outputs, trace) -> bool:
    """Every rate the agent said must be a rate a tool returned in the same trace."""
    said = {round(float(x), 4) for x in PERCENT.findall(str(outputs))}
    returned = set()
    for span in trace.search_spans(span_type=SpanType.TOOL):
        returned |= set(_rates(span.outputs))
    return said <= returned

Comparing numbers rather than strings makes "6.50%" match a returned 6.5, and reading only rate fields stops a 12-month term from excusing a quoted 12%. It only works if the tools are traced as TOOL spans and return structured output, which is one more reason to decorate them with @mlflow.trace(span_type=SpanType.TOOL) from the start.

Run them on the evaluation set before a prompt change ships and on a sample of production traffic after, and keep a human-dialed control group, because funded loans per thousand attempts against that control is the only way to tell an agent that's better from one that's dialing more.

The post names the failures it designs against, and we'd put the same three on any agent's risk list. The first isn't the model saying something odd: it's a consent table refreshed nightly while the agent calls someone who revoked at 10am, so revocation goes into the online store as a streaming event and the gate reads it on every attempt. The second is cost blindness, since a conversation spends tokens on every turn and a thousand concurrent calls compound fast, which is what rate limits and blocking budgets in Unity Gateway are for. The third is scope: one campaign, one set of states, one script, outbound only, with a human transfer on anything the agent wasn't built to handle. It argues for equity mining on the lender's own book as the first campaign rather than bought leads, because the loan data and the consent chain are already the lender's own.

Agents propose, systems act #

The distinction we hold most firmly is between an agent that produces a recommendation and one that changes something in the world. Reading, summarising, drafting, and recommending are one risk class; writing to a system of record, moving money, contacting a customer, or changing an account's status is a completely different one. Everything in this chapter concerns the first class. The second needs a governance layer outside the model, and it is the subject of Governed Actions.

Costs move differently here #

Agent workloads bill on tokens and endpoint uptime rather than the compute patterns the rest of the platform has taught your team to reason about, and cost per query varies with the input in a way a SQL query's does not. We'd instrument it from day one, read it per agent from system.ai_gateway.usage, and remember that a retrieval change improving quality by adding context also multiplies the bill. Record tokens in and out alongside the evaluation score, so quality and spend are read from the same table.

Unity Gateway budgets take shared or per-user monthly thresholds, and a threshold can block usage rather than only alert. Sushruth's write-up makes the point we'd repeat to any team: set the blocking threshold, not only the alert, because an agent stuck in a retry loop against a frontier model is a cost incident that ends at the block and doesn't end at the alert. Two details decide whether that holds. A budget leaves out external model spend unless you opt it in, which is in Beta, so a frontier model from another provider needs that option switched on. And Databricks enforces the block approximately and says not to treat it as an absolute cap, so the bill can run somewhat past the threshold before requests stop. One trap from the same write-up: the legacy workspace MCP endpoints, including the Unity Catalog functions server under /api/2.0/mcp/functions/, bypass Unity Gateway, so their calls miss its tracing, grants and guardrails. Databricks' built-in MCP services page now says so outright for all three legacy servers (AI Search, Databricks SQL and Unity Catalog functions), which keep only the permissions on the underlying table, function or index. An old integration reused for a new agent quietly removes the whole runtime layer, so we'd point new agents at the system.ai services instead.