类 DashScopeConversationMerger

java.lang.Object
io.agentscope.core.formatter.dashscope.DashScopeConversationMerger

public class DashScopeConversationMerger extends Object
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

      public DashScopeConversationMerger(String conversationHistoryPrompt)
      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 merge
      nameExtractor - Function to extract agent name from message
      toolResultConverter - Function to convert tool result blocks to strings
      historyPrompt - 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 merge
      nameExtractor - Function to extract agent name from message
      toolResultConverter - Function to convert tool result blocks to strings
      isFirst - Whether this is the first agent message group (includes history prompt if true)
      返回:
      Single merged DashScopeMessage with multimodal content