Class GeminiResponseParser
java.lang.Object
io.agentscope.extensions.model.gemini.formatter.GeminiResponseParser
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 -
Method Summary
Modifier and TypeMethodDescriptionprotected voidparsePartsToBlocks(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.ChatResponseparseResponse(com.google.genai.types.GenerateContentResponse response, Instant startTime) Parse Gemini GenerateContentResponse to AgentScope ChatResponse.protected voidparseToolCall(com.google.genai.types.FunctionCall functionCall, byte[] thoughtSignature, List<io.agentscope.core.message.ContentBlock> blocks) Parse Gemini FunctionCall to ToolUseBlock.
-
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 responsestartTime- 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 objectsblocks- 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 objectthoughtSignature- Thought signature from the Part (may be null)blocks- List to add parsed ToolUseBlock to
-