Class FunctionToolsLoader
FunctionTools implementations using Java's
ServiceLoader mechanism.
This class acts as the entry point for registering a curated set of local
capabilities (such as file access, command execution, and HTTP retrieval)
with a ProcessProvider provider. Implementations are discovered from the
classpath (typically via META-INF/services provider configuration)
and then applied to the provider in discovery order.
Usage Example
ProcessProvider provider = ...; Class<?> appClass = ...; FunctionToolsLoader loader = new FunctionToolsLoader(); loader.applyTools(provider, appClass);
The loader maintains a list of discovered FunctionTools instances and
applies them to the provider, filtered by application class compatibility.
- Author:
- Viktor Tovstyi
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final List<FunctionTools> List of discoveredFunctionToolsinstances, loaded from the classpath.private static final org.slf4j.LoggerLogger for debug output during tool discovery and application. -
Constructor Summary
ConstructorsConstructorDescriptionConstructs a newFunctionToolsLoaderand discovers availableFunctionToolsimplementations usingServiceLoader. -
Method Summary
Modifier and TypeMethodDescriptionvoidapplyTools(ProcessProvider provider, String[] tools, Class<?> appClass) Applies all discoveredFunctionToolsinstallers to the given provider, filtered by application class compatibility.private booleanisSupportedFor(Class<?> appClass, Class<? extends FunctionTools> functionToolsClass) Checks whether the givenFunctionToolsimplementation supports assignment to the specified application class.private void
-
Field Details
-
logger
private static final org.slf4j.Logger loggerLogger for debug output during tool discovery and application. -
functionTools
List of discoveredFunctionToolsinstances, loaded from the classpath.
-
-
Constructor Details
-
FunctionToolsLoader
public FunctionToolsLoader()Constructs a newFunctionToolsLoaderand discovers availableFunctionToolsimplementations usingServiceLoader.Each discovered tool is added to the internal list and logged for debugging.
-
-
Method Details
-
loadLegacyServiceDescriptor
private void loadLegacyServiceDescriptor() -
applyTools
Applies all discoveredFunctionToolsinstallers to the given provider, filtered by application class compatibility.For each compatible tool, both tool functions and prompts are registered with the provider.
- Parameters:
provider- theProcessProviderprovider instance to augment with tools, prompts, and resourcestools- names of tools that the provider should register; provider-specific filtering is applied byProcessProvider.addTools(FunctionTools, String[])appClass- the application class requesting tool assignment; only tools compatible with this class are applied
-
isSupportedFor
private boolean isSupportedFor(Class<?> appClass, Class<? extends FunctionTools> functionToolsClass) Checks whether the givenFunctionToolsimplementation supports assignment to the specified application class.If the
SupportedForannotation is present, only classes listed in its value are considered compatible. If the annotation is absent, compatibility is assumed.- Parameters:
appClass- the application class requesting tool assignmentfunctionToolsClass- the FunctionTools implementation class- Returns:
trueif the tool is compatible with the application class,falseotherwise
-