fromFunction<Options extends ToolOptions> static method
StringTool<ToolOptions>
fromFunction<Options extends ToolOptions>({
- required String name,
- required String description,
- String inputDescription = 'The input to the tool',
- bool strict = false,
- required FutureOr<
String> func(- String input
- bool returnDirect = false,
- String handleToolError()?,
override
Creates a StringTool from a function.
name
is the unique name of the tool that clearly communicates its purpose.description
is used to tell the model how/when/why to use the tool. You can provide few-shot examples as a part of the description.strict
whether to enable strict schema adherence when generating the tool call (only supported by some providers).func
is the function that will be called when the tool is run.returnDirect
whether to return the tool's output directly. Setting this to true means that after the tool is called, the AgentExecutor will stop looping.handleToolError
is a function that handles the content of the ToolException thrown by the tool.
Implementation
static StringTool fromFunction<Options extends ToolOptions>({
required final String name,
required final String description,
final String inputDescription = 'The input to the tool',
final bool strict = false,
required final FutureOr<String> Function(String input) func,
final bool returnDirect = false,
final String Function(ToolException)? handleToolError,
}) {
return _StringToolFunc<Options>(
name: name,
description: description,
inputDescription: inputDescription,
strict: strict,
func: func,
returnDirect: returnDirect,
handleToolError: handleToolError,
);
}