Tool class

A tool available for the model to call.

Currently only supports function tools, but the structure allows for future expansion to other tool types.

Example

final tool = Tool.function(
  name: 'get_weather',
  description: 'Get the current weather for a location',
  parameters: {
    'type': 'object',
    'properties': {
      'location': {
        'type': 'string',
        'description': 'The city and state, e.g. San Francisco, CA',
      },
      'unit': {
        'type': 'string',
        'enum': ['celsius', 'fahrenheit'],
      },
    },
    'required': ['location'],
  },
);
Annotations
  • @immutable

Constructors

Tool({required String type, required FunctionDefinition function})
Creates a Tool.
const
Tool.fromJson(Map<String, dynamic> json)
Creates a Tool from JSON.
factory
Tool.function({required String name, String? description, Map<String, dynamic>? parameters, bool strict = false})
Creates a function tool.
factory

Properties

function FunctionDefinition
The function definition.
final
hashCode int
The hash code for this object.
no setteroverride
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
type String
The type of the tool (currently only "function").
final

Methods

copyWith({String? type, FunctionDefinition? function}) Tool
Creates a copy with the given fields replaced.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toJson() Map<String, dynamic>
Converts to JSON.
toString() String
A string representation of this object.
override

Operators

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