Class MethodToolCallback

java.lang.Object
org.springframework.ai.tool.method.MethodToolCallback
All Implemented Interfaces:
FunctionCallback, ToolCallback

public class MethodToolCallback extends Object implements ToolCallback
A ToolCallback implementation to invoke methods as tools.
Since:
1.0.0
Author:
Thomas Vitale
  • Constructor Details

  • Method Details

    • getToolDefinition

      public ToolDefinition getToolDefinition()
      Description copied from interface: ToolCallback
      Definition used by the AI model to determine when and how to call the tool.
      Specified by:
      getToolDefinition in interface ToolCallback
    • getToolMetadata

      public ToolMetadata getToolMetadata()
      Description copied from interface: ToolCallback
      Metadata providing additional information on how to handle the tool.
      Specified by:
      getToolMetadata in interface ToolCallback
    • call

      public String call(String toolInput)
      Description copied from interface: FunctionCallback
      Called when a model detects and triggers a function call. The model is responsible to pass the function arguments in the pre-configured JSON schema format.
      Specified by:
      call in interface FunctionCallback
      Parameters:
      toolInput - JSON string with the function arguments to be passed to the function. The arguments are defined as JSON schema usually registered with the model.
      Returns:
      String containing the function call response.
    • call

      public String call(String toolInput, @Nullable ToolContext toolContext)
      Description copied from interface: FunctionCallback
      Called when a model detects and triggers a function call. The model is responsible to pass the function arguments in the pre-configured JSON schema format. Additionally, the model can pass a context map to the function if available. The context is used to pass additional user provided state in addition to the arguments provided by the AI model.
      Specified by:
      call in interface FunctionCallback
      Parameters:
      toolInput - JSON string with the function arguments to be passed to the function. The arguments are defined as JSON schema usually registered with the model. Arguments are provided by the AI model.
      toolContext - Map with the function context. The context is used to pass additional user provided state in addition to the arguments provided by the AI model.
      Returns:
      String containing the function call response.
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • builder

      public static MethodToolCallback.Builder builder()
      Description copied from interface: FunctionCallback
      Creates a new FunctionCallback.Builder instance used to build a default FunctionCallback instance.
      Returns:
      Returns a new FunctionCallback.Builder instance.