Class MethodInvokingFunctionCallback
java.lang.Object
org.springframework.ai.model.function.MethodInvokingFunctionCallback
- All Implemented Interfaces:
FunctionCallback
A
FunctionCallback
that invokes methods on objects via reflection, supporting:
- Static and non-static methods
- Any number of parameters (including none)
- Any parameter/return types (primitives, objects, collections)
- Special handling for
ToolContext
parameters
- Since:
- 1.0.0
- Author:
- Christian Tzolov
-
Nested Class Summary
Nested classes/interfaces inherited from interface org.springframework.ai.model.function.FunctionCallback
FunctionCallback.Builder, FunctionCallback.FunctionInvokingSpec<I,
O>, FunctionCallback.MethodInvokingSpec -
Method Summary
Modifier and TypeMethodDescriptionCalled when a model detects and triggers a function call.call
(String functionInput, ToolContext toolContext) Called when a model detects and triggers a function call.protected String
generateJsonSchema
(Map<String, Class<?>> namedClasses) Generates a JSON schema from the given named classes.getName()
protected Object
toJavaType
(Object value, Class<?> javaType) Converts the given value to the specified Java type.
-
Method Details
-
getName
- Specified by:
getName
in interfaceFunctionCallback
- Returns:
- Returns the Function name. Unique within the model.
-
getDescription
- Specified by:
getDescription
in interfaceFunctionCallback
- Returns:
- Returns the function description. This description is used by the model do decide if the function should be called or not.
-
getInputTypeSchema
- Specified by:
getInputTypeSchema
in interfaceFunctionCallback
- Returns:
- Returns the JSON schema of the function input type.
-
call
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 interfaceFunctionCallback
- Parameters:
functionInput
- 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
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 interfaceFunctionCallback
- Parameters:
functionInput
- 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.
-
generateJsonSchema
Generates a JSON schema from the given named classes.- Parameters:
namedClasses
- The named classes to generate the schema from.- Returns:
- The generated JSON schema.
-
toJavaType
Converts the given value to the specified Java type.- Parameters:
value
- The value to convert.javaType
- The Java type to convert to.- Returns:
- Returns the converted value.
-