Skip to main content

ActionDefinition

interface ActionDefinition {
    name: string
    description: string
    options?: Record<string, ActionOption>
    approvalRequired?: boolean
}

Properties

PropertyTypeRequiredDescription
namestringYesUnique identifier for the action
descriptionstringYesExplains when to use this action
optionsRecord<string, ActionOption>NoParameters the action accepts
approvalRequiredbooleanNoRequire user confirmation

ActionOption

interface ActionOption {
    type: "string" | "number" | "boolean"
    description?: string
    required?: boolean
}

Properties

PropertyTypeRequiredDefaultDescription
type"string" | "number" | "boolean"YesParameter type
descriptionstringNoExplains the parameter
requiredbooleanNofalseWhether parameter is required

ToolAction

The action object passed to onAction:
interface ToolAction {
    name: string
    options?: Record<string, unknown>
}

Examples

Simple Action

{
    name: "refresh",
    description: "Refresh the current view",
}

Action with Options

{
    name: "createProject",
    description: "Create a new project with a name and optional description",
    options: {
        name: {
            type: "string",
            description: "Project name",
            required: true,
        },
        description: {
            type: "string",
            description: "Project description",
            required: false,
        },
    },
}

Destructive Action

{
    name: "deleteProject",
    description: "Permanently delete a project and all its data",
    options: {
        projectId: {
            type: "string",
            description: "ID of the project to delete",
            required: true,
        },
    },
    approvalRequired: true,
}

Boolean Option

{
    name: "toggleNotifications",
    description: "Enable or disable notifications",
    options: {
        enabled: {
            type: "boolean",
            description: "Whether notifications are enabled",
            required: true,
        },
    },
}

Number Option

{
    name: "setQuantity",
    description: "Set the quantity for an item",
    options: {
        itemId: {
            type: "string",
            required: true,
        },
        quantity: {
            type: "number",
            description: "New quantity (must be positive)",
            required: true,
        },
    },
}

Best Practices

Descriptions

Write specific descriptions that tell the AI when to use the action:
// Good
description: "Archive a project. The project will be hidden from the active list but can be restored later."

// Bad
description: "Archive"

Naming

Use clear, verb-based names:
// Good
name: "createProject"
name: "deleteUser"
name: "toggleDarkMode"

// Bad
name: "project"
name: "doDelete"
name: "darkMode"

Approval

Mark destructive or irreversible actions:
// Should require approval
{ name: "deleteAccount", approvalRequired: true }
{ name: "sendEmail", approvalRequired: true }
{ name: "publishPost", approvalRequired: true }

// Usually don't need approval
{ name: "createDraft", approvalRequired: false }
{ name: "updateSettings", approvalRequired: false }
{ name: "search", approvalRequired: false }