@databricks/ai-sdk-provider 0.1.1 → 0.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -4,12 +4,12 @@ Databricks provider for the [Vercel AI SDK](https://sdk.vercel.ai/docs).
4
4
 
5
5
  ## Features
6
6
 
7
- - 🚀 Support for three Databricks endpoint types:
8
- - **Chat Agent** (`agent/v2/chat`) - Databricks chat agent API
9
- - **Responses Agent** (`agent/v1/responses`) - Databricks responses agent API
10
- - **FM API** (`llm/v1/chat`) - Foundation model chat completions API
7
+ - 🚀 Support for all Databricks endpoint types:
8
+ - **Responses** (`agent/v1/responses`) - Foundation model and agent responses API ([docs](https://docs.databricks.com/aws/en/machine-learning/foundation-model-apis/api-reference#responses-api))
9
+ - **Chat Completions** (`llm/v1/chat`) - Foundation model chat completions API ([docs](https://docs.databricks.com/aws/en/machine-learning/foundation-model-apis/api-reference#chat-completions-api))
10
+ - **Chat Agent** (`agent/v2/chat`) - Legacy Databricks chat agent API ([docs](https://docs.databricks.com/aws/en/generative-ai/agent-framework/agent-legacy-schema))
11
11
  - 🔄 Stream and non-stream (generate) support for all endpoint types
12
- - 🛠️ Custom tool calling mechanism for Databricks agents
12
+ - 🛠️ Tool calling and agent support
13
13
  - 🔐 Flexible authentication (bring your own tokens/headers)
14
14
  - 🎯 Full TypeScript support
15
15
 
@@ -47,11 +47,11 @@ const provider = createDatabricksProvider({
47
47
  },
48
48
  })
49
49
 
50
- // Use the Chat Agent endpoint
51
- const responsesAgent = provider.responsesAgent('your-agent-endpoint')
50
+ // Use the Responses endpoint
51
+ const model = provider.responses('your-agent-endpoint')
52
52
 
53
53
  const result = await generateText({
54
- model: responsesAgent,
54
+ model,
55
55
  prompt: 'Hello, how are you?',
56
56
  })
57
57
 
@@ -89,9 +89,9 @@ Creates a Databricks provider instance.
89
89
 
90
90
  **Returns:** `DatabricksProvider` with three model creation methods:
91
91
 
92
+ - `responses(modelId: string)`: Create a Responses model
93
+ - `chatCompletions(modelId: string)`: Create a Chat Completions model
92
94
  - `chatAgent(modelId: string)`: Create a Chat Agent model
93
- - `responsesAgent(modelId: string)`: Create a Responses Agent model
94
- - `fmapi(modelId: string)`: Create an FM API model
95
95
 
96
96
  ### Tool Constants
97
97
 
@@ -101,16 +101,45 @@ import { DATABRICKS_TOOL_DEFINITION, DATABRICKS_TOOL_CALL_ID } from '@databricks
101
101
 
102
102
  #### Why are these needed?
103
103
 
104
- The AI SDK requires tools to be defined ahead of time with known schemas. However, Databricks agents can orchestrate tools dynamically at runtime - we don't know which tools will be called until the model executes.
104
+ When using AI SDK functions like `streamText` or `generateText`, you must declare which tools are allowed upfront in the `tools` parameter. This works well when you control which tools are available. However, when working with Databricks agents (like Responses agents or Agents on Apps), the agent decides which tools to call at runtime - you don't know ahead of time what tools will be invoked.
105
105
 
106
- To bridge this gap, this provider uses a special "catch-all" tool definition:
106
+ To bridge this gap, this provider uses a special "catch-all" tool pattern:
107
107
 
108
- - **`DATABRICKS_TOOL_DEFINITION`**: A universal tool definition that accepts any input/output schema. This allows the provider to handle any tool that Databricks agents orchestrate, regardless of its schema.
108
+ - **`DATABRICKS_TOOL_DEFINITION`**: A universal tool definition that accepts any input/output schema. This allows the provider to handle any tool that Databricks agents orchestrate, regardless of its actual schema.
109
109
 
110
- - **`DATABRICKS_TOOL_CALL_ID`**: The constant ID (`'databricks-tool-call'`) used to identify this special tool. The actual tool name from Databricks is preserved in the metadata so it can be displayed correctly in the UI and passed back to the model.
110
+ - **`DATABRICKS_TOOL_CALL_ID`**: The constant ID (`'databricks-tool-call'`) used to label all tool calls and tool results under a single identifier. The actual tool name from Databricks is preserved in `providerMetadata.databricks.toolName` so it can be displayed correctly in the UI and passed back to the model.
111
111
 
112
112
  This pattern enables dynamic tool orchestration by Databricks while maintaining compatibility with the AI SDK's tool interface.
113
113
 
114
+ #### Example: Server-side streaming with tools
115
+
116
+ ```typescript
117
+ import { streamText } from 'ai'
118
+ import { createDatabricksProvider, DATABRICKS_TOOL_CALL_ID, DATABRICKS_TOOL_DEFINITION } from '@databricks/ai-sdk-provider'
119
+
120
+ const provider = createDatabricksProvider({
121
+ baseURL: 'https://your-workspace.databricks.com/serving-endpoints',
122
+ headers: { Authorization: `Bearer ${token}` },
123
+ })
124
+
125
+ const model = provider.responses('my-agent-endpoint')
126
+
127
+ const result = streamText({
128
+ model,
129
+ messages: convertToModelMessages(uiMessages),
130
+ tools: {
131
+ // Register the catch-all tool to handle any tool the agent calls
132
+ [DATABRICKS_TOOL_CALL_ID]: DATABRICKS_TOOL_DEFINITION,
133
+ },
134
+ })
135
+ ```
136
+
137
+ When the agent makes a tool call, you'll receive it with:
138
+ - `toolName: 'databricks-tool-call'` (the constant ID)
139
+ - `providerMetadata.databricks.toolName: 'actual_tool_name'` (the real tool name)
140
+
141
+ This allows your UI to display the actual tool name while the AI SDK routes all tool calls through the single registered tool definition.
142
+
114
143
  ### MCP Utilities
115
144
 
116
145
  ```typescript
@@ -129,13 +158,13 @@ MCP (Model Context Protocol) approval utilities for handling approval workflows.
129
158
 
130
159
  ## Examples
131
160
 
132
- ### Responses Agent Endpoint
161
+ ### Responses Endpoint
133
162
 
134
163
  ```typescript
135
- const responsesAgent = provider.responsesAgent('my-responses-agent')
164
+ const model = provider.responses('my-responses-agent')
136
165
 
137
166
  const result = await generateText({
138
- model: responsesAgent,
167
+ model,
139
168
  prompt: 'Analyze this data...',
140
169
  })
141
170
 
@@ -144,18 +173,30 @@ console.log(result.text)
144
173
 
145
174
  ### With Tool Calling
146
175
 
176
+ When your Databricks agent can call tools, register the catch-all tool definition:
177
+
147
178
  ```typescript
148
179
  import { DATABRICKS_TOOL_CALL_ID, DATABRICKS_TOOL_DEFINITION } from '@databricks/ai-sdk-provider'
149
180
 
150
- const responsesAgent = provider.responsesAgent('my-agent-with-tools')
181
+ const model = provider.responses('my-agent-with-tools')
151
182
 
152
183
  const result = await generateText({
153
- model: responsesAgent,
184
+ model,
154
185
  prompt: 'Search for information about AI',
155
186
  tools: {
156
187
  [DATABRICKS_TOOL_CALL_ID]: DATABRICKS_TOOL_DEFINITION,
157
188
  },
158
189
  })
190
+
191
+ // Access tool calls from the result
192
+ for (const part of result.content) {
193
+ if (part.type === 'tool-call') {
194
+ // part.toolName === 'databricks-tool-call' (the constant ID)
195
+ // part.providerMetadata.databricks.toolName contains the actual tool name
196
+ const actualToolName = part.providerMetadata?.databricks?.toolName
197
+ console.log(`Agent called tool: ${actualToolName}`)
198
+ }
199
+ }
159
200
  ```
160
201
 
161
202
  ## Links