Class AgentCardValidator

java.lang.Object
org.a2aproject.sdk.server.AgentCardValidator

public class AgentCardValidator extends Object
Validates AgentCard transport configuration against available transport endpoints.
  • Field Details

  • Constructor Details

    • AgentCardValidator

      public AgentCardValidator()
  • Method Details

    • newValidatedCardsSet

      public static Set<AgentCard> newValidatedCardsSet()
      Creates a new thread-safe set for tracking which AgentCard instances 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 validatedCards parameter
    • resolveAndValidateOnce

      public static AgentCard resolveAndValidateOnce(jakarta.enterprise.inject.Instance<AgentCard> agentCardInstance, Set<AgentCard> validatedCards)
      Resolves an AgentCard from the given Instance and validates its transport configuration once per distinct card using the default validateTransportConfiguration(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 card
      validatedCards - 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 an AgentCard from 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 card
      validatedCards - set tracking which cards have already been validated
      validator - 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 @PublicAgentCard
      extendedCard - the CDI instance for the @ExtendedAgentCard, may be null
      validatedCards - 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 default validateTransportConfiguration(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 @PublicAgentCard
      extendedCard - the CDI instance for the @ExtendedAgentCard, may be null
      agentCardRouter - optional router for tenant-specific card resolution
      tenant - the tenant identifier, may be null
      validatedCards - set tracking which cards have already been validated
      validator - 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 tenant
      IllegalStateException - if no card can be resolved (non-tenant-scoped path)
      See Also:
      • resolveTenantScoped(AgentCardRouter, String, Set, Consumer)
      • resolveDefaultWithRouterFallback(Instance, Instance, AgentCardRouter, String, Set, Consumer)
    • 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 are null.
      Parameters:
      publicCard - the public agent card, may be null
      extendedCard - the extended agent card, may be null
      Returns:
      the first non-null card
      Throws:
      IllegalStateException - if both cards are null
    • validateTransportConfiguration

      public static void validateTransportConfiguration(AgentCard agentCard)
      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