Class DashScopeMultiAgentFormatter

java.lang.Object
io.agentscope.core.formatter.AbstractBaseFormatter<DashScopeMessage,DashScopeResponse,DashScopeRequest>
io.agentscope.extensions.model.dashscope.formatter.DashScopeMultiAgentFormatter
All Implemented Interfaces:
io.agentscope.core.formatter.Formatter<DashScopeMessage,DashScopeResponse,DashScopeRequest>

public class DashScopeMultiAgentFormatter extends io.agentscope.core.formatter.AbstractBaseFormatter<DashScopeMessage,DashScopeResponse,DashScopeRequest>
DashScope formatter for multi-agent conversations. Converts AgentScope Msg objects to DashScope DTO Message objects with multi-agent support. Collapses multi-agent conversation into a single user message with history tags.

ThinkingBlock Handling: ThinkingBlock content is filtered out and NOT sent to DashScope API. It is stored in memory but excluded from all formatted messages.

  • Constructor Details

    • DashScopeMultiAgentFormatter

      public DashScopeMultiAgentFormatter()
      Create a DashScopeMultiAgentFormatter with default conversation history prompt.
    • DashScopeMultiAgentFormatter

      public DashScopeMultiAgentFormatter(String conversationHistoryPrompt)
      Create a DashScopeMultiAgentFormatter with custom conversation history prompt.
      Parameters:
      conversationHistoryPrompt - The prompt to prepend before conversation history
  • Method Details

    • doFormat

      protected List<DashScopeMessage> doFormat(List<io.agentscope.core.message.Msg> msgs)
      Specified by:
      doFormat in class io.agentscope.core.formatter.AbstractBaseFormatter<DashScopeMessage,DashScopeResponse,DashScopeRequest>
    • doFormat

      protected List<DashScopeMessage> doFormat(List<io.agentscope.core.message.Msg> msgs, io.agentscope.core.model.GenerateOptions options)
      Overrides:
      doFormat in class io.agentscope.core.formatter.AbstractBaseFormatter<DashScopeMessage,DashScopeResponse,DashScopeRequest>
    • parseResponse

      public io.agentscope.core.model.ChatResponse parseResponse(DashScopeResponse result, Instant startTime)
    • applyOptions

      public void applyOptions(DashScopeRequest request, io.agentscope.core.model.GenerateOptions options, io.agentscope.core.model.GenerateOptions defaultOptions)
    • applyTools

      public void applyTools(DashScopeRequest request, List<io.agentscope.core.model.ToolSchema> tools)
    • applyToolChoice

      public void applyToolChoice(DashScopeRequest request, io.agentscope.core.model.ToolChoice toolChoice)
    • formatMultiModal

      public List<DashScopeMessage> formatMultiModal(List<io.agentscope.core.message.Msg> msgs)
      Format AgentScope Msg objects to DashScope MultiModal message format. This method is used for vision models that require the MultiModalConversation API.

      Processing steps: 1. Process system message (if any) 2. Group remaining messages into "agent_message" and "tool_sequence" 3. Process each group in order, with first agent_message having history prompt

      Parameters:
      msgs - The AgentScope messages to convert
      Returns:
      List of DashScopeMessage objects with multimodal content
    • formatMultiModal

      public List<DashScopeMessage> formatMultiModal(List<io.agentscope.core.message.Msg> msgs, io.agentscope.core.model.GenerateOptions options)
      Format AgentScope Msg objects to DashScope MultiModal message format using request-scoped generation options.
      Parameters:
      msgs - The AgentScope messages to convert
      options - request-scoped generation options; may be null
      Returns:
      List of DashScopeMessage objects with multimodal content
    • buildRequest

      public DashScopeRequest buildRequest(String model, List<DashScopeMessage> messages, boolean stream)
      Build a complete DashScopeRequest for the API call.
      Parameters:
      model - Model name
      messages - Formatted DashScope messages
      stream - Whether to enable streaming
      Returns:
      Complete DashScopeRequest ready for API call