Class AiToolRegistryImpl

java.lang.Object
io.jmix.aitools.tool.impl.AiToolRegistryImpl
All Implemented Interfaces:
AiToolRegistry, org.springframework.beans.factory.InitializingBean

@Component("aitls_AiToolRegistryImpl") public class AiToolRegistryImpl extends Object implements AiToolRegistry, org.springframework.beans.factory.InitializingBean
Default AiToolRegistry. On startup:
  • Field Details

  • Constructor Details

    • AiToolRegistryImpl

      public AiToolRegistryImpl()
  • Method Details

    • afterPropertiesSet

      public void afterPropertiesSet()
      Specified by:
      afterPropertiesSet in interface org.springframework.beans.factory.InitializingBean
    • refresh

      protected void refresh()
    • getAll

      public List<ResolvedAiTool> getAll()
      Description copied from interface: AiToolRegistry
      Returns all resolved tools in registration order.
      Specified by:
      getAll in interface AiToolRegistry
      Returns:
      all resolved tools
    • findByName

      public Optional<ResolvedAiTool> findByName(String name)
      Description copied from interface: AiToolRegistry
      Returns a resolved tool by its name (the value passed to @Tool(name=...) or derived from the method name), or empty when no such tool is registered.
      Specified by:
      findByName in interface AiToolRegistry
      Parameters:
      name - tool name to look up
      Returns:
      the matching tool, or empty when none is registered under that name
    • findByMarker

      public List<ResolvedAiTool> findByMarker(Class<? extends JmixAiTool> marker)
      Description copied from interface: AiToolRegistry
      Returns all resolved tools produced by beans implementing the given marker sub-interface of JmixAiTool (e.g. DataLoadAiTool.class).
      Specified by:
      findByMarker in interface AiToolRegistry
      Parameters:
      marker - marker sub-interface to filter by
      Returns:
      resolved tools whose source bean implements the marker
    • getAllCallbacks

      public List<org.springframework.ai.tool.ToolCallback> getAllCallbacks()
      Description copied from interface: AiToolRegistry
      Shortcut returning ToolCallbacks of all resolved tools in the same order as AiToolRegistry.getAll().
      Specified by:
      getAllCallbacks in interface AiToolRegistry
      Returns:
      callbacks of all resolved tools
    • deduplicate

      protected List<JmixAiTool> deduplicate(List<JmixAiTool> tools)
      Removes references to the same bean instance appearing multiple times in the autowired list (this can happen when a single bean is exposed via several JmixAiTool sub-interfaces and Spring resolves the injection through each of them). Deduplication is based on object identity, so multiple distinct beans of the same class are preserved.
      Parameters:
      tools - autowired tool beans, possibly containing the same instance more than once
      Returns:
      tools with duplicate instances removed, preserving first-seen order
    • collectCandidates

      protected void collectCandidates(JmixAiTool tool, Map<String,List<AiToolRegistryImpl.ToolCandidate>> regulars, Map<String,List<AiToolRegistryImpl.ToolCandidate>> overrideBuckets)
    • resolveWinner

      protected AiToolRegistryImpl.ToolCandidate resolveWinner(String name, List<AiToolRegistryImpl.ToolCandidate> candidates)
    • unionMarkers

      protected Set<Class<? extends JmixAiTool>> unionMarkers(List<AiToolRegistryImpl.ToolCandidate> candidates)
      Union of marker sub-interfaces from every candidate in the bucket. Ensures that an override does not silently drop a tool from a marker-specific view that the original implementation participated in.
      Parameters:
      candidates - all candidates grouped under the same tool name
      Returns:
      union of marker sub-interfaces across the candidates' source beans
    • buildResolvedTool

      protected ResolvedAiTool buildResolvedTool(String registryKey, AiToolRegistryImpl.ToolCandidate candidate, Set<Class<? extends JmixAiTool>> markers)
      Builds the resolved tool entry. The registryKey is the bucket name under which all candidates were grouped: it is the override target when the winner is an override resolved against an existing original, or the winner's own @Tool name otherwise. Either way, this is the name the LLM will see, so we use it both as the registry name and as the underlying ToolDefinition name.

      The metadata (description and other attributes) comes from the winner's own @Tool annotation via AiToolDescriptor, which means an override author can change the description while keeping the tool name stable.

      Parameters:
      registryKey - the name under which the tool is registered and exposed to the LLM
      candidate - the winning candidate the entry is built from
      markers - marker sub-interfaces this tool participates in
      Returns:
      the resolved tool entry
    • collectMarkers

      protected Set<Class<? extends JmixAiTool>> collectMarkers(JmixAiTool tool)
    • collectMarkersRecursive

      protected void collectMarkersRecursive(@Nullable Class<?> type, Set<Class<? extends JmixAiTool>> acc)
    • isToolAnnotatedMethod

      protected boolean isToolAnnotatedMethod(Method method)
    • readOverrideValue

      protected @Nullable String readOverrideValue(Method method)
    • getTargetClass

      protected Class<?> getTargetClass(JmixAiTool tool)