Class GeminiResponseParser

java.lang.Object
io.agentscope.extensions.model.gemini.formatter.GeminiResponseParser

public class GeminiResponseParser extends Object
Parses Gemini API responses to AgentScope ChatResponse.

This parser handles the conversion of Gemini's GenerateContentResponse to AgentScope's ChatResponse format, including:

  • Text blocks from text parts
  • Thinking blocks from parts with thought=true flag
  • Tool use blocks from function_call parts
  • Usage metadata with token counts

Important: In Gemini API, thinking content is indicated by the "thought" flag on Part objects.

  • Constructor Summary

    Constructors
    Constructor
    Description
    Creates a new GeminiResponseParser.
  • Method Summary

    Modifier and Type
    Method
    Description
    protected void
    parsePartsToBlocks(List<com.google.genai.types.Part> parts, List<io.agentscope.core.message.ContentBlock> blocks)
    Parse Gemini Part objects to AgentScope ContentBlocks.
    io.agentscope.core.model.ChatResponse
    parseResponse(com.google.genai.types.GenerateContentResponse response, Instant startTime)
    Parse Gemini GenerateContentResponse to AgentScope ChatResponse.
    protected void
    parseToolCall(com.google.genai.types.FunctionCall functionCall, byte[] thoughtSignature, List<io.agentscope.core.message.ContentBlock> blocks)
    Parse Gemini FunctionCall to ToolUseBlock.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • GeminiResponseParser

      public GeminiResponseParser()
      Creates a new GeminiResponseParser.
  • Method Details

    • parseResponse

      public io.agentscope.core.model.ChatResponse parseResponse(com.google.genai.types.GenerateContentResponse response, Instant startTime)
      Parse Gemini GenerateContentResponse to AgentScope ChatResponse.
      Parameters:
      response - Gemini generation response
      startTime - Request start time for calculating duration
      Returns:
      AgentScope ChatResponse
    • parsePartsToBlocks

      protected void parsePartsToBlocks(List<com.google.genai.types.Part> parts, List<io.agentscope.core.message.ContentBlock> blocks)
      Parse Gemini Part objects to AgentScope ContentBlocks. Order of block types: ThinkingBlock, TextBlock, ToolUseBlock
      Parameters:
      parts - List of Gemini Part objects
      blocks - List to add parsed ContentBlocks to
    • parseToolCall

      protected void parseToolCall(com.google.genai.types.FunctionCall functionCall, byte[] thoughtSignature, List<io.agentscope.core.message.ContentBlock> blocks)
      Parse Gemini FunctionCall to ToolUseBlock.
      Parameters:
      functionCall - Gemini FunctionCall object
      thoughtSignature - Thought signature from the Part (may be null)
      blocks - List to add parsed ToolUseBlock to