Puck AI 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
mode"auto"”auto” | “inline” | “preload”-
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

mode

The execution mode for this tool. One of:

  • auto (default): Automatically use preload or inline modes as appropriate
  • preload: Call this tool before generating a page, and load it into the context window
  • inline: Call this tool during a generation, and bind the result to a field
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
  },
  mode: "inline", // Only allow this tool to be bound to a field
});

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
  },
});