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 Summary
ConstructorsConstructorDescriptionCreate a DashScopeMultiAgentFormatter with default conversation history prompt.DashScopeMultiAgentFormatter(String conversationHistoryPrompt) Create a DashScopeMultiAgentFormatter with custom conversation history prompt. -
Method Summary
Modifier and TypeMethodDescriptionvoidapplyOptions(DashScopeRequest request, io.agentscope.core.model.GenerateOptions options, io.agentscope.core.model.GenerateOptions defaultOptions) voidapplyToolChoice(DashScopeRequest request, io.agentscope.core.model.ToolChoice toolChoice) voidapplyTools(DashScopeRequest request, List<io.agentscope.core.model.ToolSchema> tools) buildRequest(String model, List<DashScopeMessage> messages, boolean stream) Build a complete DashScopeRequest for the API call.protected List<DashScopeMessage>protected List<DashScopeMessage>doFormat(List<io.agentscope.core.message.Msg> msgs, io.agentscope.core.model.GenerateOptions options) formatMultiModal(List<io.agentscope.core.message.Msg> msgs) Format AgentScope Msg objects to DashScope MultiModal message format.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.io.agentscope.core.model.ChatResponseparseResponse(DashScopeResponse result, Instant startTime) Methods inherited from class io.agentscope.core.formatter.AbstractBaseFormatter
convertToolResultToString, extractTextContent, extractTextContent, format, format, formatRoleLabel, getOptionOrDefault, hasMediaContent, saveBase64DataToTempFile, shouldBypassHistoryMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface io.agentscope.core.formatter.Formatter
applyToolChoice, applyTools
-
Constructor Details
-
DashScopeMultiAgentFormatter
public DashScopeMultiAgentFormatter()Create a DashScopeMultiAgentFormatter with default conversation history prompt. -
DashScopeMultiAgentFormatter
Create a DashScopeMultiAgentFormatter with custom conversation history prompt.- Parameters:
conversationHistoryPrompt- The prompt to prepend before conversation history
-
-
Method Details
-
doFormat
- Specified by:
doFormatin classio.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:
doFormatin classio.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
-
applyToolChoice
public void applyToolChoice(DashScopeRequest request, io.agentscope.core.model.ToolChoice toolChoice) -
formatMultiModal
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 convertoptions- request-scoped generation options; may benull- Returns:
- List of DashScopeMessage objects with multimodal content
-
buildRequest
Build a complete DashScopeRequest for the API call.- Parameters:
model- Model namemessages- Formatted DashScope messagesstream- Whether to enable streaming- Returns:
- Complete DashScopeRequest ready for API call
-