Class AgentFunctionCallbackWrapper.Builder<I,O>

java.lang.Object
org.bsc.spring.agentexecutor.function.AgentFunctionCallbackWrapper.Builder<I,O>
Type Parameters:
I - The input type for the function or bi-function being built.
O - The output type for the function or bi-function being built.
Enclosing class:
AgentFunctionCallbackWrapper<I,O>

public static class AgentFunctionCallbackWrapper.Builder<I,O> extends Object
A class that serves as a builder for creating instances of AgentFunctionCallbackWrapper. This builder allows for the specification of various properties such as name, description, input type, and response converter, providing a structured way to construct complex objects.
  • Constructor Details

    • Builder

      public Builder(BiFunction<I,org.springframework.ai.chat.model.ToolContext,O> biFunction)
      Initializes a new instance of the Builder class with the specified BiFunction.
      Parameters:
      biFunction - The BiFunction that the builder will use to handle operations, which cannot be null.
    • Builder

      public Builder(Function<I,O> function)
      Constructs a new instance of the Builder class.
      Parameters:
      function - The function to be used for processing input and producing output.
      Throws:
      IllegalArgumentException - if the function is null.
  • Method Details

    • withName

      Sets the name for the current builder.
      Parameters:
      name - The name to be set. Must not be empty.
      Returns:
      This builder instance for method chaining.
    • withDescription

      public AgentFunctionCallbackWrapper.Builder<I,O> withDescription(String description)
      Sets the description for the builder.
      Parameters:
      description - the description to set
      Returns:
      the current instance of Builder, allowing method chaining
    • withInputType

      public AgentFunctionCallbackWrapper.Builder<I,O> withInputType(Class<I> inputType)
      Sets the input type for this builder.
      Parameters:
      inputType - the class representing the input type
      Returns:
      the builder instance for method chaining
    • withResponseConverter

      public AgentFunctionCallbackWrapper.Builder<I,O> withResponseConverter(Function<O,String> responseConverter)
      Sets the response converter for the builder.
      Parameters:
      responseConverter - a function that converts the response object to a string
      Returns:
      this builder instance for method chaining
      Throws:
      IllegalArgumentException - if the responseConverter is null
    • withInputTypeSchema

      public AgentFunctionCallbackWrapper.Builder<I,O> withInputTypeSchema(String inputTypeSchema)
      Sets the input type schema for the builder.
      Parameters:
      inputTypeSchema - the input type schema to set, cannot be empty
      Returns:
      a reference to this Builder instance
      Throws:
      IllegalArgumentException - if inputTypeSchema is empty
    • withObjectMapper

      public AgentFunctionCallbackWrapper.Builder<I,O> withObjectMapper(com.fasterxml.jackson.databind.ObjectMapper objectMapper)
      Sets the objectMapper for the builder.
      Parameters:
      objectMapper - the ObjectMapper to use
      Returns:
      this builder instance
    • withSchemaType

      public AgentFunctionCallbackWrapper.Builder<I,O> withSchemaType(org.springframework.ai.model.function.FunctionCallbackContext.SchemaType schemaType)
      Sets the schema type for the builder.
      Parameters:
      schemaType - the schema type to set, must not be null
      Returns:
      this builder instance for method chaining
    • build

      public AgentFunctionCallbackWrapper<I,O> build()
      Builds an instance of AgentFunctionCallbackWrapper.

      Asserts that the name and description are not empty, and that the responseConverter and objectMapper are not null. If the inputType is null, it resolves the input type based on the function or biFunction provided. If the inputTypeSchema is null, it generates a JSON schema for the input type based on whether the schemaType is OPEN_API_SCHEMA. It creates a finalBiFunction using the provided biFunction or falls back to using the function with a default implementation.

      Returns:
      a new instance of AgentFunctionCallbackWrapper