@databricks/ai-sdk-provider 0.2.2 → 0.3.0
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 +59 -49
- package/dist/index.cjs +457 -244
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +22 -33
- package/dist/index.d.cts.map +1 -1
- package/dist/{index.d.ts → index.d.mts} +23 -34
- package/dist/index.d.mts.map +1 -0
- package/dist/{index.js → index.mjs} +418 -179
- package/dist/index.mjs.map +1 -0
- package/package.json +7 -7
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js.map +0 -1
package/README.md
CHANGED
|
@@ -86,6 +86,7 @@ Creates a Databricks provider instance.
|
|
|
86
86
|
- `settings.provider` (string, optional): Provider name (defaults to "databricks")
|
|
87
87
|
- `settings.fetch` (function, optional): Custom fetch implementation
|
|
88
88
|
- `settings.formatUrl` (function, optional): Optional function to format the URL
|
|
89
|
+
- `settings.useRemoteToolCalling` (boolean, optional): Enable remote tool calling mode (defaults to `false`). See [Remote Tool Calling](#remote-tool-calling) below.
|
|
89
90
|
|
|
90
91
|
**Returns:** `DatabricksProvider` with three model creation methods:
|
|
91
92
|
|
|
@@ -93,33 +94,71 @@ Creates a Databricks provider instance.
|
|
|
93
94
|
- `chatCompletions(modelId: string)`: Create a Chat Completions model
|
|
94
95
|
- `chatAgent(modelId: string)`: Create a Chat Agent model
|
|
95
96
|
|
|
96
|
-
### Tool
|
|
97
|
+
### Remote Tool Calling
|
|
98
|
+
|
|
99
|
+
The `useRemoteToolCalling` option controls how tool calls from Databricks agents are handled. When enabled, tool calls are marked as `dynamic: true` and `providerExecuted: true`, which tells the AI SDK that:
|
|
100
|
+
|
|
101
|
+
1. **Dynamic**: The tools are not pre-registered - the agent decides which tools to call at runtime
|
|
102
|
+
2. **Provider-executed**: The tools are executed remotely by Databricks, not by your application
|
|
103
|
+
|
|
104
|
+
#### When to use `useRemoteToolCalling: true`
|
|
105
|
+
|
|
106
|
+
Enable this option when your Databricks agent handles tool execution internally:
|
|
107
|
+
|
|
108
|
+
- **Databricks Agents with built-in tools**: Agents that use tools like Python execution, SQL queries, or other Databricks-managed tools
|
|
109
|
+
- **Agents on Apps**: When deploying agents that manage their own tool execution
|
|
110
|
+
- **MCP (Model Context Protocol) integrations**: When tools are executed via MCP servers managed by Databricks
|
|
97
111
|
|
|
98
112
|
```typescript
|
|
99
|
-
|
|
113
|
+
const provider = createDatabricksProvider({
|
|
114
|
+
baseURL: 'https://your-workspace.databricks.com/serving-endpoints',
|
|
115
|
+
headers: { Authorization: `Bearer ${token}` },
|
|
116
|
+
useRemoteToolCalling: true, // Enable for Databricks-managed tool execution
|
|
117
|
+
})
|
|
100
118
|
```
|
|
101
119
|
|
|
102
|
-
####
|
|
120
|
+
#### When NOT to use `useRemoteToolCalling`
|
|
103
121
|
|
|
104
|
-
|
|
122
|
+
Keep this option disabled (the default) when:
|
|
105
123
|
|
|
106
|
-
|
|
124
|
+
- **You define and execute tools locally**: Your application registers tools with the AI SDK and handles their execution
|
|
125
|
+
- **Standard chat completions**: You're using the Chat Completions endpoint without agent features
|
|
126
|
+
- **Hybrid scenarios**: You want to intercept tool calls and handle some locally
|
|
107
127
|
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
128
|
+
```typescript
|
|
129
|
+
// Default behavior - you handle tool execution
|
|
130
|
+
const provider = createDatabricksProvider({
|
|
131
|
+
baseURL: 'https://your-workspace.databricks.com/serving-endpoints',
|
|
132
|
+
headers: { Authorization: `Bearer ${token}` },
|
|
133
|
+
// useRemoteToolCalling defaults to false
|
|
134
|
+
})
|
|
111
135
|
|
|
112
|
-
|
|
136
|
+
const result = await generateText({
|
|
137
|
+
model: provider.chatCompletions('my-model'),
|
|
138
|
+
prompt: 'What is the weather?',
|
|
139
|
+
tools: {
|
|
140
|
+
getWeather: {
|
|
141
|
+
description: 'Get weather for a location',
|
|
142
|
+
parameters: z.object({ location: z.string() }),
|
|
143
|
+
execute: async ({ location }) => {
|
|
144
|
+
// Your local tool execution
|
|
145
|
+
return fetchWeather(location)
|
|
146
|
+
},
|
|
147
|
+
},
|
|
148
|
+
},
|
|
149
|
+
})
|
|
150
|
+
```
|
|
113
151
|
|
|
114
|
-
#### Example:
|
|
152
|
+
#### Example: Remote tool calling with Databricks agents
|
|
115
153
|
|
|
116
154
|
```typescript
|
|
117
155
|
import { streamText } from 'ai'
|
|
118
|
-
import { createDatabricksProvider
|
|
156
|
+
import { createDatabricksProvider } from '@databricks/ai-sdk-provider'
|
|
119
157
|
|
|
120
158
|
const provider = createDatabricksProvider({
|
|
121
159
|
baseURL: 'https://your-workspace.databricks.com/serving-endpoints',
|
|
122
160
|
headers: { Authorization: `Bearer ${token}` },
|
|
161
|
+
useRemoteToolCalling: true,
|
|
123
162
|
})
|
|
124
163
|
|
|
125
164
|
const model = provider.responses('my-agent-endpoint')
|
|
@@ -127,18 +166,17 @@ const model = provider.responses('my-agent-endpoint')
|
|
|
127
166
|
const result = streamText({
|
|
128
167
|
model,
|
|
129
168
|
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
|
-
},
|
|
169
|
+
// No need to pre-register tools - they're handled by Databricks
|
|
134
170
|
})
|
|
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
171
|
|
|
141
|
-
|
|
172
|
+
// Tool calls will have the actual tool name from Databricks
|
|
173
|
+
for await (const part of result.fullStream) {
|
|
174
|
+
if (part.type === 'tool-call') {
|
|
175
|
+
console.log(`Agent called: ${part.toolName}`)
|
|
176
|
+
// Tool is executed remotely - result will come from Databricks
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
```
|
|
142
180
|
|
|
143
181
|
### MCP Utilities
|
|
144
182
|
|
|
@@ -171,34 +209,6 @@ const result = await generateText({
|
|
|
171
209
|
console.log(result.text)
|
|
172
210
|
```
|
|
173
211
|
|
|
174
|
-
### With Tool Calling
|
|
175
|
-
|
|
176
|
-
When your Databricks agent can call tools, register the catch-all tool definition:
|
|
177
|
-
|
|
178
|
-
```typescript
|
|
179
|
-
import { DATABRICKS_TOOL_CALL_ID, DATABRICKS_TOOL_DEFINITION } from '@databricks/ai-sdk-provider'
|
|
180
|
-
|
|
181
|
-
const model = provider.responses('my-agent-with-tools')
|
|
182
|
-
|
|
183
|
-
const result = await generateText({
|
|
184
|
-
model,
|
|
185
|
-
prompt: 'Search for information about AI',
|
|
186
|
-
tools: {
|
|
187
|
-
[DATABRICKS_TOOL_CALL_ID]: DATABRICKS_TOOL_DEFINITION,
|
|
188
|
-
},
|
|
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
|
-
}
|
|
200
|
-
```
|
|
201
|
-
|
|
202
212
|
## Links
|
|
203
213
|
|
|
204
214
|
- [Vercel AI SDK Documentation](https://sdk.vercel.ai/docs)
|