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

public class JavaObjectToolkit extends AbstractToolkit<JavaMethodTool> implements 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 Details

    • toolkitClassName

      private final String toolkitClassName
      The fully qualified name of the toolkit class. This is the "Ground Truth" used to restore the instance after deserialization.
    • toolkitInstance

      private Object toolkitInstance
      The singleton instance of the tool class. Non-final to support circular reference resolution during Kryo deserialization.
    • tools

      private List<JavaMethodTool> tools
      A list of all declared methods (tools) for this toolkit. Non-final to support robust deserialization and hot-reloading.
  • Constructor Details

    • JavaObjectToolkit

      public JavaObjectToolkit(ToolManager toolManager, Class<?> toolClass) throws Exception
      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:
      initialize in class AbstractToolkit<JavaMethodTool>
    • getAllTools

      public List<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:
      getAllTools in class AbstractToolkit<JavaMethodTool>
      Returns:
      The complete list of tools.
    • getContextProvider

      public ContextProvider getContextProvider()
      Description copied from class: AbstractToolkit
      If this toolkit provides additional context.
      Specified by:
      getContextProvider in class AbstractToolkit<JavaMethodTool>
      Returns:
      the context provider if any.
    • rebind

      public void rebind()
      Description copied from interface: Rebindable
      Re-initializes the object's state after deserialization.
      Specified by:
      rebind in interface Rebindable
    • getAllAnnotatedMethods

      public static List<Method> getAllAnnotatedMethods(Class<?> clazz)
      Recursively finds all methods annotated with AgiTool in 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:
      postActivate in class AbstractToolkit<JavaMethodTool>