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
| Property | Type | Required | Description |
|---|---|---|---|
name | string | Yes | Unique identifier for the tool |
description | string | Yes | What the tool does (helps the AI decide when to use it) |
cb | function | Yes | The function to execute |
inputSchema | ZodObject | No | Schema for input parameters |
defaultLoadingText | string | No | Text shown while the tool runs |
defaultSuccessText | string | No | Text shown when complete |
Next Steps
- React Integration — Using tools with React hooks
- Chat SDK Reference — Full API documentation
- Tool Calls — Advanced patterns and best practices