Class AgentFunctionCallbackWrapper<I,O>

java.lang.Object
org.bsc.spring.agentexecutor.function.AgentFunctionCallbackWrapper<I,O>
Type Parameters:
I - the type of the input
O - the type of the output
All Implemented Interfaces:
BiFunction<I,org.springframework.ai.chat.model.ToolContext,O>, org.springframework.ai.model.function.FunctionCallback

public class AgentFunctionCallbackWrapper<I,O> extends Object implements BiFunction<I,org.springframework.ai.chat.model.ToolContext,O>, org.springframework.ai.model.function.FunctionCallback
A wrapper for a FunctionCallback.
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    static class 
    A class that serves as a builder for creating instances of AgentFunctionCallbackWrapper.

    Nested classes/interfaces inherited from interface org.springframework.ai.model.function.FunctionCallback

    org.springframework.ai.model.function.FunctionCallback.FunctionInvokingSpec<I extends Object,O extends Object>, org.springframework.ai.model.function.FunctionCallback.MethodInvokingSpec
  • Constructor Summary

    Constructors
    Modifier
    Constructor
    Description
    protected
    AgentFunctionCallbackWrapper(String name, String description, String inputTypeSchema, Class<I> inputType, Function<O,String> responseConverter, com.fasterxml.jackson.databind.ObjectMapper objectMapper, BiFunction<I,org.springframework.ai.chat.model.ToolContext,O> function)
    Constructs a new instance of the AgentFunctionCallbackWrapper class with the specified parameters.
  • Method Summary

    Modifier and Type
    Method
    Description
    apply(I input, org.springframework.ai.chat.model.ToolContext context)
    Applies a function to the given input and context.
    builder(BiFunction<I,org.springframework.ai.chat.model.ToolContext,O> biFunction)
    Creates a builder for an agent function callback.
    builder(Function<I,O> function)
    Creates a builder for an AgentFunctionCallbackWrapper.
    call(String functionArguments)
    Calls a specified function with the provided arguments.
    call(String functionInput, org.springframework.ai.chat.model.ToolContext toolContext)
    Executes a given function with the provided input and tool context.
    convertResponse(org.springframework.ai.chat.messages.ToolResponseMessage.ToolResponse toolResponse)
    Converts a ToolResponseMessage.ToolResponse object to the specified output type.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

    Methods inherited from interface java.util.function.BiFunction

    andThen

    Methods inherited from interface org.springframework.ai.model.function.FunctionCallback

    getDescription, getInputTypeSchema, getName
  • Constructor Details

    • AgentFunctionCallbackWrapper

      protected AgentFunctionCallbackWrapper(String name, String description, String inputTypeSchema, Class<I> inputType, Function<O,String> responseConverter, com.fasterxml.jackson.databind.ObjectMapper objectMapper, BiFunction<I,org.springframework.ai.chat.model.ToolContext,O> function)
      Constructs a new instance of the AgentFunctionCallbackWrapper class with the specified parameters.
      Parameters:
      name - the name of the agent function callback wrapper, must not be null
      description - a description of the agent function callback wrapper, must not be null
      inputTypeSchema - the schema of the input type of the agent function, must not be null
      inputType - the input class type of the agent function, must not be null
      responseConverter - a function to convert the response object to a string, must not be null
      objectMapper - an instance of ObjectMapper for JSON processing, must not be null
      function - a bi-function that executes the agent function with the input and returns a result, must not be null
  • Method Details

    • convertResponse

      public O convertResponse(org.springframework.ai.chat.messages.ToolResponseMessage.ToolResponse toolResponse)
      Converts a ToolResponseMessage.ToolResponse object to the specified output type.
      Parameters:
      toolResponse - The response message from an external tool. Must not be null.
      Returns:
      An instance of the target class populated with data from the tool response.
      Throws:
      RuntimeException - if there is an error processing the JSON data.
    • call

      public String call(String functionInput, org.springframework.ai.chat.model.ToolContext toolContext)
      Executes a given function with the provided input and tool context.
      Specified by:
      call in interface org.springframework.ai.model.function.FunctionCallback
      Parameters:
      functionInput - The input string in JSON format representing the function to be called.
      toolContext - The context object containing tools and utilities required for executing the function.
      Returns:
      A string representing the result of the function execution, converted to a format suitable for output.
    • call

      public String call(String functionArguments)
      Calls a specified function with the provided arguments.
      Specified by:
      call in interface org.springframework.ai.model.function.FunctionCallback
      Parameters:
      functionArguments - The arguments for the function as a JSON string.
      Returns:
      A string representing the response after processing.
    • apply

      public O apply(I input, org.springframework.ai.chat.model.ToolContext context)
      Applies a function to the given input and context.
      Specified by:
      apply in interface BiFunction<I,org.springframework.ai.chat.model.ToolContext,O>
      Parameters:
      input - the input to apply
      context - the context in which to apply the input
      Returns:
      the result of applying the input and context
    • builder

      public static <I, O> AgentFunctionCallbackWrapper.Builder<I,O> builder(BiFunction<I,org.springframework.ai.chat.model.ToolContext,O> biFunction)
      Creates a builder for an agent function callback.
      Type Parameters:
      I - The type of input to the bi-function.
      O - The type of output from the bi-function.
      Parameters:
      biFunction - The bi-function that will be used to create the agent function.
      Returns:
      A new builder instance.
    • builder

      public static <I, O> AgentFunctionCallbackWrapper.Builder<I,O> builder(Function<I,O> function)
      Creates a builder for an AgentFunctionCallbackWrapper. The builder takes a Function that defines the mapping from input type I to output type O.
      Type Parameters:
      I - the input type of the function
      O - the output type of the function
      Returns:
      a new Builder instance that can be used to configure and build an AgentFunctionCallbackWrapper