fromFunction<Options extends ToolOptions> static method

StringTool<ToolOptions> fromFunction<Options extends ToolOptions>({
  1. required String name,
  2. required String description,
  3. String inputDescription = 'The input to the tool',
  4. bool strict = false,
  5. required FutureOr<String> func(
    1. String input
    ),
  6. bool returnDirect = false,
  7. String handleToolError(
    1. ToolException
    )?,
})
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,
  );
}