Tool<Input extends Object, Options extends ToolOptions, Output extends Object> class abstract base

A LangChain tool.

The Input to the tool needs to be described by the inputJsonSchema.

You can easily create a tool from a function using Tool.fromFunction.

If you want to create a tool that accepts a single string input and returns a string output, you can use StringTool or StringTool.fromFunction.

Inheritance
Implemented types
Implementers

Constructors

Tool({required String name, required String description, required Map<String, dynamic> inputJsonSchema, bool strict = false, bool returnDirect = false, Output handleToolError(ToolException)?, Options? defaultOptions})
A LangChain tool.

Properties

defaultOptions → Options
The default options to use when invoking the Runnable.
finalinherited
description String
Used to tell the model how/when/why to use the tool. You can provide few-shot examples as a part of the description.
final
handleToolError → Output Function(ToolException)?
Handle the content of the ToolException thrown by the tool.
final
hashCode int
The hash code for this object.
no setteroverride
inputJsonSchema Map<String, dynamic>
Schema to parse and validate tool's input arguments. Following the JSON Schema specification.
final
name String
The unique name of the tool that clearly communicates its purpose.
final
returnDirect bool
Whether to return the tool's output directly. Setting this to true means that after the tool is called, the AgentExecutor will stop looping.
final
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
strict bool
Whether to enable strict schema adherence when generating the tool call. If set to true, the model will follow the exact schema defined in the inputJsonSchema field.
final

Methods

batch(List<Input> inputs, {List<Options>? options}) Future<List<Output>>
Batches the invocation of the Runnable on the given inputs.
inherited
bind(Options options) RunnableBinding<Input, Options, Output>
Binds the Runnable to the given options.
inherited
close() → void
Cleans up any resources associated with it the Runnable.
inherited
getCompatibleOptions(RunnableOptions? options) → Options?
Returns the given options if they are compatible with the Runnable, otherwise returns null.
inherited
getInputFromJson(Map<String, dynamic> json) → Input
Parses the input JSON to the tool's input type.
invoke(Input input, {Options? options}) Future<Output>
Runs the tool.
override
invokeInternal(Input input, {Options? options}) Future<Output>
Actual implementation of invoke method logic.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
pipe<NewRunOutput extends Object?, NewCallOptions extends RunnableOptions>(Runnable<Output, NewCallOptions, NewRunOutput> next) RunnableSequence<Input, NewRunOutput>
Pipes the output of this Runnable into another Runnable using a RunnableSequence.
inherited
stream(Input input, {Options? options}) Stream<Output>
Streams the output of invoking the Runnable on the given input.
inherited
streamFromInputStream(Stream<Input> inputStream, {Options? options}) Stream<Output>
Streams the tool's output for the input resulting from reducing the input stream.
override
toJson() Map<String, dynamic>
Converts the tool spec to a JSON-serializable map.
override
toString() String
A string representation of this object.
inherited
withFallbacks(List<Runnable<Input, RunnableOptions, Output>> fallbacks) RunnableWithFallback<Input, Output>
Adds fallback runnables to be invoked if the primary runnable fails.
inherited

Operators

operator ==(covariant ToolSpec other) bool
The equality operator.
override

Static Methods

fromFunction<Input extends Object, Output extends Object>({required String name, required String description, required Map<String, dynamic> inputJsonSchema, bool strict = false, required FutureOr<Output> func(Input input), Input getInputFromJson(Map<String, dynamic> json)?, bool returnDirect = false, Output handleToolError(ToolException)?}) Tool<Object, ToolOptions, Object>
Creates a Tool from a function.
override