Databricks
The platform runs models, the index, and the deployed agent. You write the agent code, the tools, and the evaluation, and you keep them in a repository deployed with a bundle.平台负责运行模型、索引和已部署的智能体。你编写智能体代码、工具和评估,把它们放在代码仓库里,用 bundle 部署。
These guides were written from vendor documentation read in October 2026. None was executed: there was no account on these platforms. Product names change often. Confirm each command against the linked source before you rely on it.这些指南依据 2026 年 10 月查阅的厂商文档编写。全部未经实际执行:编写时没有这些平台的账号。产品名称经常变化。使用前请对照链接的来源逐条核实命令。
Playbook: running it on Databricks操作手册:在 Databricks 上运行它
What you own归你负责的
Agent code, tool functions, instructions, gold sets, scorers, the publish pipeline for documents.智能体代码、工具函数、指令、标准集、scorer、文档的发布流程。
What the platform runs由平台运行的
Model endpoints, Unity Gateway, AI Search indexes, Agent Runtime and Apps, MLflow tracing, Jobs, permissions.模型端点、Unity Gateway、AI Search 索引、Agent Runtime 与 Apps、MLflow tracing、Jobs、权限。
Build steps搭建步骤
01Reach models through Unity Gateway通过 Unity Gateway 访问模型
Do this操作
- Pick a hosted model endpoint in the workspace.在工作区里选一个托管的模型端点。
- Route calls through Unity Gateway so one client reaches every model.让调用经过 Unity Gateway,这样一个客户端就能访问所有模型。
- Measure tokens per second and first-token time for the endpoint, exactly as in module 1.测量该端点的每秒 token 数和首 token 时间,做法与第 1 模块完全相同。
from agents import set_default_openai_client
from databricks_openai import AsyncDatabricksOpenAI
set_default_openai_client(AsyncDatabricksOpenAI(use_ai_gateway=True))You are done when完成标志A chat call returns a completion and appears in gateway usage.一次 chat 调用返回了结果,并出现在网关的用量记录里。
02Land documents and keep the ledger as a table落地文档,并把台账做成一张表
Do this操作
- Upload raw files to a Unity Catalog volume, using the same folder taxonomy.把原始文件上传到 Unity Catalog volume,沿用同样的目录分类。
- Run the validation and chunking code from labs 3 and 5 in a job. Write chunks to a Delta table with columns id, source, text, context, tier.在一个 job 里运行 lab 3 和 lab 5 的校验与切块代码。把文本块写入 Delta 表,列包括 id、source、text、context、tier。
- Keep the ledger as a second Delta table.把台账做成第二张 Delta 表。
You are done when完成标志The chunk table has one row per chunk and a primary key column.文本块表每个块一行,并有主键列。
03Create an AI Search index over the chunk table在文本块表上创建 AI Search 索引
Do this操作
- Create an endpoint, then a Delta Sync index with a managed embedding model.先创建 endpoint,再创建使用托管 embedding 模型的 Delta Sync 索引。
- Query it. The vendor page shows `query_type="FULL_TEXT"`. It mentions hybrid search and does not show the hybrid value, so confirm that on the query page.对它执行查询。厂商文档给出的示例是 `query_type="FULL_TEXT"`。文档提到了混合检索,但没有给出对应的取值,请到查询相关页面确认。
- Apply the tier bonus and dedup from lab 5 to the returned rows in your tool code.在你的工具代码里,对返回的数据行应用 lab 5 的等级加分和去重。
from databricks.ai_search.client import AISearchClient
client = AISearchClient()
client.create_endpoint(name="policy_endpoint", endpoint_type="STANDARD")
index = client.create_delta_sync_index(
endpoint_name="policy_endpoint",
source_table_name="main.agent.policy_chunks",
index_name="main.agent.policy_chunks_index",
pipeline_type="TRIGGERED",
primary_key="id",
embedding_source_column="text",
embedding_model_endpoint_name="databricks-qwen3-embedding-0-6b",
)
results = index.similarity_search(query_text="lodging cap", columns=["id", "text"], num_results=10,
query_type="FULL_TEXT")You are done when完成标志The gold set from lab 11 scores at least as well against this index as against the lab index.lab 11 的标准集在这个索引上的得分不低于在 lab 索引上的得分。
04Author the agent from the app template基于应用模板编写智能体
Do this操作
- Clone the vendor's app templates and open the OpenAI Agents SDK template.克隆厂商的应用模板仓库,打开 OpenAI Agents SDK 那个模板。
- Define tools with the decorator and create the agent with your instructions.用装饰器定义工具,并用你的指令创建智能体。
- Run it locally before deploying.部署之前先在本地运行。
git clone https://github.com/databricks/app-templates.git
cd app-templates/agent-openai-agents-sdk
uv run quickstart
uv run start-app # then open http://localhost:8000You are done when完成标志The local app answers a question using your tool.本地应用使用你的工具回答了一个问题。
05Add tools and grant their permissions添加工具并授予权限
Do this操作
- Local function tools need no resource grant.本地函数工具不需要授予资源权限。
- Add MCP servers in agent code and grant their permissions in `databricks.yml`.在智能体代码中添加 MCP 服务,并在 `databricks.yml` 里授予相应权限。
- Keep the diagnostic-on-empty rule from lab 6 in every tool you write.你写的每个工具都要保留 lab 6 里“空结果必须带诊断信息”的规则。
You are done when完成标志A call with a filter that matches nothing returns a diagnostic.使用匹配不到任何数据的过滤条件调用时,返回了诊断信息。
06Deploy with a bundle用 bundle 部署
Do this操作
- Validate, deploy, then run the app.先校验,再部署,然后运行应用。
- Name the app with the prefix `agent-` so it appears in the workspace agents list.应用名以 `agent-` 开头,这样它才会出现在工作区的智能体列表里。
- Query it with an OAuth token. Personal access tokens are not accepted for this.用 OAuth 令牌调用它。这里不接受个人访问令牌。
databricks bundle validate
databricks bundle deploy
databricks bundle run agent_openai_agents_sdk
# query: POST https://<app-url>/responses with Authorization: Bearer $(databricks auth token ...)You are done when完成标志The deployed URL answers the same question the local app did.已部署的 URL 能回答本地应用回答过的同一个问题。
07Evaluate with MLflow scorers and a Unity Catalog dataset用 MLflow scorer 和 Unity Catalog 数据集做评估
Do this操作
- Create an evaluation dataset as a Unity Catalog table and merge records into it.以 Unity Catalog 表的形式创建评估数据集,并把记录合并进去。
- Run `mlflow.genai.evaluate` with your predict function and a list of scorers.用你的 predict 函数和一组 scorer 运行 `mlflow.genai.evaluate`。
- Restrict write permission on the dataset table. That is the seal.限制该数据集表的写权限。这就是封存。
- Repeat runs and report the spread, as in lab 11.像 lab 11 那样多次运行并报告波动范围。
import mlflow
from mlflow.genai.scorers import RetrievalGroundedness, RelevanceToQuery, Safety, Guidelines
eval_dataset = mlflow.genai.datasets.create_dataset(uc_table_name="main.agent.frozen_questions")
# eval_dataset = eval_dataset.merge_records(traces_or_records)
results = mlflow.genai.evaluate(
data=eval_dataset,
predict_fn=ask_agent,
scorers=[RetrievalGroundedness(), RelevanceToQuery(), Safety()],
)You are done when完成标志An evaluation run appears in MLflow with one row per question and a score per scorer.MLflow 里出现一次评估运行,每个问题一行,每个 scorer 一个分数。
08Schedule the learning loop as a job把学习循环排成定时任务
Do this操作
- Run the observe, evidence, and gate code from lab 13 as a scheduled job over the trace tables.把 lab 13 的观察、证据和关卡代码作为定时任务,在 trace 表上运行。
- Keep it in report mode until you have read a week of reports.在你看完一周的报告之前,让它保持报告模式。
- Apply a change as a commit to the repository, deployed by the bundle.把改动以提交的形式应用到仓库,再由 bundle 部署。
You are done when完成标志Every applied rule is a commit with an evaluation run linked to it.每条已应用的规则都对应一次提交,并关联了一次评估运行。