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.
nameis the unique name of the tool that clearly communicates its purpose.descriptionis used to tell the model how/when/why to use the tool. You can provide few-shot examples as a part of the description.strictwhether to enable strict schema adherence when generating the tool call (only supported by some providers).funcis the function that will be called when the tool is run.returnDirectwhether to return the tool's output directly. Setting this to true means that after the tool is called, the AgentExecutor will stop looping.handleToolErroris 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,
);
}