Class ToolManager
java.lang.Object
uno.anahata.ai.tools.ToolManager
Manages the registration, identification, and execution of local tools (functions).
This class uses reflection to scan provided classes for methods annotated with
AIToolMethod. It converts these methods into FunctionDeclarations
for the Gemini API and handles the invocation of these methods when the model
requests a tool call.
It also manages tool call IDs, user confirmation workflows via FunctionPrompter,
and asynchronous tool execution.
-
Constructor Summary
ConstructorsConstructorDescriptionToolManager(Chat chat, FunctionPrompter prompter) Constructs a new ToolManager for the given Chat instance and prompter. -
Method Summary
Modifier and TypeMethodDescriptionGets the set of tool names that are configured to be always approved.getContextBehavior(String toolName) Gets the context behavior (EPHEMERAL or STATEFUL_REPLACE) for a specific tool.Gets a list of information about all registered functions.com.google.genai.types.ToolGets theToolobject containing all registered function declarations.Gets the set of tool names that are configured to be never approved.com.google.genai.types.ToolConfigGets the tool configuration for API calls.getToolMethod(String toolName) Gets the Java Method associated with a specific tool name.processFunctionCalls(ChatMessage modelResponseMessage) Processes a list of function calls proposed by the model.voidresetIdCounter(int value) Resets the tool call ID counter to a specific value.
-
Constructor Details
-
ToolManager
Constructs a new ToolManager for the given Chat instance and prompter.- Parameters:
chat- The Chat instance.prompter- The prompter for user confirmation.
-
-
Method Details
-
resetIdCounter
public void resetIdCounter(int value) Resets the tool call ID counter to a specific value.- Parameters:
value- The new starting value.
-
processFunctionCalls
Processes a list of function calls proposed by the model.This method assigns IDs to the calls, prompts the user for confirmation (if necessary), and executes the approved calls.
- Parameters:
modelResponseMessage- The message from the model containing the function calls.- Returns:
- A
FunctionProcessingResultcontaining the outcomes and execution results.
-
getFunctionTool
public com.google.genai.types.Tool getFunctionTool()Gets theToolobject containing all registered function declarations.- Returns:
- The Tool object.
-
getFunctionInfos
Gets a list of information about all registered functions.- Returns:
- An unmodifiable list of FunctionInfo objects.
-
getToolConfig
public com.google.genai.types.ToolConfig getToolConfig()Gets the tool configuration for API calls.- Returns:
- The ToolConfig object.
-
getContextBehavior
Gets the context behavior (EPHEMERAL or STATEFUL_REPLACE) for a specific tool.- Parameters:
toolName- The name of the tool.- Returns:
- The ContextBehavior.
-
getToolMethod
-
getAlwaysApproveFunctions
-
getNeverApproveFunctions
-
