Package com.tnsai.spi

Interface ToolRegistry


public interface ToolRegistry
Registry for managing agent tools.

This interface provides a unified API for tool registration, discovery, and invocation. Implementations can use in-memory storage, remote registries, or distributed caches.

Features

  • Tool registration and discovery
  • Tag-based filtering
  • Dynamic tool loading
  • Tool metadata management

Usage


 ToolRegistry registry = ToolRegistry.inMemory();

 // Register a tool
 registry.register(ToolRegistryEntry.builder()
     .name("calculator")
     .description("Performs arithmetic calculations")
     .parameter("expression", "string", "The mathematical expression")
     .tags("math", "utility")
     .build());

 // Find tools by tag
 List<ToolRegistryEntry> mathTools = registry.findByTag("math");

 // Search tools
 List<ToolRegistryEntry> results = registry.search("calculate");
 
  • Method Details

    • register

      void register(ToolRegistry.ToolRegistryEntry tool)
      Registers a tool in the registry.
      Parameters:
      tool - the tool definition to register
      Throws:
      IllegalArgumentException - if another display name already owns the same normalized key
    • unregister

      boolean unregister(String toolName)
      Unregisters a tool from the registry.
      Parameters:
      toolName - the name of the tool to unregister
      Returns:
      true if the tool was unregistered
    • get

      Gets a tool by name.
      Parameters:
      toolName - the tool name
      Returns:
      optional containing the tool, or empty if not found
    • getAll

      Returns all registered tools.
      Returns:
      list of all tools
    • findByTag

      Finds tools by tag.
      Parameters:
      tag - the tag to search for
      Returns:
      list of matching tools
    • find

      Finds tools matching a predicate.
      Parameters:
      predicate - the filter predicate
      Returns:
      list of matching tools
    • search

      Searches tools by name or description.
      Parameters:
      query - the search query
      Returns:
      list of matching tools
    • size

      int size()
      Returns the number of registered tools.
      Returns:
      tool count
    • clear

      void clear()
      Clears all registered tools.
    • inMemory

      static ToolRegistry inMemory()
      Returns an in-memory tool registry.
      Returns:
      in-memory registry instance
    • normalize

      static String normalize(String toolName)
      Returns the canonical key for a tool name.

      Normalization trims surrounding whitespace and folds case with Locale.ROOT. It intentionally performs no language-specific or accent-specific mapping, so distinct Unicode names remain distinct.

      Parameters:
      toolName - tool name to normalize
      Returns:
      canonical registry key
      Throws:
      NullPointerException - if toolName is null