Class AnthropicClient

java.lang.Object
org.egothor.methodatlas.ai.AnthropicClient
All Implemented Interfaces:
AiProviderClient

public final class AnthropicClient extends Object implements AiProviderClient
AiProviderClient implementation for the Anthropic API.

This client submits classification requests to the Anthropic Claude API and converts the returned response into the internal AiClassSuggestion model used by the MethodAtlas AI subsystem.

Operational Responsibilities

  • constructing Anthropic message API requests
  • injecting the taxonomy-driven classification prompt
  • performing authenticated HTTP calls to the Anthropic service
  • extracting the JSON result embedded in the model response
  • normalizing the result into AiClassSuggestion

The client uses the /v1/messages endpoint and relies on the Claude message format, where a system prompt defines classification rules and the user message contains the class source together with the taxonomy specification.

Instances of this class are typically created by AiProviderFactory.create(AiOptions).

This implementation is stateless apart from immutable configuration and is therefore safe for reuse across multiple requests.

See Also:
  • Constructor Details

    • AnthropicClient

      public AnthropicClient(AiOptions options)
      Creates a new Anthropic client using the supplied runtime configuration.

      The configuration defines the model identifier, API endpoint, request timeout, and authentication settings used when communicating with the Anthropic service.

      Parameters:
      options - AI runtime configuration
  • Method Details

    • isAvailable

      public boolean isAvailable()
      Determines whether the Anthropic provider can be used in the current runtime environment.

      The provider is considered available when a non-empty API key can be resolved from AiOptions.resolvedApiKey().

      Specified by:
      isAvailable in interface AiProviderClient
      Returns:
      true if a usable API key is configured
    • suggestForClass

      public AiClassSuggestion suggestForClass(String fqcn, String classSource, String taxonomyText, List<PromptBuilder.TargetMethod> targetMethods) throws AiSuggestionException
      Submits a classification request to the Anthropic API for the specified test class.

      The method constructs a message-based request containing:

      • a system prompt enforcing deterministic JSON output
      • a user prompt containing the class source and taxonomy definition

      The response is parsed to extract the first JSON object returned by the model, which is then deserialized into an AiClassSuggestion.

      Specified by:
      suggestForClass in interface AiProviderClient
      Parameters:
      fqcn - fully qualified class name being analyzed
      classSource - complete source code of the class
      taxonomyText - taxonomy definition guiding classification
      targetMethods - deterministically extracted JUnit test methods that must be classified
      Returns:
      normalized AI classification result
      Throws:
      AiSuggestionException - if the provider request fails, the response cannot be parsed, or the provider returns invalid content
      See Also: