java.lang.Object
com.agentforge4j.llm.DefaultLlmClientResolver
- All Implemented Interfaces:
LlmClientResolver
Default
LlmClientResolver: builds an immutable map of provider id to LlmClient.
discover(ObjectMapper, Collection, LlmSecretResolver) loads LlmClientFactory implementations via
JPMS ServiceLoader, pairs each with a matching LlmClientConfiguration by provider id
(case-insensitive), and constructs clients. resolve(String) looks up a client or fails with
IllegalArgumentException.
-
Constructor Summary
ConstructorsConstructorDescriptionDefaultLlmClientResolver(Collection<LlmClient> clients) Creates a resolver backed by an explicit non-empty client list (typically used in tests). -
Method Summary
Modifier and TypeMethodDescriptionstatic DefaultLlmClientResolverdiscover(com.fasterxml.jackson.databind.ObjectMapper objectMapper, Collection<LlmClientConfiguration> configs, LlmSecretResolver secretResolver) DiscoversLlmClientFactoryimplementations and builds clients for each configuration that matches a factory's provider id, resolving each provider's credential reference viasecretResolver.booleanisProviderAvailable(String provider) Returns the client for the given provider id (matched case-insensitively by typical implementations).
-
Constructor Details
-
DefaultLlmClientResolver
Creates a resolver backed by an explicit non-empty client list (typically used in tests).- Parameters:
clients- non-empty, no null elements, uniqueLlmClient.getProviderName()per entry- Throws:
IllegalArgumentException- if validation fails
-
-
Method Details
-
discover
public static DefaultLlmClientResolver discover(com.fasterxml.jackson.databind.ObjectMapper objectMapper, Collection<LlmClientConfiguration> configs, LlmSecretResolver secretResolver) DiscoversLlmClientFactoryimplementations and builds clients for each configuration that matches a factory's provider id, resolving each provider's credential reference viasecretResolver. Each client is constructed throughLlmClientFactory.create(LlmClientFactoryContext).Factories without a matching configuration are skipped (warning logged). At least one client must be created or
IllegalStateExceptionis thrown.- Parameters:
objectMapper- passed to each factoryconfigs- one or moreLlmClientConfigurationentries (duplicate provider ids fail)secretResolver- resolver for credential references; must not benull- Returns:
- resolver over all constructed clients
- Throws:
IllegalStateException- when no client could be built (missing provider modules or configs)
-
resolve
Returns the client for the given provider id (matched case-insensitively by typical implementations).- Specified by:
resolvein interfaceLlmClientResolver- Parameters:
provider- provider id such as"openai"or"ollama"- Returns:
- client for that provider
-
isProviderAvailable
- Specified by:
isProviderAvailablein interfaceLlmClientResolver
-
listAvailableClients
- Specified by:
listAvailableClientsin interfaceLlmClientResolver
-