Class GeminiResponse


public class GeminiResponse extends Response<GeminiModelMessage>
A specialized, object-oriented Response class for the Gemini provider. It encapsulates all the logic for converting a native Google GenerateContentResponse into the Anahata domain model, making it a self-contained and reusable component.
Author:
anahata
  • Field Details

    • genaiResponse

      private final transient com.google.genai.types.GenerateContentResponse genaiResponse
      The original, native response object from the Google GenAI API. transient to avoid serialization of SDK types.
    • candidates

      private final List<GeminiModelMessage> candidates
      The list of converted model messages.
    • usageMetadata

      private final ResponseUsageMetadata usageMetadata
      The converted usage metadata.
    • promptFeedback

      private final Optional<String> promptFeedback
      Optional feedback from the safety filters.
    • rawRequestConfigJson

      private final String rawRequestConfigJson
      The raw JSON of the request configuration.
    • rawHistoryJson

      private final String rawHistoryJson
      The raw JSON of the conversation history sent in the request.
    • rawJson

      private final String rawJson
      The raw JSON of the entire response.
    • modelVersion

      private final String modelVersion
      The model version used for this specific generation.
  • Constructor Details

    • GeminiResponse

      public GeminiResponse(String requestConfigJson, String historyJson, Agi agi, String modelId, com.google.genai.types.GenerateContentResponse genaiResponse)
      Constructs a GeminiResponse, performing the full conversion from the native Google GenAI response to the Anahata domain model.
      Parameters:
      requestConfigJson - The raw JSON of the request configuration.
      historyJson - The raw JSON of the conversation history sent in the request.
      agi - The parent agi session, required for constructing model messages.
      modelId - The ID of the model that generated this response.
      genaiResponse - The native response object from the API.
  • Method Details

    • convertUsageMetadata

      private ResponseUsageMetadata convertUsageMetadata(com.google.genai.types.GenerateContentResponseUsageMetadata genaiUsage)
      Converts the native GenAI usage metadata to the V2 core model.
      Parameters:
      genaiUsage - The native usage metadata.
      Returns:
      The V2 ResponseUsageMetadata.
    • getTotalTokenCount

      public int getTotalTokenCount()
      Gets the total number of tokens for the entire interaction (prompt + all candidates).
      Specified by:
      getTotalTokenCount in class Response<GeminiModelMessage>
      Returns:
      The total token count.