Chatoyant - v0.2.1
    Preparing search index...

    Class Tool<TArgs, TResult>

    Tool class for defining callable tools.

    class WeatherParams extends Schema {
    city = Schema.String({ description: "City name" });
    unit = Schema.Enum(["celsius", "fahrenheit"] as const, { optional: true });
    }

    const weatherTool = new Tool({
    name: "get_weather",
    description: "Get current weather for a city",
    parameters: WeatherParams,
    execute: async ({ args }) => {
    const weather = await fetchWeather(args.city);
    return { temperature: weather.temp, conditions: weather.sky };
    },
    });

    chat.addTool(weatherTool);

    Type Parameters

    • TArgs = unknown
    • TResult = unknown
    Index

    Constructors

    Properties

    name: string

    Tool name

    description: string

    Tool description

    parameters: SchemaInstance

    Parameter schema instance

    resultSchema?: SchemaInstance

    Result schema instance (optional)

    timeout: number

    Execution timeout

    Methods

    • Validate arguments against parameter schema.

      Parameters

      • args: unknown

      Returns boolean

    • Parse and validate arguments. Throws SchemaError if invalid.

      Parameters

      • args: unknown

      Returns TArgs

    • Validate result against result schema (if defined).

      Parameters

      • result: unknown

      Returns boolean