Class AgentCardValidator
java.lang.Object
org.a2aproject.sdk.server.AgentCardValidator
Validates AgentCard transport configuration against available transport endpoints.
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionCreates a new thread-safe set for tracking whichAgentCardinstances have already been validated.static AgentCardrequireFirst(@Nullable AgentCard publicCard, @Nullable AgentCard extendedCard) Returns the first non-null agent card, preferring the public card.static AgentCardresolveAndValidateOnce(jakarta.enterprise.inject.Instance<AgentCard> agentCardInstance, Set<AgentCard> validatedCards) Resolves anAgentCardfrom the givenInstanceand validates its transport configuration once per distinct card using the defaultvalidateTransportConfiguration(AgentCard)check.static AgentCardresolveAndValidateOnce(Supplier<AgentCard> agentCardSupplier, Set<AgentCard> validatedCards, Consumer<AgentCard> validator) Obtains anAgentCardfrom the given supplier and applies the provided validator once per distinct card.static AgentCardresolveWithFallback(jakarta.enterprise.inject.Instance<AgentCard> publicCard, @Nullable jakarta.enterprise.inject.Instance<AgentCard> extendedCard, Set<AgentCard> validatedCards) Resolves an agent card from the public instance, falling back to the extended instance if the public one is absent.static AgentCardresolveWithFallback(jakarta.enterprise.inject.Instance<AgentCard> publicCard, @Nullable jakarta.enterprise.inject.Instance<AgentCard> extendedCard, @Nullable AgentCardRouter agentCardRouter, @Nullable String tenant, Set<AgentCard> validatedCards) Convenience overload that uses the defaultvalidateTransportConfiguration(AgentCard)validator.static AgentCardresolveWithFallback(jakarta.enterprise.inject.Instance<AgentCard> publicCard, @Nullable jakarta.enterprise.inject.Instance<AgentCard> extendedCard, @Nullable AgentCardRouter agentCardRouter, @Nullable String tenant, Set<AgentCard> validatedCards, Consumer<AgentCard> validator) Resolves an agent card using one of two resolution strategies depending on whether a tenant-scoped request is being made, and validates using the supplied validator.static voidvalidateTransportConfiguration(AgentCard agentCard) Validates the transport configuration of an AgentCard against available transports found on the classpath.
-
Field Details
-
SKIP_PROPERTY
- See Also:
-
SKIP_JSONRPC_PROPERTY
- See Also:
-
SKIP_GRPC_PROPERTY
- See Also:
-
SKIP_REST_PROPERTY
- See Also:
-
-
Constructor Details
-
AgentCardValidator
public AgentCardValidator()
-
-
Method Details
-
newValidatedCardsSet
Creates a new thread-safe set for tracking whichAgentCardinstances have already been validated. Each distinct card is validated at most once; subsequent requests for the same card skip validation.- Returns:
- a concurrent set suitable for use as the
validatedCardsparameter
-
resolveAndValidateOnce
public static AgentCard resolveAndValidateOnce(jakarta.enterprise.inject.Instance<AgentCard> agentCardInstance, Set<AgentCard> validatedCards) Resolves anAgentCardfrom the givenInstanceand validates its transport configuration once per distinct card using the defaultvalidateTransportConfiguration(AgentCard)check. On failure the card is removed from the set so validation can be retried on the next call.- Parameters:
agentCardInstance- the CDI instance holding the agent cardvalidatedCards- set tracking which cards have already been validated- Returns:
- the resolved agent card
-
resolveAndValidateOnce
public static AgentCard resolveAndValidateOnce(Supplier<AgentCard> agentCardSupplier, Set<AgentCard> validatedCards, Consumer<AgentCard> validator) Obtains anAgentCardfrom the given supplier and applies the provided validator once per distinct card. On failure the card is removed from the set so validation can be retried on the next call.- Parameters:
agentCardSupplier- supplier that produces the agent cardvalidatedCards- set tracking which cards have already been validatedvalidator- validation logic to apply on first access- Returns:
- the resolved agent card
-
resolveWithFallback
public static AgentCard resolveWithFallback(jakarta.enterprise.inject.Instance<AgentCard> publicCard, @Nullable jakarta.enterprise.inject.Instance<AgentCard> extendedCard, Set<AgentCard> validatedCards) Resolves an agent card from the public instance, falling back to the extended instance if the public one is absent. Throws if neither is available.- Parameters:
publicCard- the CDI instance for the@PublicAgentCardextendedCard- the CDI instance for the@ExtendedAgentCard, may benullvalidatedCards- set tracking which cards have already been validated- Returns:
- the resolved agent card
- Throws:
IllegalStateException- if neither card is available
-
resolveWithFallback
public static AgentCard resolveWithFallback(jakarta.enterprise.inject.Instance<AgentCard> publicCard, @Nullable jakarta.enterprise.inject.Instance<AgentCard> extendedCard, @Nullable AgentCardRouter agentCardRouter, @Nullable String tenant, Set<AgentCard> validatedCards) Convenience overload that uses the defaultvalidateTransportConfiguration(AgentCard)validator.- See Also:
-
resolveWithFallback
public static AgentCard resolveWithFallback(jakarta.enterprise.inject.Instance<AgentCard> publicCard, @Nullable jakarta.enterprise.inject.Instance<AgentCard> extendedCard, @Nullable AgentCardRouter agentCardRouter, @Nullable String tenant, Set<AgentCard> validatedCards, Consumer<AgentCard> validator) Resolves an agent card using one of two resolution strategies depending on whether a tenant-scoped request is being made, and validates using the supplied validator.- Parameters:
publicCard- the CDI instance for the@PublicAgentCardextendedCard- the CDI instance for the@ExtendedAgentCard, may benullagentCardRouter- optional router for tenant-specific card resolutiontenant- the tenant identifier, may benullvalidatedCards- set tracking which cards have already been validatedvalidator- validation logic to apply on first access of each distinct card- Returns:
- the resolved agent card
- Throws:
TenantNotFoundException- if a non-blank tenant is specified, a router is available, but neither a public nor extended card is registered for that tenantIllegalStateException- if no card can be resolved (non-tenant-scoped path)- See Also:
-
requireFirst
public static AgentCard requireFirst(@Nullable AgentCard publicCard, @Nullable AgentCard extendedCard) Returns the first non-null agent card, preferring the public card. Throws if both arenull.- Parameters:
publicCard- the public agent card, may benullextendedCard- the extended agent card, may benull- Returns:
- the first non-null card
- Throws:
IllegalStateException- if both cards arenull
-
validateTransportConfiguration
Validates the transport configuration of an AgentCard against available transports found on the classpath. Logs warnings for missing transports and errors for unsupported transports.- Parameters:
agentCard- the agent card to validate
-