DashScopeConversationMerger
public class DashScopeConversationMerger
源码Source
io/agentscope/extensions/model/dashscope/formatter/DashScopeConversationMerger.java:43–316DashScope 会话 Merger,与模型服务通信并返回生成或向量化结果。位于 io.agentscope.extensions.model.dashscope.formatter 包。核心成员包括 mergeToMessage、mergeToMultiModalMessage、DashScopeConversationMerger。
Merges multi-agent conversation messages for DashScope API.
This class consolidates multiple agent messages into a single message with conversation history wrapped in special tags. It preserves agent names, roles, and multimodal content (images/videos).
构造器摘要Constructor Summary
| 构造器Constructor | 说明Description |
|---|---|
public DashScopeConversationMerger(String conversationHistoryPrompt) | 创建DashScopeConversationMerger 使用自定义会话历史提示词。 Create a DashScopeConversationMerger with custom conversation history prompt. |
方法摘要Method Summary
| 方法Method | 说明Description |
|---|---|
public DashScopeMessage mergeToMessage(List<Msg> msgs, Function<Msg, String> nameExtractor, Function<List<ContentBlock>, String> toolResultConverter, String historyPrompt) | 合并到消息。 Merge conversation messages into a single DashScopeMessage (text-only mode). |
public DashScopeMessage mergeToMultiModalMessage(List<Msg> msgs, Function<Msg, String> nameExtractor, Function<List<ContentBlock>, String> toolResultConverter, boolean isFirst) | 合并 `mergeToMultiModalMessage`。 Merge conversation messages into a single DashScopeMessage (multimodal mode). |
构造器详情Constructor Detail
DashScopeConversationMerger
public DashScopeConversationMerger(String conversationHistoryPrompt)
创建DashScopeConversationMerger 使用自定义会话历史提示词。
Create a DashScopeConversationMerger with custom conversation history prompt.
参数Parameters
| 名称Name | 类型Type | 说明Description |
|---|---|---|
conversationHistoryPrompt | String | 会话历史提示词(类型 `String`)。The prompt to prepend before conversation history |
源码Source
io/agentscope/extensions/model/dashscope/formatter/DashScopeConversationMerger.java:58–61方法详情Method Detail
mergeToMessage
public DashScopeMessage mergeToMessage(List<Msg> msgs, Function<Msg, String> nameExtractor, Function<List<ContentBlock>, String> toolResultConverter, String historyPrompt)
合并到消息。
Merge conversation messages into a single DashScopeMessage (text-only mode).
参数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) |
DashScopeMessage返回DashScopeMessage。Single merged DashScopeMessage
源码Source
io/agentscope/extensions/model/dashscope/formatter/DashScopeConversationMerger.java:75–177mergeToMultiModalMessage
public DashScopeMessage mergeToMultiModalMessage(List<Msg> msgs, Function<Msg, String> nameExtractor, Function<List<ContentBlock>, String> toolResultConverter, boolean isFirst)
合并 mergeToMultiModalMessage。
Merge conversation messages into a single DashScopeMessage (multimodal mode).
参数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 |
isFirst | boolean | 是第一个(类型 `boolean`)。Whether this is the first agent message group (includes history prompt if true) |
DashScopeMessage返回DashScopeMessage。Single merged DashScopeMessage with multimodal content
源码Source
io/agentscope/extensions/model/dashscope/formatter/DashScopeConversationMerger.java:192–315