Skip to content

model

Databricks Model Serving resolver for Mastra agents.

Each agent step calls buildModel with the active RequestContext. The user stamped by MastraServer carries an AppKit WorkspaceClient; we ask it for the workspace host and a fresh bearer header, then point Mastra’s OpenAI-compatible provider at /serving-endpoints on that host.

This module only adds the Mastra-specific glue. The actual model selection - listing the workspace catalogue and resolving an explicit name / class / fallback chain to a real endpoint id - lives in @dbx-tools/model (selectModel) so non-Mastra consumers (e.g. a job that just needs a model name) can reuse it. Here we assemble the explicit ask from Mastra’s request context (the per-request override under MASTRA_MODEL_OVERRIDE_KEY, the agent / plugin modelId, or DATABRICKS_SERVING_ENDPOINT_NAME), pass the plugin’s fuzzy / class / fallback knobs through, and wrap the resolved id in the OpenAI-compatible provider config Mastra expects. Catalogue fetches fail loud: network / auth errors propagate so callers see the real SDK message.