类 DashScopeMultiAgentFormatter

所有已实现的接口:
Formatter<DashScopeMessage,DashScopeResponse,DashScopeRequest>

public class DashScopeMultiAgentFormatter extends 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.

  • 构造器详细资料

    • DashScopeMultiAgentFormatter

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

      public DashScopeMultiAgentFormatter(String conversationHistoryPrompt)
      Create a DashScopeMultiAgentFormatter with custom conversation history prompt.
      参数:
      conversationHistoryPrompt - The prompt to prepend before conversation history
  • 方法详细资料

    • doFormat

      protected List<DashScopeMessage> doFormat(List<Msg> msgs)
      指定者:
      doFormat 在类中 AbstractBaseFormatter<DashScopeMessage,DashScopeResponse,DashScopeRequest>
    • parseResponse

      public ChatResponse parseResponse(DashScopeResponse result, Instant startTime)
      从接口复制的说明: Formatter
      Parse provider-specific response to AgentScope ChatResponse.
      参数:
      result - Provider-specific response object
      startTime - Request start time for calculating duration
      返回:
      AgentScope ChatResponse
    • applyOptions

      public void applyOptions(DashScopeRequest request, GenerateOptions options, GenerateOptions defaultOptions)
      从接口复制的说明: Formatter
      Apply generation options to provider-specific request parameters.
      参数:
      request - Provider-specific request parameters builder
      options - Generation options to apply
      defaultOptions - Default options to use if options parameter is null
    • applyTools

      public void applyTools(DashScopeRequest request, List<ToolSchema> tools)
      从接口复制的说明: Formatter
      Apply tool schemas to provider-specific request parameters.
      参数:
      request - Provider-specific request parameters builder
      tools - List of tool schemas to apply (may be null or empty)
    • applyToolChoice

      public void applyToolChoice(DashScopeRequest request, ToolChoice toolChoice)
      从接口复制的说明: Formatter
      Apply tool choice configuration to provider-specific request parameters.

      This method controls how the model uses tools. The default implementation does nothing, allowing formatters to override for providers that support tool choice configuration.

      参数:
      request - Provider-specific request parameters builder
      toolChoice - Tool choice configuration (null means provider default)
    • formatMultiModal

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

      This method follows Python's logic: 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

      参数:
      msgs - The AgentScope messages to convert
      返回:
      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.
      参数:
      model - Model name
      messages - Formatted DashScope messages
      stream - Whether to enable streaming
      返回:
      Complete DashScopeRequest ready for API call
    • applyCacheControl

      public void applyCacheControl(List<DashScopeMessage> messages)
      Apply cache control to DashScope messages.

      Adds cache_control: {"type": "ephemeral"} to all system messages and the last message in the list. Messages that already have cache_control set (e.g., via manual metadata marking) will not be overwritten.

      参数:
      messages - the list of formatted DashScope messages