GeminiConversationMerger
public class GeminiConversationMerger
源码Source
io/agentscope/extensions/model/gemini/formatter/GeminiConversationMerger.java:51–182Gemini 会话 Merger,与模型服务通信并返回生成或向量化结果。位于 io.agentscope.extensions.model.gemini.formatter 包。核心成员包括 mergeToContent、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
| 构造器Constructor | 说明Description |
|---|---|
public GeminiConversationMerger(String conversationHistoryPrompt) | 创建GeminiConversationMerger 使用自定义会话历史提示词。 Create a GeminiConversationMerger with custom conversation history prompt. |
方法摘要Method Summary
| 方法Method | 说明Description |
|---|---|
public Content mergeToContent(List<Msg> msgs, Function<Msg, String> nameExtractor, Function<List<ContentBlock>, String> toolResultConverter, String historyPrompt) | 合并到内容。 Merge conversation messages into a single Content (for Gemini API). |
构造器详情Constructor Detail
GeminiConversationMerger
public GeminiConversationMerger(String conversationHistoryPrompt)
创建GeminiConversationMerger 使用自定义会话历史提示词。
Create a GeminiConversationMerger with custom conversation history prompt.
参数Parameters
| 名称Name | 类型Type | 说明Description |
|---|---|---|
conversationHistoryPrompt | String | 会话历史提示词(类型 `String`)。The prompt to prepend before conversation history |
源码Source
io/agentscope/extensions/model/gemini/formatter/GeminiConversationMerger.java:66–69方法详情Method Detail
mergeToContent
public Content mergeToContent(List<Msg> msgs, Function<Msg, String> nameExtractor, Function<List<ContentBlock>, String> toolResultConverter, String historyPrompt)
合并到内容。
Merge conversation messages into a single Content (for Gemini API).
参数Parameters
| 名称Name | 类型Type | 说明Description |
|---|---|---|
msgs | List<Msg> | 消息列表(类型 `List`)。List of conversation messages to merge |
nameExtractor | Function<Msg, String> | 名称 Extractor(类型 `Function`)。Function to extract agent name from message |
toolResultConverter | Function<List<ContentBlock>, String> | 工具结果转换器(类型 `Function , String>`)。Function to convert tool result blocks to strings |
historyPrompt | String | 历史提示词(类型 `String`)。The prompt to prepend (empty if not first group) |
Content返回内容。Single merged Content for Gemini API
源码Source
io/agentscope/extensions/model/gemini/formatter/GeminiConversationMerger.java:84–181