Puck AI closed beta
Read docs
API ReferenceAICloud Clienttool

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

ParamExampleTypeStatus
description"Get a list of product codes"StringRequired
inputSchemaz.object()Zod ObjectRequired
execute() => "Result"FunctionRequired
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
  },
});