类 GeminiResponseParser

java.lang.Object
io.agentscope.core.formatter.gemini.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.

  • 构造器详细资料

    • GeminiResponseParser

      public GeminiResponseParser()
      Creates a new GeminiResponseParser.
  • 方法详细资料

    • parseResponse

      public ChatResponse parseResponse(com.google.genai.types.GenerateContentResponse response, Instant startTime)
      Parse Gemini GenerateContentResponse to AgentScope ChatResponse.
      参数:
      response - Gemini generation response
      startTime - Request start time for calculating duration
      返回:
      AgentScope ChatResponse
    • parsePartsToBlocks

      protected void parsePartsToBlocks(List<com.google.genai.types.Part> parts, List<ContentBlock> blocks)
      Parse Gemini Part objects to AgentScope ContentBlocks. Order of block types: ThinkingBlock, TextBlock, ToolUseBlock
      参数:
      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<ContentBlock> blocks)
      Parse Gemini FunctionCall to ToolUseBlock.
      参数:
      functionCall - Gemini FunctionCall object
      thoughtSignature - Thought signature from the Part (may be null)
      blocks - List to add parsed ToolUseBlock to