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 Summary
Modifier and TypeMethodDescriptionexecuteTool(String toolName, AgentToolContext context, Map<String, Object> parameters) Execute a tool by name with the given context and parameters.Get all registered tools.Get a tool definition by name.intGet the number of registered tools.getToolsByPlugin(String pluginId) Get all tools registered by a specific plugin.booleanCheck if a tool with the given name exists.intregisterProvider(String pluginId, AgentToolProvider provider) Register a tool provider with annotated @AgentTool methods.booleanregisterTool(String pluginId, ToolDefinition definition) Register a single tool with a custom executor.searchTools(String keyword) Search for tools by keyword.intunregisterAll(String pluginId) Unregister all tools from a plugin.booleanunregisterTool(String toolName) Unregister a specific tool.
-
Method Details
-
registerProvider
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
Register a single tool with a custom executor.- Parameters:
pluginId- the plugin identifierdefinition- the tool definition- Returns:
- true if registered successfully
-
unregisterTool
Unregister a specific tool.- Parameters:
toolName- the tool name- Returns:
- true if the tool was found and unregistered
-
unregisterAll
Unregister all tools from a plugin.- Parameters:
pluginId- the plugin identifier- Returns:
- number of tools unregistered
-
getTool
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
Get all tools registered by a specific plugin.- Parameters:
pluginId- the plugin identifier- Returns:
- collection of tool definitions from that plugin
-
searchTools
Search for tools by keyword.- Parameters:
keyword- the keyword to search- Returns:
- matching tool definitions
-
hasTool
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
Execute a tool by name with the given context and parameters.- Parameters:
toolName- the tool namecontext- the execution contextparameters- the tool parameters- Returns:
- the tool execution result
-