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>
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 Summary
-
Method Summary
Modifier and TypeMethodDescriptionbuild()
Builds an instance ofAgentFunctionCallbackWrapper
.withDescription
(String description) Sets the description for the builder.withInputType
(Class<I> inputType) Sets the input type for this builder.withInputTypeSchema
(String inputTypeSchema) Sets the input type schema for the builder.Sets the name for the current builder.withObjectMapper
(com.fasterxml.jackson.databind.ObjectMapper objectMapper) Sets the objectMapper for the builder.withResponseConverter
(Function<O, String> responseConverter) Sets the response converter for the builder.withSchemaType
(org.springframework.ai.model.function.FunctionCallbackContext.SchemaType schemaType) Sets the schema type for the builder.
-
Constructor Details
-
Builder
Initializes a new instance of the Builder class with the specified BiFunction.- Parameters:
biFunction
- TheBiFunction
that the builder will use to handle operations, which cannot be null.
-
Builder
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
Sets the description for the builder.- Parameters:
description
- the description to set- Returns:
- the current instance of Builder, allowing method chaining
-
withInputType
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 theresponseConverter
is null
-
withInputTypeSchema
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
Builds an instance ofAgentFunctionCallbackWrapper
.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
-