Class MessageConvertUtil
java.lang.Object
io.agentscope.core.a2a.server.utils.MessageConvertUtil
Message Converter between Agentscope
Msg and A2A Message or Artifact.-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic List<io.agentscope.core.message.Msg>compactStreamingChunks(List<io.agentscope.core.message.Msg> msgs) Compact consecutive streaming delta messages that share the same message id.static List<io.a2a.spec.Part<?>>convertFromContentBlocks(io.agentscope.core.message.Msg msg) Convert content blocks inMsgto list ofPart.static List<io.a2a.spec.Part<?>>convertFromContentBlocks(io.agentscope.core.message.Msg msg, boolean streamingChunk) Convert content blocks inMsgto list ofPart.static List<io.agentscope.core.message.Msg>convertFromMessageToMsgs(io.a2a.spec.Message message) Convert a A2AMessageto List ofMsg.static io.a2a.spec.MessageconvertFromMsgToMessage(io.agentscope.core.message.Msg msg, String taskId, String contextId) Convert aMsgtoMessage.static io.a2a.spec.MessageconvertFromMsgToMessage(List<io.agentscope.core.message.Msg> msgs, String taskId, String contextId) Convert a list ofMsgtoMessage.
-
Constructor Details
-
MessageConvertUtil
public MessageConvertUtil()
-
-
Method Details
-
convertFromMsgToMessage
public static io.a2a.spec.Message convertFromMsgToMessage(List<io.agentscope.core.message.Msg> msgs, String taskId, String contextId) Convert a list ofMsgtoMessage.- Parameters:
msgs- the list of Msg to converttaskId- the taskIdcontextId- the contextId- Returns:
- the converted Message object
-
compactStreamingChunks
public static List<io.agentscope.core.message.Msg> compactStreamingChunks(List<io.agentscope.core.message.Msg> msgs) Compact consecutive streaming delta messages that share the same message id.This is intended for executor fallback paths that accumulate
Eventchunks. Regular conversion from user-provided message lists must keep usingconvertFromMsgToMessage(List, String, String)directly so semantic message and block boundaries are preserved.- Parameters:
msgs- messages emitted by the streaming event pipeline- Returns:
- messages with consecutive text/thinking deltas merged per message id
-
convertFromMsgToMessage
public static io.a2a.spec.Message convertFromMsgToMessage(io.agentscope.core.message.Msg msg, String taskId, String contextId) Convert aMsgtoMessage.- Parameters:
msg- the Msg to converttaskId- the taskIdcontextId- the contextId- Returns:
- the converted Message object
-
convertFromContentBlocks
public static List<io.a2a.spec.Part<?>> convertFromContentBlocks(io.agentscope.core.message.Msg msg) Convert content blocks inMsgto list ofPart.- Parameters:
msg- the Msg saved content blocks to convert- Returns:
- list of Part
-
convertFromContentBlocks
public static List<io.a2a.spec.Part<?>> convertFromContentBlocks(io.agentscope.core.message.Msg msg, boolean streamingChunk) Convert content blocks inMsgto list ofPart.- Parameters:
msg- the Msg saved content blocks to convertstreamingChunk- whether these parts represent streaming delta chunks- Returns:
- list of Part
-
convertFromMessageToMsgs
public static List<io.agentscope.core.message.Msg> convertFromMessageToMsgs(io.a2a.spec.Message message) Convert a A2AMessageto List ofMsg.Convert rule is revert from List of
Msgto A2AMessagein A2aAgent, step with following:- Traversal all
Partfrom A2AMessageand Convert to targetContentBlock. - Try to read msgId and msgName from each
Partmetadata and keep them with order. - Combine all
ContentBlockby msgId, If no msgId fromPart, create a random single id for it. - Traversal all msgId with order, and build
Msgwith msgId, msgName, it'sContentBlockand metadata if found fromMessagemetadata.
If A2A
Messagefrom no agentscope client, parts might not include msgId and msgName, it will degrade to onePartto oneMsgwith singleContentBlock.- Parameters:
message- a2a protocol message from a2a client.- Returns:
- list of
Msg
- Traversal all
-