Package org.machanism.machai.ai.tools
Class FunctionToolsLoader
java.lang.Object
org.machanism.machai.ai.tools.FunctionToolsLoader
Discovers and applies
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 Genai 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
Genai 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
-
Constructor Summary
ConstructorsConstructorDescriptionConstructs a newFunctionToolsLoaderand discovers availableFunctionToolsimplementations usingServiceLoader. -
Method Summary
Modifier and TypeMethodDescriptionvoidapplyTools(Genai provider, Class<?> appClass) Applies all discoveredFunctionToolsinstallers to the given provider, filtered by application class compatibility.
-
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
-
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- theGenaiprovider instance to augment with tool functionsappClass- the application class requesting tool assignment; only tools compatible with this class are applied- Throws:
IllegalArgumentException- if a discovered installer cannot be instantiated
-