Skip to main content
Tools are functions that can be called by the AI model during conversations. They allow your agent to perform actions, retrieve information, or interact with external systems based on user requests.

Creating a tool

Create a tool in src/tools/:
import { Autonomous } from "@botpress/runtime";
import { z } from "@botpress/sdk";

export default new Autonomous.Tool({
  name: "myTool",
  description: "A tool that does something useful",
  input: z.object({}), // Input schema
  output: z.object({}), // Output schema
  handler: async ({}) => {
    // Tool logic
    return {};
  },
});

Tool input and output

Define input and output schemas using Zod schemas. The AI model uses these schemas to understand when and how to call your tool:
import { Autonomous } from "@botpress/runtime";
import { z } from "@botpress/sdk";

export default new Autonomous.Tool({
  name: "getWeather",
  description: "Get the current weather for a location",
  input: z.object({
    location: z.string().describe("The city or location name"),
    unit: z.enum(["celsius", "fahrenheit"]).optional().describe("Temperature unit"),
  }),
  output: z.object({
    temperature: z.number(),
    condition: z.string(),
  }),
  handler: async ({ location, unit }) => {
    // Fetch weather data
    const weather = await fetchWeatherData(location, unit);
    return {
      temperature: weather.temp,
      condition: weather.condition,
    };
  },
});

Using tools in conversations

Provide an array of tools to your agent in a conversation handler:
import { Conversation } from "@botpress/runtime";
import getWeather from "../tools/weather";

export default new Conversation({
  channel: "*",
  handler: async ({ execute }) => {
    await execute({
      instructions: "You are a helpful weather assistant.",
      tools: [getWeather],
    });
  },
});

Converting actions to tools

You can convert actions to tools using the asTool() method:
import { Conversation, actions } from "@botpress/runtime";

export default new Conversation({
  channel: "*",
  handler: async ({ execute }) => {
    await execute({
      instructions: "You are a helpful assistant.",
      tools: [actions.calculateTotal.asTool()],
    });
  },
});

Tool handler

The handler function receives the input parameters and executes the tool’s logic. It can also call custom actions.
import { Autonomous } from "@botpress/runtime";
import { z } from "@botpress/sdk";

export default new Autonomous.Tool({
  name: "searchDatabase",
  description: "Search the database",
  input: z.object({
    query: z.string(),
  }),
  handler: async ({ query }) => {
    // Perform search
    return { results: [] };
  },
});

Multiple tools

You can provide multiple tools to your agent:
import { Conversation } from "@botpress/runtime";
import { getWeather, searchDatabase, processOrder } from "../tools/index";

export default new Conversation({
  channel: "*",
  handler: async ({ execute }) => {
    await execute({
      instructions: "You are a helpful assistant with access to various tools.",
      tools: [
        getWeather,
        searchDatabase,
        processOrder,
      ],
    });
  },
});

Tool descriptions

The description field is crucial—it helps the AI model understand when to use your tool. Write clear, concise descriptions:
export default new Autonomous.Tool({
  name: "calculateTotal",
  description: "Calculate the total price of items including tax and shipping. Use this when the user asks about prices, costs, or totals.",
  input: z.object({
    items: z.array(z.object({
      price: z.number(),
      quantity: z.number(),
    })),
  }),
  // ...
});

Best practices

  • Write clear, descriptive tool names and descriptions
  • Use Zod schemas with .describe() to provide context for each input parameter
  • Keep tool handlers focused on a single responsibility
  • Use tools for operations that require external data or actions
  • Test tools independently before using them in conversations
Tools are ideal for operations that the AI model needs to perform dynamically based on user requests. They enable your agent to go beyond just generating text and actually interact with systems, retrieve data, and perform actions.

Reference

Tool props

Handler parameters

The handler function receives validated input and execution context: