Class AbstractTool<P extends AbstractToolParameter, C extends AbstractToolCall>
java.lang.Object
uno.anahata.asi.agi.event.BasicPropertyChangeSource
uno.anahata.asi.agi.tool.spi.AbstractTool<P,C>
- Type Parameters:
P- The specific subclass of AbstractToolParameter this tool uses.C- The specific subclass of AbstractToolCall this tool creates.
- All Implemented Interfaces:
PropertyChangeSource, Rebindable
- Direct Known Subclasses:
BadTool, JavaMethodTool
public abstract class AbstractTool<P extends AbstractToolParameter, C extends AbstractToolCall>
extends BasicPropertyChangeSource
The abstract base class for a tool, now generic on its Parameter and Call
types.
- Author:
- anahata-gemini-pro-2.5
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected StringA detailed description of what the tool does.private intThe maximum depth this tool call should be retained in the context.protected final @NonNull StringThe fully qualified name of the tool, e.g., "LocalFiles.readFile".A rich, ordered list of the tool's parameters.protected ToolPermissionThe user's configured preference for this tool, determining its execution behavior.protected StringA pre-generated, language-agnostic JSON schema for the tool's return type.private Integerprotected AbstractToolkitA reference to the parent toolkit that owns this tool.Fields inherited from class BasicPropertyChangeSource
propertyChangeSupport -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedAbstractTool(@NonNull String name) Constructs a new AbstractTool with the given name. -
Method Summary
Modifier and TypeMethodDescriptionabstract CcreateCall(AbstractModelMessage message, String id, Map<String, Object> args) Factory method to create a tool-specific call object from raw model data.intThe effective maximum depth.abstract TypeTemplate method hook for subclasses to provide their specific Response type.Convenience method to resolve the currently selected model from the parent session.intCalculates the total token count of this tool on-the-fly using the active model.voidResets the cached token count, forcing a recalculation on the next query.voidsetPermission(ToolPermission permission) Sets the user's execution permission preference for this tool and fires a property change event.Methods inherited from class BasicPropertyChangeSource
addPropertyChangeListener, addPropertyChangeListener, rebind, removePropertyChangeListener, removePropertyChangeListenerMethods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface PropertyChangeSource
getPropertyChangeSupport
-
Field Details
-
tokenCount
-
name
The fully qualified name of the tool, e.g., "LocalFiles.readFile". This is immutable. -
description
A detailed description of what the tool does. -
toolkit
A reference to the parent toolkit that owns this tool. Can be null for standalone tools. -
permission
The user's configured preference for this tool, determining its execution behavior. -
maxDepth
private int maxDepthThe maximum depth this tool call should be retained in the context. -
parameters
A rich, ordered list of the tool's parameters. -
responseJsonSchema
A pre-generated, language-agnostic JSON schema for the tool's return type. Can be null for void methods.
-
-
Constructor Details
-
AbstractTool
Constructs a new AbstractTool with the given name.- Parameters:
name- The tool's name.
-
-
Method Details
-
setPermission
Sets the user's execution permission preference for this tool and fires a property change event.- Parameters:
permission- The new permission level to apply.
-
getEffectiveMaxDepth
public int getEffectiveMaxDepth()The effective maximum depth.- Returns:
- the effective max depth.
-
getSelectedModel
Convenience method to resolve the currently selected model from the parent session.- Returns:
- The active AbstractModel, or null if no session is active or no model is selected.
-
createCall
Factory method to create a tool-specific call object from raw model data.- Parameters:
message- the model message the call will belong to.id- The call ID.args- The raw arguments from the model.- Returns:
- A new tool call instance.
-
getResponseType
Template method hook for subclasses to provide their specific Response type.- Returns:
- The reflection Type of the corresponding AbstractToolResponse subclass.
-
getTokenCount
public int getTokenCount()Calculates the total token count of this tool on-the-fly using the active model.This method prioritizes counting the exact, provider-specific JSON declaration payload emitted by
AbstractModel.getToolDeclarationJson(AbstractTool, RequestConfig)to ensure 100% billing-identical token metrics in the context window. It falls back to a naive summation of descriptions and schemas if the tool is not yet bound to an active session context.This value is cached to prevent redundant calculations during Context Window transitions.
- Returns:
- The precise token count representing the tool's declaration overhead.
-
resetTokenCount
public void resetTokenCount()Resets the cached token count, forcing a recalculation on the next query.
-

