Package io.agentscope.core.agui.model
Class AguiMessage
java.lang.Object
io.agentscope.core.agui.model.AguiMessage
Represents a message in the AG-UI protocol.
Messages are the primary communication unit in the AG-UI protocol. They contain content, role information, and optionally tool calls or tool call IDs.
Message roles:
- user - Messages from the user
- assistant - Messages from the AI assistant
- system - System instructions
- tool - Tool execution results
The content field uses MessageContent, a type-safe sealed union
that can represent either plain text or a list of structured InputContent
parts (text, image, audio, video, document).
-
Constructor Summary
ConstructorsConstructorDescriptionAguiMessage(String id, String role, MessageContent content, List<AguiToolCall> toolCalls, String toolCallId) Creates a new AguiMessage. -
Method Summary
Modifier and TypeMethodDescriptionstatic AguiMessageassistantMessage(String id, String content) Creates a simple assistant message.static AguiMessageblocksMessage(String id, String role, List<InputContent> blocks, List<AguiToolCall> toolCalls, String toolCallId) Creates a message with structured content blocks, supporting a custom role, tool calls, and tool call ID.booleanGet the message content as a type-safeMessageContent.getId()Get the message ID.getRole()Get the message role.Get the plain text content if the content is aMessageContent.Text.Get the tool call ID (for tool messages).Get the tool calls (for assistant messages).booleanCheck if this message has structured content blocks.inthashCode()booleanCheck if this message has tool calls.booleanCheck if this is an assistant message.booleanCheck if this is a system message.booleanCheck if this is a tool message.booleanCheck if this is a user message.static AguiMessagesystemMessage(String id, String content) Creates a system message.static AguiMessagetextMessage(String id, String role, String text, List<AguiToolCall> toolCalls, String toolCallId) Creates a message with plain text content, supporting a custom role, tool calls, and tool call ID.static AguiMessagetoolMessage(String id, String toolCallId, String content) Creates a tool result message.toString()static AguiMessageuserMessage(String id, String content) Creates a simple user message with plain text content.static AguiMessageuserMessage(String id, List<InputContent> blocks) Creates a user message with structured content blocks.
-
Constructor Details
-
AguiMessage
public AguiMessage(String id, String role, MessageContent content, List<AguiToolCall> toolCalls, String toolCallId) Creates a new AguiMessage.- Parameters:
id- The unique message IDrole- The message role (user, assistant, system, tool)content- The message content (plain text or structured blocks), may be nulltoolCalls- Tool calls for assistant messages (optional)toolCallId- Tool call ID for tool messages (optional)
-
-
Method Details
-
userMessage
Creates a simple user message with plain text content.- Parameters:
id- The message IDcontent- The message content as plain text- Returns:
- A new user message
-
userMessage
Creates a user message with structured content blocks.- Parameters:
id- The message IDblocks- The structured content parts- Returns:
- A new user message
-
assistantMessage
Creates a simple assistant message.- Parameters:
id- The message IDcontent- The message content as plain text- Returns:
- A new assistant message
-
systemMessage
Creates a system message.- Parameters:
id- The message IDcontent- The message content as plain text- Returns:
- A new system message
-
toolMessage
Creates a tool result message.- Parameters:
id- The message IDtoolCallId- The ID of the tool call this is responding tocontent- The tool result content as plain text- Returns:
- A new tool message
-
textMessage
public static AguiMessage textMessage(String id, String role, String text, List<AguiToolCall> toolCalls, String toolCallId) Creates a message with plain text content, supporting a custom role, tool calls, and tool call ID. This is the full-parameter convenience factory for text-based messages.- Parameters:
id- The message IDrole- The message role (user, assistant, system, tool)text- The message content as plain text, may be nulltoolCalls- Tool calls for assistant messages (optional)toolCallId- Tool call ID for tool messages (optional)- Returns:
- A new message
-
blocksMessage
public static AguiMessage blocksMessage(String id, String role, List<InputContent> blocks, List<AguiToolCall> toolCalls, String toolCallId) Creates a message with structured content blocks, supporting a custom role, tool calls, and tool call ID. This is the full-parameter convenience factory for blocks-based messages.- Parameters:
id- The message IDrole- The message role (user, assistant, system, tool)blocks- The structured content partstoolCalls- Tool calls for assistant messages (optional)toolCallId- Tool call ID for tool messages (optional)- Returns:
- A new message
-
getId
Get the message ID.- Returns:
- The message ID
-
getRole
Get the message role.- Returns:
- The role (user, assistant, system, tool)
-
getContent
Get the message content as a type-safeMessageContent.- Returns:
- The content, may be null
-
getTextContent
Get the plain text content if the content is aMessageContent.Text.This is a convenience method for the common case where content is plain text. If the content is structured blocks or null, this returns null.
- Returns:
- The text value, or null if content is not plain text
-
hasBlocks
public boolean hasBlocks()Check if this message has structured content blocks.- Returns:
- true if the content is a
MessageContent.Blocks
-
getToolCalls
Get the tool calls (for assistant messages).- Returns:
- The tool calls as an immutable list, empty if none
-
getToolCallId
Get the tool call ID (for tool messages).- Returns:
- The tool call ID, or null if not a tool message
-
isUserMessage
public boolean isUserMessage()Check if this is a user message.- Returns:
- true if role is "user"
-
isAssistantMessage
public boolean isAssistantMessage()Check if this is an assistant message.- Returns:
- true if role is "assistant"
-
isSystemMessage
public boolean isSystemMessage()Check if this is a system message.- Returns:
- true if role is "system"
-
isToolMessage
public boolean isToolMessage()Check if this is a tool message.- Returns:
- true if role is "tool"
-
hasToolCalls
public boolean hasToolCalls()Check if this message has tool calls.- Returns:
- true if tool calls are present
-
toString
-
equals
-
hashCode
public int hashCode()
-