Tool class abstract

Base class for all agent tools.

Implementing a tool

class MyTool extends Tool {
  @override
  String get name => 'my_tool';

  @override
  String get description => 'Does something useful.';

  @override
  Map<String, String> get inputSchema => {
    'query': 'The input string to process.',
  };

  @override
  Future<ToolResult> run(Map<String, dynamic> input) async {
    final q = input['query'] as String? ?? '';
    return ToolResult.success(name, 'Processed: $q');
  }
}
Implementers

Constructors

Tool()
const

Properties

description → String
One-sentence description included in the system prompt.
no setter
hashCode → int
The hash code for this object.
no setterinherited
inputSchema → Map<String, String>
Schema of expected input keys and their descriptions.
no setter
isIdempotent → bool
Whether this tool can safely be retried on failure.
no setter
name → String
Unique snake_case name the LLM uses to invoke this tool.
no setter
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
run(Map<String, dynamic> input) → Future<ToolResult>
Executes the tool with the given input map.
toString() → String
A string representation of this object.
override
validate(Map<String, dynamic> input) → String?
Validates the input map against inputSchema.

Operators

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