Class SpiToolRegistry

java.lang.Object
ai.mindconnect.agent.tool.SpiToolRegistry
All Implemented Interfaces:
ToolRegistry

public class SpiToolRegistry extends Object implements ToolRegistry
ToolRegistry that discovers tool sources from the classpath via ServiceLoader. Two SPIs are consulted in order:
  1. ToolFactory — strictly 1:1 with a tool name. Existing built-ins (file/web/document/etc.) register this way and are unchanged.
  2. MultiToolProvider — contributes multiple names from one registration. Used for MCP bundles (e.g. all Gmail sub-tools share one provider and one cached connection), for built-in bundles that want to share resources, and for dynamic sources such as persisted workflows.

Provider names are resolved live: knownToolNames() and resolve(ai.mindconnect.agent.tool.AgentTool, ai.mindconnect.common.Namespace, java.lang.String, java.util.UUID) ask each provider for its current toolNames() on every call, so a provider backed by mutable data (a workflow store, a remote catalog) surfaces additions and removals without a restart. Only the provider set is fixed at construction (ServiceLoader scan).

ToolFactory wins on name collisions to keep behavior stable during the gradual migration from single- to multi-tool registration; between providers, the first registered provider claiming a name wins.

Adding a new tool source is purely additive: implement the SPI, list it in META-INF/services/...ToolFactory or META-INF/services/...MultiToolProvider. No runtime code change.

  • Constructor Details

  • Method Details

    • knownToolNames

      public Set<String> knownToolNames()
      Description copied from interface: ToolRegistry
      Names of all tools known to this registry. Used by admin UIs to render a selection dropdown when configuring an agent's tool list. Order is deterministic (typically registration order). Default: empty for registries that don't enumerate.
      Specified by:
      knownToolNames in interface ToolRegistry
    • toolNamesByGroup

      public Map<String,Set<String>> toolNamesByGroup()
      Description copied from interface: ToolRegistry
      Every resolvable tool name, grouped by its rubric (ToolFactory.group() / MultiToolProvider.group()) — for catalogs and pickers that present tools by category (agent functions, web tools, document tools, …). Groups and names are sorted; like ToolRegistry.knownToolNames() the view reflects the registry's current state. Default: everything under "General".
      Specified by:
      toolNamesByGroup in interface ToolRegistry
    • overridesSchema

      public Map<String,Object> overridesSchema(String toolName)
      Description copied from interface: ToolRegistry
      The config-overrides schema a tool declares (ToolFactory.overridesSchema()), so admin UIs can show which override keys a tool supports. Empty for tools that declare none (e.g. MCP tools, whose knobs are all parameters).
      Specified by:
      overridesSchema in interface ToolRegistry
    • resolve

      public Optional<Tool> resolve(AgentTool agentTool, Namespace namespace, String userId, UUID sessionId)
      Specified by:
      resolve in interface ToolRegistry