AS AgentScopeAPI 手册 / API Reference

DashScopeConversationMerger

public class DashScopeConversationMerger
源码Source io/agentscope/extensions/model/dashscope/formatter/DashScopeConversationMerger.java:43–316

DashScope 会话 Merger,与模型服务通信并返回生成或向量化结果。位于 io.agentscope.extensions.model.dashscope.formatter 包。核心成员包括 mergeToMessage、mergeToMultiModalMessage、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).

构造器摘要Constructor Summary

构造器Constructor说明Description
public DashScopeConversationMerger(String conversationHistoryPrompt)
创建DashScopeConversationMerger 使用自定义会话历史提示词。
Create a DashScopeConversationMerger with custom conversation history prompt.

方法摘要Method Summary

方法Method说明Description
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).
public DashScopeMessage mergeToMultiModalMessage(List<Msg> msgs, Function<Msg, String> nameExtractor, Function<List<ContentBlock>, String> toolResultConverter, boolean isFirst)
合并 `mergeToMultiModalMessage`。
Merge conversation messages into a single DashScopeMessage (multimodal mode).

构造器详情Constructor Detail

DashScopeConversationMerger

public DashScopeConversationMerger(String conversationHistoryPrompt)

创建DashScopeConversationMerger 使用自定义会话历史提示词。

Create a DashScopeConversationMerger with custom conversation history prompt.

参数Parameters
名称Name类型Type说明Description
conversationHistoryPromptString会话历史提示词(类型 `String`)。The prompt to prepend before conversation history
源码Source io/agentscope/extensions/model/dashscope/formatter/DashScopeConversationMerger.java:58–61

方法详情Method Detail

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).

参数Parameters
名称Name类型Type说明Description
msgsList<Msg>消息列表(类型 `List`)。List of conversation messages to merge
nameExtractorFunction<Msg, String>名称 Extractor(类型 `Function`)。Function to extract agent name from message
toolResultConverterFunction<List<ContentBlock>, String>工具结果转换器(类型 `Function , String>`)。Function to convert tool result blocks to strings
historyPromptString历史提示词(类型 `String`)。The prompt to prepend (empty if not first group)
返回Returns DashScopeMessage
返回DashScopeMessage。Single merged DashScopeMessage
源码Source io/agentscope/extensions/model/dashscope/formatter/DashScopeConversationMerger.java:75–177

mergeToMultiModalMessage

public DashScopeMessage mergeToMultiModalMessage(List<Msg> msgs, Function<Msg, String> nameExtractor, Function<List<ContentBlock>, String> toolResultConverter, boolean isFirst)

合并 mergeToMultiModalMessage。

Merge conversation messages into a single DashScopeMessage (multimodal mode).

参数Parameters
名称Name类型Type说明Description
msgsList<Msg>消息列表(类型 `List`)。List of conversation messages to merge
nameExtractorFunction<Msg, String>名称 Extractor(类型 `Function`)。Function to extract agent name from message
toolResultConverterFunction<List<ContentBlock>, String>工具结果转换器(类型 `Function , String>`)。Function to convert tool result blocks to strings
isFirstboolean是第一个(类型 `boolean`)。Whether this is the first agent message group (includes history prompt if true)
返回Returns DashScopeMessage
返回DashScopeMessage。Single merged DashScopeMessage with multimodal content
源码Source io/agentscope/extensions/model/dashscope/formatter/DashScopeConversationMerger.java:192–315
基于官方固定版本源码静态生成Generated from pinned official sources · Python 2.0.11 · Java 2.0.4
签名与文档为静态抽取;如有疑问请以源码为准。Signatures and docs are extracted statically; verify against the source when in doubt.