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");
-
Nested Class Summary
Nested ClassesModifier and TypeInterfaceDescriptionstatic final recordParameter definition for a tool.static final recordDefinition of a tool available to agents.static enumType of tool. -
Method Summary
Modifier and TypeMethodDescriptionvoidclear()Clears all registered tools.find(Predicate<ToolRegistry.ToolRegistryEntry> predicate) Finds tools matching a predicate.Finds tools by tag.Gets a tool by name.getAll()Returns all registered tools.static ToolRegistryinMemory()Returns an in-memory tool registry.static StringReturns the canonical key for a tool name.voidRegisters a tool in the registry.Searches tools by name or description.intsize()Returns the number of registered tools.booleanunregister(String toolName) Unregisters a tool from the registry.
-
Method Details
-
register
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
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
List<ToolRegistry.ToolRegistryEntry> 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
Returns an in-memory tool registry.- Returns:
- in-memory registry instance
-
normalize
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- iftoolNameisnull
-