Tool class abstract

Base class for defining tools that can be called by the language model.

Tools allow the language model to perform actions or retrieve information that it cannot do on its own, such as fetching live data, performing calculations, or interacting with external services.

To create a tool, extend this class and implement:

  • name - A unique identifier for the tool
  • description - A description of what the tool does (used by the model)
  • parameters - The schema defining the tool's input parameters
  • call - The function that executes when the model calls the tool

Example:

@Generable()
class WeatherArgs {
  @Guide(description: "The city to get weather for")
  final String city;
  WeatherArgs({required this.city});
}

class WeatherTool extends Tool {
  @override
  String name = "getWeather";

  @override
  String description = "Get current weather for a city";

  @override
  GenerationSchema get parameters => $WeatherArgsGenerable.generationSchema;

  @override
  Future<GeneratedContent> call(GeneratedContent arguments) async {
    final args = $WeatherArgsGenerable.fromGeneratedContent(arguments);
    // Fetch weather data...
    return WeatherResult(temperature: 72, condition: "sunny").toGeneratedContent();
  }
}

Constructors

Tool()

Properties

description String
A description of what this tool does.
no setter
hashCode int
The hash code for this object.
no setterinherited
name String
The unique name of this tool.
no setter
parameters GenerationSchema
The schema defining the tool's input parameters.
no setter
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

call(GeneratedContent arguments) Future<GeneratedContent>
Executes the tool with the given arguments.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toJson() Map<String, dynamic>
Converts this tool to a JSON representation.
toString() String
A string representation of this object.
inherited

Operators

operator ==(Object other) bool
The equality operator.
inherited