Skip to content

src/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 construct a request-scoped Vercel AI SDK provider for the endpoint’s native Databricks serving protocol.

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 ProviderV4 model Mastra accepts. Catalogue fetches fail loud: network / auth errors propagate so callers see the real SDK message.