Class JavaObjectToolkit
java.lang.Object
uno.anahata.asi.agi.tool.spi.AbstractToolkit<JavaMethodTool>
uno.anahata.asi.agi.tool.spi.java.JavaObjectToolkit
- All Implemented Interfaces:
Rebindable
A domain object that parses a Java class via reflection to build a complete,
self-contained Toolkit, including all its tools and parameters.
This class is the cornerstone of the V2's decoupled tool architecture, separating the parsing of tool metadata from the management and execution of tools.
- Author:
- anahata-gemini-pro-2.5
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final StringThe fully qualified name of the toolkit class.private ObjectThe singleton instance of the tool class.private List<JavaMethodTool> A list of all declared methods (tools) for this toolkit.Fields inherited from class AbstractToolkit
defaultMaxDepth, description, enabled, name, toolManagerModifier and TypeFieldDescriptionprotected intThe default maximum depth policy for tools in this toolkit.protected StringA description of the toolkit's purpose.protected booleanWhether the toolkit is currently enabled.protected StringThe name of the toolkit.protected final @NonNull ToolManagerThe parent ToolManager that manages this toolkit. -
Constructor Summary
ConstructorsConstructorDescriptionJavaObjectToolkit(ToolManager toolManager, Class<?> toolClass) Constructs a new JavaObjectToolkit by parsing the given class. -
Method Summary
Modifier and TypeMethodDescriptiongetAllAnnotatedMethods(Class<?> clazz) Recursively finds all methods annotated withAgiToolin the class hierarchy.Gets all tools declared within this toolkit, regardless of their permission status.If this toolkit provides additional context.voidPerforms one-time setup after the toolkit is registered.voidPerforms logic after the session has been activated and bound to the environment.voidrebind()Re-initializes the object's state after deserialization.Methods inherited from class AbstractToolkit
getAllowedTools, getDisabledTools, getTokenCountModifier and TypeMethodDescriptionGets a list of tools that are allowed to be presented to the model.Gets a list of tools that are allowed to be presented to the model.intCalculates the total token count of this toolkit on-the-fly by aggregating the cached token counts of all its contained tools.
-
Field Details
-
toolkitClassName
The fully qualified name of the toolkit class. This is the "Ground Truth" used to restore the instance after deserialization. -
toolkitInstance
The singleton instance of the tool class. Non-final to support circular reference resolution during Kryo deserialization. -
tools
A list of all declared methods (tools) for this toolkit. Non-final to support robust deserialization and hot-reloading.
-
-
Constructor Details
-
JavaObjectToolkit
Constructs a new JavaObjectToolkit by parsing the given class.- Parameters:
toolManager- The parent ToolManager.toolClass- The class to parse.- Throws:
Exception- if the class is not a valid toolkit or instantiation fails.
-
-
Method Details
-
initialize
public void initialize()Performs one-time setup after the toolkit is registered.Implementation details: Delegates to the underlying implementation if it is an
AnahataToolkit.- Overrides:
initializein classAbstractToolkit<JavaMethodTool>
-
getAllTools
Gets all tools declared within this toolkit, regardless of their permission status. Implementation details: Includes a null guard to handle circular dependencies during Kryo deserialization.- Specified by:
getAllToolsin classAbstractToolkit<JavaMethodTool>- Returns:
- The complete list of tools.
-
getContextProvider
Description copied from class:AbstractToolkitIf this toolkit provides additional context.- Specified by:
getContextProviderin classAbstractToolkit<JavaMethodTool>- Returns:
- the context provider if any.
-
rebind
public void rebind()Description copied from interface:RebindableRe-initializes the object's state after deserialization.- Specified by:
rebindin interfaceRebindable
-
getAllAnnotatedMethods
Recursively finds all methods annotated withAgiToolin the class hierarchy.Discovery Pattern: This method traverses up the superclass hierarchy, ensuring that child overrides take precedence over parent declarations.
- Parameters:
clazz- The class to start the search from.- Returns:
- A list of annotated methods.
-
postActivate
public void postActivate()Performs logic after the session has been activated and bound to the environment. Subclasses should override this to perform one-time setup that requires the entire session graph to be available.Implementation details: 1. Warm up tools: triggers restoration of reflection methods and parameters. 2. Delegates to the underlying implementation if it is an
AnahataToolkit.- Overrides:
postActivatein classAbstractToolkit<JavaMethodTool>
-

