Appearance
Function: tool()
ts
function tool<S>(config: ToolConfig<S>): ChatToolDef<output<S>>;Defined in: packages/sdk/src/renderer/templates/chat-tools.ts:316
Define a tool the model may call during a chat. The model picks a tool by its description, fills the typed input, and execute runs skill-side and returns what the turn shows.
Type Parameters
| Type Parameter | Default type |
|---|---|
S extends ZodType<unknown, unknown, $ZodTypeInternals<unknown, unknown>> | ZodType<{ prompt: string; }, unknown, $ZodTypeInternals<{ prompt: string; }, unknown>> |
Parameters
| Parameter | Type |
|---|---|
config | ToolConfig<S> |
Returns
ChatToolDef<output<S>>
Example
ts
import {tool, reply, z} from '@matterway/sdk/UI';
const weather = tool({
description: 'Current weather for a city',
inputSchema: z.object({city: z.string()}),
execute: async ({city}) => {
const w = await getWeather(city);
return reply(`It's ${w.tempC}°C in ${city}.`); // …or `return w` to let the AI phrase it
},
});