AguiMessage
public class AguiMessage
io/agentscope/core/agui/model/AguiMessage.java:42–323表示消息,使用 AG-UI 协议。位于 io.agentscope.core.agui.model 包。核心成员包括 userMessage、assistantMessage、systemMessage、toolMessage、textMessage、blocksMessage。
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
| 构造器Constructor | 说明Description |
|---|---|
public AguiMessage(String id, String role, MessageContent content, List<AguiToolCall> toolCalls, String toolCallId) | 创建新的AguiMessage。 Creates a new AguiMessage. |
方法摘要Method Summary
构造器详情Constructor Detail
AguiMessage
public AguiMessage(String id, String role, MessageContent content, List<AguiToolCall> toolCalls, String toolCallId)
创建新的AguiMessage。
Creates a new AguiMessage.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
id | String | 标识(类型 `String`)。The unique message ID |
role | String | 角色(类型 `String`)。The message role (user, assistant, system, tool) |
content | MessageContent | 内容(类型 `MessageContent`)。The message content (plain text or structured blocks), may be null |
toolCalls | List<AguiToolCall> | 工具调用(类型 `List`)。Tool calls for assistant messages (optional) |
toolCallId | String | 用于工具消息(可选)的工具调用标识。Tool call ID for tool messages (optional) |
io/agentscope/core/agui/model/AguiMessage.java:59–74方法详情Method Detail
userMessage
public static AguiMessage userMessage(String id, String content)
执行用户消息相关操作。
Creates a simple user message with plain text content.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
id | String | 消息标识。The message ID |
content | String | 内容(类型 `String`)。The message content as plain text |
AguiMessageio/agentscope/core/agui/model/AguiMessage.java:83–85userMessage
public static AguiMessage userMessage(String id, List<InputContent> blocks)
执行用户消息相关操作。
Creates a user message with structured content blocks.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
id | String | 消息标识。The message ID |
blocks | List<InputContent> | 内容块列表(类型 `List`)。The structured content parts |
AguiMessageio/agentscope/core/agui/model/AguiMessage.java:94–96assistantMessage
public static AguiMessage assistantMessage(String id, String content)
执行 assistantMessage 方法。
Creates a simple assistant message.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
id | String | 消息标识。The message ID |
content | String | 内容(类型 `String`)。The message content as plain text |
AguiMessageio/agentscope/core/agui/model/AguiMessage.java:105–107systemMessage
public static AguiMessage systemMessage(String id, String content)
创建系统消息。
Creates a system message.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
id | String | 消息标识。The message ID |
content | String | 内容(类型 `String`)。The message content as plain text |
AguiMessageio/agentscope/core/agui/model/AguiMessage.java:116–118toolMessage
public static AguiMessage toolMessage(String id, String toolCallId, String content)
创建工具结果消息。
Creates a tool result message.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
id | String | 消息标识。The message ID |
toolCallId | String | 工具调用标识(类型 `String`)。The ID of the tool call this is responding to |
content | String | 内容(类型 `String`)。The tool result content as plain text |
AguiMessageio/agentscope/core/agui/model/AguiMessage.java:128–130textMessage
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.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
id | String | 消息标识。The message ID |
role | String | 角色(类型 `String`)。The message role (user, assistant, system, tool) |
text | String | 文本(类型 `String`)。The message content as plain text, may be null |
toolCalls | List<AguiToolCall> | 工具调用(类型 `List`)。Tool calls for assistant messages (optional) |
toolCallId | String | 用于工具消息(可选)的工具调用标识。Tool call ID for tool messages (optional) |
AguiMessageio/agentscope/core/agui/model/AguiMessage.java:143–146blocksMessage
public static AguiMessage blocksMessage(String id, String role, List<InputContent> blocks, List<AguiToolCall> toolCalls, String toolCallId)
执行 blocksMessage 方法。
Creates a message with structured content blocks, supporting a custom role, tool calls, and tool call ID.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
id | String | 消息标识。The message ID |
role | String | 角色(类型 `String`)。The message role (user, assistant, system, tool) |
blocks | List<InputContent> | 内容块列表(类型 `List`)。The structured content parts |
toolCalls | List<AguiToolCall> | 工具调用(类型 `List`)。Tool calls for assistant messages (optional) |
toolCallId | String | 用于工具消息(可选)的工具调用标识。Tool call ID for tool messages (optional) |
AguiMessageio/agentscope/core/agui/model/AguiMessage.java:159–166getId
public String getId()
获取消息标识。
Get the message ID.
Stringio/agentscope/core/agui/model/AguiMessage.java:183–185getRole
public String getRole()
获取消息角色。
Get the message role.
Stringio/agentscope/core/agui/model/AguiMessage.java:192–194getContent
public MessageContent getContent()
获取内容。
Get the message content as a type-safe MessageContent.
MessageContentio/agentscope/core/agui/model/AguiMessage.java:201–203getTextContent
public String getTextContent()
获取文本内容。
Get the plain text content if the content is a MessageContent.Text.
Stringio/agentscope/core/agui/model/AguiMessage.java:213–218hasBlocks
public boolean hasBlocks()
判断是否具有 hasBlocks。
Check if this message has structured content blocks.
booleanio/agentscope/core/agui/model/AguiMessage.java:225–227getToolCalls
public List<AguiToolCall> getToolCalls()
获取工具调用。
Get the tool calls (for assistant messages).
List<AguiToolCall>io/agentscope/core/agui/model/AguiMessage.java:234–236getToolCallId
public String getToolCallId()
获取工具调用标识(用于工具消息)。
Get the tool call ID (for tool messages).
Stringio/agentscope/core/agui/model/AguiMessage.java:243–245isUserMessage
public boolean isUserMessage()
检查if 此是用户消息。
Check if this is a user message.
booleanio/agentscope/core/agui/model/AguiMessage.java:252–254isAssistantMessage
public boolean isAssistantMessage()
判断是否 isAssistantMessage。
Check if this is an assistant message.
booleanio/agentscope/core/agui/model/AguiMessage.java:261–263isSystemMessage
public boolean isSystemMessage()
检查if 此是系统消息。
Check if this is a system message.
booleanio/agentscope/core/agui/model/AguiMessage.java:270–272isToolMessage
public boolean isToolMessage()
检查if 此是工具消息。
Check if this is a tool message.
booleanio/agentscope/core/agui/model/AguiMessage.java:279–281hasToolCalls
public boolean hasToolCalls()
检查if 此消息有工具调用。
Check if this message has tool calls.
booleanio/agentscope/core/agui/model/AguiMessage.java:288–290toString
public String toString()
返回 toString 结果。
Returns the to string.
Stringio/agentscope/core/agui/model/AguiMessage.java:292–305equals
public boolean equals(Object o)
设置该参数。
Performs the equals operation.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
o | Object | o(类型 `Object`)。The o. |
booleanio/agentscope/core/agui/model/AguiMessage.java:307–317hashCode
public int hashCode()
返回 hashCode 结果。
Returns the hash code.
intio/agentscope/core/agui/model/AguiMessage.java:319–322