类 DashScopeConversationMerger
java.lang.Object
io.agentscope.core.formatter.dashscope.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).
-
构造器概要
构造器构造器说明DashScopeConversationMerger(String conversationHistoryPrompt) Create a DashScopeConversationMerger with custom conversation history prompt. -
方法概要
修饰符和类型方法说明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).mergeToMultiModalMessage(List<Msg> msgs, Function<Msg, String> nameExtractor, Function<List<ContentBlock>, String> toolResultConverter, boolean isFirst) Merge conversation messages into a single DashScopeMessage (multimodal mode).
-
构造器详细资料
-
DashScopeConversationMerger
Create a DashScopeConversationMerger with custom conversation history prompt.- 参数:
conversationHistoryPrompt- The prompt to prepend before conversation history
-
-
方法详细资料
-
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).This method combines all agent messages into a single user message with conversation history wrapped in
<history>tags. Agent names and roles are embedded in the text.- 参数:
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)- 返回:
- Single merged DashScopeMessage
-
mergeToMultiModalMessage
public DashScopeMessage mergeToMultiModalMessage(List<Msg> msgs, Function<Msg, String> nameExtractor, Function<List<ContentBlock>, String> toolResultConverter, boolean isFirst) Merge conversation messages into a single DashScopeMessage (multimodal mode). Follows Python's _format_agent_message logic exactly.This method combines all agent messages into a single user message with conversation history wrapped in
<history>tags. Images and videos are preserved as separate content parts in the multimodal format.- 参数:
msgs- List of conversation messages to mergenameExtractor- Function to extract agent name from messagetoolResultConverter- Function to convert tool result blocks to stringsisFirst- Whether this is the first agent message group (includes history prompt if true)- 返回:
- Single merged DashScopeMessage with multimodal content
-