tool
Define a function that the agent can execute on your server.
import { tool } from "@puckeditor/cloud-client";
const myTool = tool({
description: "Get the weather for a set of coordinates",
inputSchema: z.object({
longitude: z.number(),
latitude: z.number(),
}),
execute: async ({ longitude, latitude }) => {
return getWeather({ longitude, latitude }); // Query your database
},
});Parameters
| Param | Example | Type | Status |
|---|---|---|---|
description | "Get a list of product codes" | String | Required |
inputSchema | z.object() | Zod Object | Required |
execute | () => "Result" | Function | Required |
name | "Get Products" | String | - |
Required Params
description
A description that the agent will use to understand how to use this tool.
import { tool } from "@puckeditor/cloud-client";
const myTool = tool({
description: "Get the weather for a set of coordinates",
inputSchema: z.object({
longitude: z.number(),
latitude: z.number(),
}),
execute: async ({ longitude, latitude }) => {
return getWeather({ longitude, latitude }); // Query your database
},
});inputSchema
The shape of the parameters provided to the execute() function. Uses zod. Must be a zod object (z.object()).
import { tool } from "@puckeditor/cloud-client";
const myTool = tool({
description: "Get the weather for a set of coordinates",
inputSchema: z.object({
longitude: z.number(),
latitude: z.number(),
}),
execute: async ({ longitude, latitude }) => {
return getWeather({ longitude, latitude }); // Query your database
},
});execute
The execution function for the tool. Will receive parameters provided by the agent that match the inputSchema.
import { tool } from "@puckeditor/cloud-client";
const myTool = tool({
description: "Get the weather for a set of coordinates",
inputSchema: z.object({
longitude: z.number(),
latitude: z.number(),
}),
execute: async ({ longitude, latitude }) => {
return getWeather({ longitude, latitude }); // Query your database
},
});Optional Params
name
An optional name for the tool.
import { tool } from "@puckeditor/cloud-client";
const myTool = tool({
name: "getWeather",
description: "Get the weather for a set of coordinates",
inputSchema: z.object({
longitude: z.number(),
latitude: z.number(),
}),
execute: async ({ longitude, latitude }) => {
return getWeather({ longitude, latitude }); // Query your database
},
});