Class AgentFunctionCallbackWrapper<I,O>
java.lang.Object
org.bsc.spring.agentexecutor.function.AgentFunctionCallbackWrapper<I,O>
- Type Parameters:
I
- the type of the inputO
- 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
Modifier and TypeClassDescriptionstatic class
A class that serves as a builder for creating instances ofAgentFunctionCallbackWrapper
. -
Constructor Summary
ModifierConstructorDescriptionprotected
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 TypeMethodDescriptionApplies a function to the given input and context.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.static <I,
O> AgentFunctionCallbackWrapper.Builder<I, O> Creates a builder for anAgentFunctionCallbackWrapper
.Calls a specified function with the provided arguments.Executes a given function with the provided input and tool context.convertResponse
(org.springframework.ai.chat.messages.ToolResponseMessage.ToolResponse toolResponse) Converts aToolResponseMessage.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 nulldescription
- a description of the agent function callback wrapper, must not be nullinputTypeSchema
- the schema of the input type of the agent function, must not be nullinputType
- the input class type of the agent function, must not be nullresponseConverter
- a function to convert the response object to a string, must not be nullobjectMapper
- an instance of ObjectMapper for JSON processing, must not be nullfunction
- 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 aToolResponseMessage.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
Executes a given function with the provided input and tool context.- Specified by:
call
in interfaceorg.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
Calls a specified function with the provided arguments.- Specified by:
call
in interfaceorg.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
Applies a function to the given input and context.- Specified by:
apply
in interfaceBiFunction<I,
org.springframework.ai.chat.model.ToolContext, O> - Parameters:
input
- the input to applycontext
- 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
Creates a builder for anAgentFunctionCallbackWrapper
. The builder takes aFunction
that defines the mapping from input typeI
to output typeO
.- Type Parameters:
I
- the input type of the functionO
- the output type of the function- Returns:
- a new
Builder
instance that can be used to configure and build anAgentFunctionCallbackWrapper
-