Tools are functions that perform specific tasks and can be called by agents.
In Icepick, a tool is a function that performs a specific task and can be called by agents. Tools handle the actual work while agents orchestrate their execution.
To create a tool, define the input and output schemas using Zod. Each Zod field should include a description to improve LLM tool selection when used in a toolbox.
Copy
import z from "zod";const MyToolInput = z.object({ message: z.string().describe("The message to process"),});const MyToolOutput = z.object({ result: z.string().describe("The processed result"),});
export const myTool = icepick.tool({ name: "my-tool", description: "Processes messages and returns results", inputSchema: MyToolInput, outputSchema: MyToolOutput, fn: async (input) => { // Tool logic here - API calls, data processing, etc. return { result: `Processed: ${input.message}`, }; },});
Tools can perform side effects like API calls, database operations, or file system access. Unlike agents, tools are designed to do the actual work and can maintain state as needed.
Tools can also be scheduled to run at specific times or on recurring schedules:
Copy
// Schedule to run at a specific timeconst scheduledRun = await myTool.schedule(new Date("2024-12-25T09:00:00Z"), { message: "Christmas task",});// Schedule with a delayconst delayedRun = await myTool.delay( 300, // 300 seconds = 5 minutes { message: "Delayed task" });// Set up recurring cron scheduleconst cronRun = await myTool.cron( "daily-cleanup", "0 2 * * *", // Every day at 2 AM { message: "Daily cleanup task" });