Class GeminiConversationMerger
java.lang.Object
io.agentscope.extensions.model.gemini.formatter.GeminiConversationMerger
Merges multi-agent conversation messages for Gemini API.
This class consolidates multiple agent messages into a single Content with conversation history wrapped in special tags. It preserves agent names and roles in the merged text.
Format:
# Conversation History <history> ## AgentName (role) Agent message content... </history>
-
Constructor Summary
ConstructorsConstructorDescriptionGeminiConversationMerger(String conversationHistoryPrompt) Create a GeminiConversationMerger with custom conversation history prompt. -
Method Summary
Modifier and TypeMethodDescriptioncom.google.genai.types.ContentmergeToContent(List<io.agentscope.core.message.Msg> msgs, Function<io.agentscope.core.message.Msg, String> nameExtractor, Function<List<io.agentscope.core.message.ContentBlock>, String> toolResultConverter, String historyPrompt) Merge conversation messages into a single Content (for Gemini API).
-
Constructor Details
-
GeminiConversationMerger
Create a GeminiConversationMerger with custom conversation history prompt.- Parameters:
conversationHistoryPrompt- The prompt to prepend before conversation history
-
-
Method Details
-
mergeToContent
public com.google.genai.types.Content mergeToContent(List<io.agentscope.core.message.Msg> msgs, Function<io.agentscope.core.message.Msg, String> nameExtractor, Function<List<io.agentscope.core.message.ContentBlock>, String> toolResultConverter, String historyPrompt) Merge conversation messages into a single Content (for Gemini API).This method combines all agent messages into a single "user" role Content with conversation history wrapped in
<history>tags. Agent names and roles are embedded in the text.- Parameters:
msgs- List of conversation messages to mergenameExtractor- Function to extract agent name from messagetoolResultConverter- Function to convert tool result blocks to stringshistoryPrompt- The prompt to prepend (empty if not first group)- Returns:
- Single merged Content for Gemini API
-