Skip to main content

Tools

Tool types for function calling with LLMs.

ToolType

Tools allow LLMs to invoke external functions. Define tools with a name, description, and JSON Schema parameters.
const tools = [
  {
    type: "function",
    definition: {
      schema: {
        name: "get_weather",
        description: "Get the current weather for a location",
        parameters: {
          type: "object",
          properties: {
            location: {
              type: "string",
              description: "City name, e.g. San Francisco",
            },
            unit: {
              type: "string",
              enum: ["celsius", "fahrenheit"],
              description: "Temperature unit",
            },
          },
          required: ["location"],
        },
      },
    },
    handler: async (args) => {
      // Your function logic here
      return { temperature: 72, condition: "sunny" };
    },
  },
];

Fields

type
string
required
The tool type. Currently only "function" is supported.
definition
object
required
handler
function
An async function that executes when the tool is called via gateway.getToolResponses(). Receives the parsed arguments and returns the result.