ToolChoice class sealed

Controls which tool the model should use.

Tool choice can be:

Example

// Let the model decide
final auto = ToolChoice.auto();

// Force specific function
final specific = ToolChoice.function('get_weather');

// Constrain to allowed tools
final allowed = ToolChoice.allowedTools(
  mode: 'auto',
  tools: [
    {'type': 'function', 'function': {'name': 'get_weather'}},
  ],
);

// Force specific custom tool
final custom = ToolChoice.custom('my_custom_tool');
Implementers
Annotations
  • @immutable

Constructors

ToolChoice.fromJson(Object? json)
Creates a ToolChoice from JSON.
factory

Properties

hashCode int
The hash code for this object.
no setterinherited
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toJson() Object
Converts to JSON.
toString() String
A string representation of this object.
inherited

Operators

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

Static Methods

allowedTools({required String mode, required List<Map<String, dynamic>> tools}) ToolChoice
Constrain the model to a set of allowed tools.
auto() ToolChoice
Let the model decide whether to call a tool.
custom(String name) ToolChoice
Force the model to call a specific custom tool.
function(String name) ToolChoice
Force the model to call a specific function.
none() ToolChoice
Disable tool calling.
required() ToolChoice
Force the model to call a tool.