Skip to main content

Add a Tool

Tools let the AI interact with your app — reading data, calling APIs, and performing actions. This is where Plucky gets powerful.

Your First Tool

Let's add a simple tool that gives the AI information about the current user.

import { addTools } from '@plucky-ai/chat-sdk'

// Demo data (in a real app, this comes from your backend/state)
const user = {
name: 'Jane Smith',
plan: 'Pro',
storageUsed: '4.2 GB',
storageLimit: '10 GB',
}

addTools({
name: 'get_account_info',
description: 'Get information about the current user and their account',
cb: async () => {
return `User: ${user.name}, Plan: ${user.plan}, Storage: ${user.storageUsed} of ${user.storageLimit}`
},
})

Now try asking: "What plan am I on?" or "How much storage do I have?"

Tool with Parameters

Tools can accept input using a Zod schema. Here's a tool that performs an action:

import { addTools } from '@plucky-ai/chat-sdk'
import { z } from 'zod'

addTools({
name: 'cancel_order',
description: 'Cancel an order by ID',
inputSchema: z.object({
orderId: z.string().describe('The order ID to cancel'),
}),
defaultLoadingText: 'Cancelling order...',
cb: async (input) => {
// In a real app: await api.cancelOrder(input.orderId)
return {
content: `Order ${input.orderId} has been cancelled.`,
successText: 'Order cancelled',
}
},
})

Tool Options

PropertyTypeRequiredDescription
namestringYesUnique identifier for the tool
descriptionstringYesWhat the tool does (helps the AI decide when to use it)
cbfunctionYesThe function to execute
inputSchemaZodObjectNoSchema for input parameters
defaultLoadingTextstringNoText shown while the tool runs
defaultSuccessTextstringNoText shown when complete

Next Steps