Class ServiceLoaderToolProviderFactory

java.lang.Object
com.agentforge4j.bootstrap.ServiceLoaderToolProviderFactory
All Implemented Interfaces:
ToolProviderFactory

public final class ServiceLoaderToolProviderFactory extends Object implements ToolProviderFactory
ToolProviderFactory that routes each IntegrationDefinition to the IntegrationToolProviderFactory contribution matching its IntegrationType.

discover(ObjectMapper, SecretResolver, HttpEgressGuard) loads contributions via ServiceLoader (mirroring DefaultLlmClientResolver's LlmClientFactory discovery), so provider modules such as agentforge4j-mcp plug in by being on the classpath — this module declares no concrete provider dependency. Two contributions claiming the same type fail construction; a definition whose type has no contribution fails create(com.agentforge4j.core.spi.integration.IntegrationDefinition) naming the type and the missing module.

  • Constructor Details

    • ServiceLoaderToolProviderFactory

      public ServiceLoaderToolProviderFactory(Collection<IntegrationToolProviderFactory> contributions, com.fasterxml.jackson.databind.ObjectMapper objectMapper, SecretResolver secretResolver, HttpEgressGuard egressGuard)
      Creates an aggregator over explicit contributions (typically used in tests).
      Parameters:
      contributions - no null elements, at most one contribution per IntegrationType
      objectMapper - the single shared Jackson mapper threaded into each contribution; must not be null
      secretResolver - the secret-reference resolver threaded into each contribution; must not be null
      egressGuard - the outbound-egress guard threaded into each contribution; must not be null
      Throws:
      IllegalStateException - if two contributions claim the same type
  • Method Details

    • discover

      public static ServiceLoaderToolProviderFactory discover(com.fasterxml.jackson.databind.ObjectMapper objectMapper, SecretResolver secretResolver, HttpEgressGuard egressGuard)
      Discovers IntegrationToolProviderFactory contributions on the classpath.

      An empty result is not an error: the aggregator only fails when asked to realise a definition whose type has no contribution.

      Parameters:
      objectMapper - the single shared Jackson mapper threaded into each contribution; must not be null
      secretResolver - the secret-reference resolver threaded into each contribution; must not be null
      egressGuard - the outbound-egress guard threaded into each contribution; must not be null
      Returns:
      aggregator over all discovered contributions
    • create

      public ToolProvider create(IntegrationDefinition definition)
      Description copied from interface: ToolProviderFactory
      Builds the tool provider for an integration.
      Specified by:
      create in interface ToolProviderFactory
      Parameters:
      definition - the integration to realise
      Returns:
      a tool provider exposing the integration's capabilities