Class MessageConvertUtil

java.lang.Object
io.agentscope.core.a2a.server.utils.MessageConvertUtil

public class MessageConvertUtil extends Object
Message Converter between Agentscope Msg and A2A Message or Artifact.
  • 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 of Msg to Message.
      Parameters:
      msgs - the list of Msg to convert
      taskId - the taskId
      contextId - 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 Event chunks. Regular conversion from user-provided message lists must keep using convertFromMsgToMessage(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 a Msg to Message.
      Parameters:
      msg - the Msg to convert
      taskId - the taskId
      contextId - 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 in Msg to list of Part.
      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 in Msg to list of Part.
      Parameters:
      msg - the Msg saved content blocks to convert
      streamingChunk - 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 A2A Message to List of Msg.

      Convert rule is revert from List of Msg to A2A Message in A2aAgent, step with following:

      1. Traversal all Part from A2A Message and Convert to target ContentBlock.
      2. Try to read msgId and msgName from each Part metadata and keep them with order.
      3. Combine all ContentBlock by msgId, If no msgId from Part, create a random single id for it.
      4. Traversal all msgId with order, and build Msg with msgId, msgName, it's ContentBlock and metadata if found from Message metadata.

      If A2A Message from no agentscope client, parts might not include msgId and msgName, it will degrade to one Part to one Msg with single ContentBlock.

      Parameters:
      message - a2a protocol message from a2a client.
      Returns:
      list of Msg