Package org.springframework.ai.tool
Class StaticToolCallbackProvider
java.lang.Object
org.springframework.ai.tool.StaticToolCallbackProvider
- All Implemented Interfaces:
ToolCallbackProvider
A simple implementation of
ToolCallbackProvider
that maintains a static array
of FunctionCallback
objects. This provider is immutable after construction and
provides a straightforward way to supply a fixed set of tool callbacks to AI models.
This implementation is thread-safe as it maintains an immutable array of callbacks that is set during construction and cannot be modified afterwards.
Example usage:
FunctionCallback callback1 = new MyFunctionCallback();
FunctionCallback callback2 = new AnotherFunctionCallback();
// Create provider with varargs constructor
ToolCallbackProvider provider1 = new StaticToolCallbackProvider(callback1, callback2);
// Or create provider with List constructor
List<FunctionCallback> callbacks = Arrays.asList(callback1, callback2);
ToolCallbackProvider provider2 = new StaticToolCallbackProvider(callbacks);
- Since:
- 1.0.0
- Author:
- Christian Tzolov
- See Also:
-
Constructor Summary
ConstructorsConstructorDescriptionStaticToolCallbackProvider
(List<? extends FunctionCallback> toolCallbacks) Constructs a new StaticToolCallbackProvider with the specified list of function callbacks.StaticToolCallbackProvider
(FunctionCallback... toolCallbacks) Constructs a new StaticToolCallbackProvider with the specified array of function callbacks. -
Method Summary
Modifier and TypeMethodDescriptionReturns the array of function callbacks held by this provider.
-
Constructor Details
-
StaticToolCallbackProvider
Constructs a new StaticToolCallbackProvider with the specified array of function callbacks.- Parameters:
toolCallbacks
- the array of function callbacks to be provided by this provider. Must not be null, though an empty array is permitted.- Throws:
IllegalArgumentException
- if the toolCallbacks array is null
-
StaticToolCallbackProvider
Constructs a new StaticToolCallbackProvider with the specified list of function callbacks. The list is converted to an array internally.- Parameters:
toolCallbacks
- the list of function callbacks to be provided by this provider. Must not be null and must not contain null elements.- Throws:
IllegalArgumentException
- if the toolCallbacks list is null or contains null elements
-
-
Method Details
-
getToolCallbacks
Returns the array of function callbacks held by this provider.- Specified by:
getToolCallbacks
in interfaceToolCallbackProvider
- Returns:
- an array containing all function callbacks provided during construction. The returned array is a direct reference to the internal array, as the callbacks are expected to be immutable.
-