Class FunctionToolCallback<I,O>
java.lang.Object
org.springframework.ai.tool.function.FunctionToolCallback<I,O>
- All Implemented Interfaces:
FunctionCallback
,ToolCallback
A
ToolCallback
implementation to invoke functions as tools.- Since:
- 1.0.0
- Author:
- Thomas Vitale
-
Nested Class Summary
Nested classes/interfaces inherited from interface org.springframework.ai.model.function.FunctionCallback
FunctionCallback.CommonCallbackInvokingSpec<B extends FunctionCallback.CommonCallbackInvokingSpec<B>>, FunctionCallback.FunctionInvokingSpec<I,
O>, FunctionCallback.MethodInvokingSpec, FunctionCallback.SchemaType -
Constructor Summary
ConstructorDescriptionFunctionToolCallback
(ToolDefinition toolDefinition, ToolMetadata toolMetadata, Type toolInputType, BiFunction<I, ToolContext, O> toolFunction, ToolCallResultConverter toolCallResultConverter) -
Method Summary
Modifier and TypeMethodDescriptionstatic <I,
O> FunctionToolCallback.Builder<I, O> builder
(String name, BiFunction<I, ToolContext, O> function) Build aFunctionToolCallback
from aBiFunction
.static <I> FunctionToolCallback.Builder<I,
Void> Build aFunctionToolCallback
from aConsumer
.static <I,
O> FunctionToolCallback.Builder<I, O> Build aFunctionToolCallback
from aFunction
.static <O> FunctionToolCallback.Builder<Void,
O> Build aFunctionToolCallback
from aSupplier
.Called when a model detects and triggers a function call.call
(String toolInput, ToolContext toolContext) Called when a model detects and triggers a function call.Definition used by the AI model to determine when and how to call the tool.Metadata providing additional information on how to handle the tool.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface org.springframework.ai.tool.ToolCallback
getDescription, getInputTypeSchema, getName
-
Constructor Details
-
FunctionToolCallback
public FunctionToolCallback(ToolDefinition toolDefinition, @Nullable ToolMetadata toolMetadata, Type toolInputType, BiFunction<I, ToolContext, O> toolFunction, @Nullable ToolCallResultConverter toolCallResultConverter)
-
-
Method Details
-
getToolDefinition
Description copied from interface:ToolCallback
Definition used by the AI model to determine when and how to call the tool.- Specified by:
getToolDefinition
in interfaceToolCallback
-
getToolMetadata
Description copied from interface:ToolCallback
Metadata providing additional information on how to handle the tool.- Specified by:
getToolMetadata
in interfaceToolCallback
-
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:
toolInput
- 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:
toolInput
- 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.
-
builder
public static <I,O> FunctionToolCallback.Builder<I,O> builder(String name, BiFunction<I, ToolContext, O> function) Build aFunctionToolCallback
from aBiFunction
. -
builder
Build aFunctionToolCallback
from aFunction
. -
builder
Build aFunctionToolCallback
from aSupplier
. -
builder
Build aFunctionToolCallback
from aConsumer
.
-