Open History to see the last commit
1---
2id: ProviderTool
3title: ProviderTool
4---
5
6Defined in: [packages/ai/src/tools/provider-tool.ts:19](https://github.com/TanStack/ai/blob/main/packages/ai/src/tools/provider-tool.ts#L19)
7
8A provider-specific tool produced by an adapter-package factory
9(e.g. `webSearchTool` from `@tanstack/ai-anthropic/tools`).
10
11The two `~`-prefixed fields are type-only phantom brands — they are never
12assigned at runtime. They allow the core type system to match a factory's
13output against the selected model's `supports.tools` list and surface a
14compile-time error when the combination is unsupported.
15
16User-defined tools (via `toolDefinition()`) remain plain `Tool` and stay
17assignable to any model.
18
19## Extends
20
21- [`Tool`](Tool.md)
22
23## Type Parameters
24
25### TProvider
26
27`TProvider` *extends* `string`
28
29Provider identifier (e.g. `'anthropic'`, `'openai'`).
30
31### TKind
32
33`TKind` *extends* `string`
34
35Canonical tool-kind string matching the provider's
36 `supports.tools` entries (e.g. `'web_search'`, `'code_execution'`).
37
38## Properties
39
40### ~provider
41
42```ts
43readonly ~provider: TProvider;
44```
45
46Defined in: [packages/ai/src/tools/provider-tool.ts:23](https://github.com/TanStack/ai/blob/main/packages/ai/src/tools/provider-tool.ts#L23)
47
48***
49
50### ~toolKind
51
52```ts
53readonly ~toolKind: TKind;
54```
55
56Defined in: [packages/ai/src/tools/provider-tool.ts:24](https://github.com/TanStack/ai/blob/main/packages/ai/src/tools/provider-tool.ts#L24)
57
58***
59
60### description
61
62```ts
63description: string;
64```
65
66Defined in: [packages/ai/src/types.ts:988](https://github.com/TanStack/ai/blob/main/packages/ai/src/types.ts#L988)
67
68Clear description of what the tool does.
69
70This is crucial - the model uses this to decide when to call the tool.
71Be specific about what the tool does, what parameters it needs, and what it returns.
72
73#### Example
74
75```ts
76"Get the current weather in a given location. Returns temperature, conditions, and forecast."
77```
78
79#### Inherited from
80
81[`Tool`](Tool.md).[`description`](Tool.md#description)
82
83***
84
85### execute?
86
87```ts
88optional execute?: (args, context?) => any;
89```
90
91Defined in: [packages/ai/src/types.ts:1068](https://github.com/TanStack/ai/blob/main/packages/ai/src/types.ts#L1068)
92
93Optional function to execute when the model calls this tool.
94
95If provided, the SDK will automatically execute the function with the model's arguments
96and feed the result back to the model. This enables autonomous tool use loops.
97
98Can return any value - will be automatically stringified if needed.
99
100#### Parameters
101
102##### args
103
104`any`
105
106The arguments parsed from the model's tool call (validated against inputSchema)
107
108##### context?
109
110[`ToolExecutionContext`](../type-aliases/ToolExecutionContext.md)\<`unknown`\>
111
112#### Returns
113
114`any`
115
116Result to send back to the model (validated against outputSchema if provided)
117
118#### Example
119
120```ts
121execute: async (args) => {
122 const weather = await fetchWeather(args.location);
123 return weather; // Can return object or string
124}
125```
126
127#### Inherited from
128
129[`Tool`](Tool.md).[`execute`](Tool.md#execute)
130
131***
132
133### inputSchema?
134
135```ts
136optional inputSchema?: SchemaInput;
137```
138
139Defined in: [packages/ai/src/types.ts:1028](https://github.com/TanStack/ai/blob/main/packages/ai/src/types.ts#L1028)
140
141Schema describing the tool's input parameters.
142
143Can be any Standard JSON Schema compliant schema (Zod, ArkType, Valibot, etc.) or a plain JSON Schema object.
144Defines the structure and types of arguments the tool accepts.
145The model will generate arguments matching this schema.
146Standard JSON Schema compliant schemas are converted to JSON Schema for LLM providers.
147
148#### See
149
150 - https://standardschema.dev/json-schema
151 - https://json-schema.org/
152
153#### Examples
154
155```ts
156// Using Zod v4+ schema (natively supports Standard JSON Schema)
157import { z } from 'zod';
158z.object({
159 location: z.string().describe("City name or coordinates"),
160 unit: z.enum(["celsius", "fahrenheit"]).optional()
161})
162```
163
164```ts
165// Using ArkType (natively supports Standard JSON Schema)
166import { type } from 'arktype';
167type({
168 location: 'string',
169 unit: "'celsius' | 'fahrenheit'"
170})
171```
172
173```ts
174// Using plain JSON Schema
175{
176 type: 'object',
177 properties: {
178 location: { type: 'string', description: 'City name or coordinates' },
179 unit: { type: 'string', enum: ['celsius', 'fahrenheit'] }
180 },
181 required: ['location']
182}
183```
184
185#### Inherited from
186
187[`Tool`](Tool.md).[`inputSchema`](Tool.md#inputschema)
188
189***
190
191### lazy?
192
193```ts
194optional lazy?: boolean;
195```
196
197Defined in: [packages/ai/src/types.ts:1074](https://github.com/TanStack/ai/blob/main/packages/ai/src/types.ts#L1074)
198
199If true, this tool is lazy and will only be sent to the LLM after being discovered via the lazy tool discovery mechanism. Works with both chat() (the synthetic discovery tool) and Code Mode (kept out of the system prompt and revealed via discover_tools).
200
201#### Inherited from
202
203[`Tool`](Tool.md).[`lazy`](Tool.md#lazy)
204
205***
206
207### metadata?
208
209```ts
210optional metadata?: Record<string, any>;
211```
212
213Defined in: [packages/ai/src/types.ts:1085](https://github.com/TanStack/ai/blob/main/packages/ai/src/types.ts#L1085)
214
215Additional metadata for adapters or custom extensions
216
217#### Inherited from
218
219[`Tool`](Tool.md).[`metadata`](Tool.md#metadata)
220
221***
222
223### name
224
225```ts
226name: string;
227```
228
229Defined in: [packages/ai/src/types.ts:978](https://github.com/TanStack/ai/blob/main/packages/ai/src/types.ts#L978)
230
231Unique name of the tool (used by the model to call it).
232
233Should be descriptive and follow naming conventions (e.g., snake_case or camelCase).
234Must be unique within the tools array.
235
236#### Example
237
238```ts
239"get_weather", "search_database", "sendEmail"
240```
241
242#### Inherited from
243
244[`Tool`](Tool.md).[`name`](Tool.md#name)
245
246***
247
248### needsApproval?
249
250```ts
251optional needsApproval?: boolean;
252```
253
254Defined in: [packages/ai/src/types.ts:1071](https://github.com/TanStack/ai/blob/main/packages/ai/src/types.ts#L1071)
255
256If true, tool execution requires user approval before running. Works with both server and client tools.
257
258#### Inherited from
259
260[`Tool`](Tool.md).[`needsApproval`](Tool.md#needsapproval)
261
262***
263
264### outputSchema?
265
266```ts
267optional outputSchema?: SchemaInput;
268```
269
270Defined in: [packages/ai/src/types.ts:1049](https://github.com/TanStack/ai/blob/main/packages/ai/src/types.ts#L1049)
271
272Optional schema for validating tool output.
273
274Can be any Standard JSON Schema compliant schema or a plain JSON Schema object.
275If provided with a Standard Schema compliant schema, tool results will be validated
276against this schema before being sent back to the model. This catches bugs in tool
277implementations and ensures consistent output formatting.
278
279Note: This is client-side validation only - not sent to LLM providers.
280Note: Plain JSON Schema output validation is not performed at runtime.
281
282#### Example
283
284```ts
285// Using Zod
286z.object({
287 temperature: z.number(),
288 conditions: z.string(),
289 forecast: z.array(z.string()).optional()
290})
291```
292
293#### Inherited from
294
295[`Tool`](Tool.md).[`outputSchema`](Tool.md#outputschema)
296
297***
298
299### replay?
300
301```ts
302optional replay?: "safe" | "never";
303```
304
305Defined in: [packages/ai/src/types.ts:1082](https://github.com/TanStack/ai/blob/main/packages/ai/src/types.ts#L1082)
306
307Whether a host may run this tool again after a crash cut the run
308between the call and its result. `'safe'` runs it again. Omit the
309field, or set `'never'`, when a second run is not safe. The host
310writes the model note. `chat()` does not read this field.
311
312#### Inherited from
313
314[`Tool`](Tool.md).[`replay`](Tool.md#replay)