Interface AgentToolRegistry


public interface AgentToolRegistry
Registry for managing agent tools from plugins.

Plugins use this registry to register their tools that the AI agent can use. The registry handles tool discovery, validation, and lifecycle management.

Example usage in a plugin:

@Plugin(name = "MyPlugin", version = "1.0.0", author = "Author")
public class MyPlugin {

    @OnEnable
    public void onEnable(PluginContext context) {
        AgentToolRegistry registry = context.getAgentToolRegistry();

        // Register a tool provider (class with @AgentTool methods)
        registry.registerProvider("my-plugin", new MyTools());

        // Or register individual tool executors
        registry.registerTool("my-plugin", ToolDefinition.builder()
            .name("hello")
            .description("Say hello to someone")
            .executor((ctx, params) -> "Hello, " + params.get("name") + "!")
            .build());
    }

    @OnDisable
    public void onDisable(PluginContext context) {
        // Unregister all tools for this plugin
        context.getAgentToolRegistry().unregisterAll("my-plugin");
    }
}

  • Method Details

    • registerProvider

      int registerProvider(String pluginId, AgentToolProvider provider)
      Register a tool provider with annotated @AgentTool methods. The registry will scan the provider for @AgentTool annotations and register each method as a tool.
      Parameters:
      pluginId - the plugin identifier (for tracking ownership)
      provider - the tool provider instance
      Returns:
      number of tools registered
    • registerTool

      boolean registerTool(String pluginId, ToolDefinition definition)
      Register a single tool with a custom executor.
      Parameters:
      pluginId - the plugin identifier
      definition - the tool definition
      Returns:
      true if registered successfully
    • unregisterTool

      boolean unregisterTool(String toolName)
      Unregister a specific tool.
      Parameters:
      toolName - the tool name
      Returns:
      true if the tool was found and unregistered
    • unregisterAll

      int unregisterAll(String pluginId)
      Unregister all tools from a plugin.
      Parameters:
      pluginId - the plugin identifier
      Returns:
      number of tools unregistered
    • getTool

      Optional<ToolDefinition> getTool(String toolName)
      Get a tool definition by name.
      Parameters:
      toolName - the tool name
      Returns:
      the tool definition, or empty if not found
    • getAllTools

      Collection<ToolDefinition> getAllTools()
      Get all registered tools.
      Returns:
      collection of all tool definitions
    • getToolsByPlugin

      Collection<ToolDefinition> getToolsByPlugin(String pluginId)
      Get all tools registered by a specific plugin.
      Parameters:
      pluginId - the plugin identifier
      Returns:
      collection of tool definitions from that plugin
    • searchTools

      Collection<ToolDefinition> searchTools(String keyword)
      Search for tools by keyword.
      Parameters:
      keyword - the keyword to search
      Returns:
      matching tool definitions
    • hasTool

      boolean hasTool(String toolName)
      Check if a tool with the given name exists.
      Parameters:
      toolName - the tool name
      Returns:
      true if exists
    • getToolCount

      int getToolCount()
      Get the number of registered tools.
      Returns:
      total tool count
    • executeTool

      ToolResult executeTool(String toolName, AgentToolContext context, Map<String,Object> parameters)
      Execute a tool by name with the given context and parameters.
      Parameters:
      toolName - the tool name
      context - the execution context
      parameters - the tool parameters
      Returns:
      the tool execution result