AS AgentScopeAPI 手册 / API Reference

AguiMessage

public class AguiMessage
源码Source 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

方法Method说明Description
public static AguiMessage userMessage(String id, String content)
static
执行用户消息相关操作。
Creates a simple user message with plain text content.
public static AguiMessage userMessage(String id, List<InputContent> blocks)
static
执行用户消息相关操作。
Creates a user message with structured content blocks.
public static AguiMessage assistantMessage(String id, String content)
static
执行 `assistantMessage` 方法。
Creates a simple assistant message.
public static AguiMessage systemMessage(String id, String content)
static
创建系统消息。
Creates a system message.
public static AguiMessage toolMessage(String id, String toolCallId, String content)
static
创建工具结果消息。
Creates a tool result message.
public static AguiMessage textMessage(String id, String role, String text, List<AguiToolCall> toolCalls, String toolCallId)
static
执行文本消息相关操作。
Creates a message with plain text content, supporting a custom role, tool calls, and tool call ID.
public static AguiMessage blocksMessage(String id, String role, List<InputContent> blocks, List<AguiToolCall> toolCalls, String toolCallId)
static
执行 `blocksMessage` 方法。
Creates a message with structured content blocks, supporting a custom role, tool calls, and tool call ID.
public String getId()
获取消息标识。
Get the message ID.
public String getRole()
获取消息角色。
Get the message role.
public MessageContent getContent()
获取内容。
Get the message content as a type-safe `MessageContent`.
public String getTextContent()
获取文本内容。
Get the plain text content if the content is a `MessageContent.Text`.
public boolean hasBlocks()
判断是否具有 `hasBlocks`。
Check if this message has structured content blocks.
public List<AguiToolCall> getToolCalls()
获取工具调用。
Get the tool calls (for assistant messages).
public String getToolCallId()
获取工具调用标识(用于工具消息)。
Get the tool call ID (for tool messages).
public boolean isUserMessage()
检查if 此是用户消息。
Check if this is a user message.
public boolean isAssistantMessage()
判断是否 `isAssistantMessage`。
Check if this is an assistant message.
public boolean isSystemMessage()
检查if 此是系统消息。
Check if this is a system message.
public boolean isToolMessage()
检查if 此是工具消息。
Check if this is a tool message.
public boolean hasToolCalls()
检查if 此消息有工具调用。
Check if this message has tool calls.
public String toString()
返回 `toString` 结果。
Returns the to string.
public boolean equals(Object o)
设置该参数。
Performs the equals operation.
public int hashCode()
返回 `hashCode` 结果。
Returns the hash code.

构造器详情Constructor Detail

AguiMessage

public AguiMessage(String id, String role, MessageContent content, List<AguiToolCall> toolCalls, String toolCallId)

创建新的AguiMessage。

Creates a new AguiMessage.

参数Parameters
名称Name类型Type说明Description
idString标识(类型 `String`)。The unique message ID
roleString角色(类型 `String`)。The message role (user, assistant, system, tool)
contentMessageContent内容(类型 `MessageContent`)。The message content (plain text or structured blocks), may be null
toolCallsList<AguiToolCall>工具调用(类型 `List`)。Tool calls for assistant messages (optional)
toolCallIdString用于工具消息(可选)的工具调用标识。Tool call ID for tool messages (optional)
源码Source io/agentscope/core/agui/model/AguiMessage.java:59–74

方法详情Method Detail

userMessage

public static AguiMessage userMessage(String id, String content)
static

执行用户消息相关操作。

Creates a simple user message with plain text content.

参数Parameters
名称Name类型Type说明Description
idString消息标识。The message ID
contentString内容(类型 `String`)。The message content as plain text
返回Returns AguiMessage
一种新的用户消息。A new user message
源码Source io/agentscope/core/agui/model/AguiMessage.java:83–85

userMessage

public static AguiMessage userMessage(String id, List<InputContent> blocks)
static

执行用户消息相关操作。

Creates a user message with structured content blocks.

参数Parameters
名称Name类型Type说明Description
idString消息标识。The message ID
blocksList<InputContent>内容块列表(类型 `List`)。The structured content parts
返回Returns AguiMessage
一种新的用户消息。A new user message
源码Source io/agentscope/core/agui/model/AguiMessage.java:94–96

assistantMessage

public static AguiMessage assistantMessage(String id, String content)
static

执行 assistantMessage 方法。

Creates a simple assistant message.

参数Parameters
名称Name类型Type说明Description
idString消息标识。The message ID
contentString内容(类型 `String`)。The message content as plain text
返回Returns AguiMessage
返回AguiMessage。A new assistant message
源码Source io/agentscope/core/agui/model/AguiMessage.java:105–107

systemMessage

public static AguiMessage systemMessage(String id, String content)
static

创建系统消息。

Creates a system message.

参数Parameters
名称Name类型Type说明Description
idString消息标识。The message ID
contentString内容(类型 `String`)。The message content as plain text
返回Returns AguiMessage
一种新的系统消息。A new system message
源码Source io/agentscope/core/agui/model/AguiMessage.java:116–118

toolMessage

public static AguiMessage toolMessage(String id, String toolCallId, String content)
static

创建工具结果消息。

Creates a tool result message.

参数Parameters
名称Name类型Type说明Description
idString消息标识。The message ID
toolCallIdString工具调用标识(类型 `String`)。The ID of the tool call this is responding to
contentString内容(类型 `String`)。The tool result content as plain text
返回Returns AguiMessage
一种新的工具消息。A new tool message
源码Source io/agentscope/core/agui/model/AguiMessage.java:128–130

textMessage

public static AguiMessage textMessage(String id, String role, String text, List<AguiToolCall> toolCalls, String toolCallId)
static

执行文本消息相关操作。

Creates a message with plain text content, supporting a custom role, tool calls, and tool call ID.

参数Parameters
名称Name类型Type说明Description
idString消息标识。The message ID
roleString角色(类型 `String`)。The message role (user, assistant, system, tool)
textString文本(类型 `String`)。The message content as plain text, may be null
toolCallsList<AguiToolCall>工具调用(类型 `List`)。Tool calls for assistant messages (optional)
toolCallIdString用于工具消息(可选)的工具调用标识。Tool call ID for tool messages (optional)
返回Returns AguiMessage
一种新的消息。A new message
源码Source io/agentscope/core/agui/model/AguiMessage.java:143–146

blocksMessage

public static AguiMessage blocksMessage(String id, String role, List<InputContent> blocks, List<AguiToolCall> toolCalls, String toolCallId)
static

执行 blocksMessage 方法。

Creates a message with structured content blocks, supporting a custom role, tool calls, and tool call ID.

参数Parameters
名称Name类型Type说明Description
idString消息标识。The message ID
roleString角色(类型 `String`)。The message role (user, assistant, system, tool)
blocksList<InputContent>内容块列表(类型 `List`)。The structured content parts
toolCallsList<AguiToolCall>工具调用(类型 `List`)。Tool calls for assistant messages (optional)
toolCallIdString用于工具消息(可选)的工具调用标识。Tool call ID for tool messages (optional)
返回Returns AguiMessage
一种新的消息。A new message
源码Source io/agentscope/core/agui/model/AguiMessage.java:159–166

getId

public String getId()

获取消息标识。

Get the message ID.

返回Returns String
消息标识。The message ID
源码Source io/agentscope/core/agui/model/AguiMessage.java:183–185

getRole

public String getRole()

获取消息角色。

Get the message role.

返回Returns String
返回字符串结果。The role (user, assistant, system, tool)
源码Source io/agentscope/core/agui/model/AguiMessage.java:192–194

getContent

public MessageContent getContent()

获取内容。

Get the message content as a type-safe MessageContent.

返回Returns MessageContent
返回MessageContent。The content, may be null
源码Source io/agentscope/core/agui/model/AguiMessage.java:201–203

getTextContent

public String getTextContent()

获取文本内容。

Get the plain text content if the content is a MessageContent.Text.

返回Returns String
返回字符串结果。The text value, or null if content is not plain text
源码Source io/agentscope/core/agui/model/AguiMessage.java:213–218

hasBlocks

public boolean hasBlocks()

判断是否具有 hasBlocks。

Check if this message has structured content blocks.

返回Returns boolean
返回布尔值,表示判断结果。true if the content is a `MessageContent.Blocks`
源码Source io/agentscope/core/agui/model/AguiMessage.java:225–227

getToolCalls

public List<AguiToolCall> getToolCalls()

获取工具调用。

Get the tool calls (for assistant messages).

返回Returns List<AguiToolCall>
返回列出。The tool calls as an immutable list, empty if none
源码Source io/agentscope/core/agui/model/AguiMessage.java:234–236

getToolCallId

public String getToolCallId()

获取工具调用标识(用于工具消息)。

Get the tool call ID (for tool messages).

返回Returns String
返回字符串结果。The tool call ID, or null if not a tool message
源码Source io/agentscope/core/agui/model/AguiMessage.java:243–245

isUserMessage

public boolean isUserMessage()

检查if 此是用户消息。

Check if this is a user message.

返回Returns boolean
返回布尔值,表示判断结果。true if role is "user"
源码Source io/agentscope/core/agui/model/AguiMessage.java:252–254

isAssistantMessage

public boolean isAssistantMessage()

判断是否 isAssistantMessage。

Check if this is an assistant message.

返回Returns boolean
返回布尔值,表示判断结果。true if role is "assistant"
源码Source io/agentscope/core/agui/model/AguiMessage.java:261–263

isSystemMessage

public boolean isSystemMessage()

检查if 此是系统消息。

Check if this is a system message.

返回Returns boolean
返回布尔值,表示判断结果。true if role is "system"
源码Source io/agentscope/core/agui/model/AguiMessage.java:270–272

isToolMessage

public boolean isToolMessage()

检查if 此是工具消息。

Check if this is a tool message.

返回Returns boolean
返回布尔值,表示判断结果。true if role is "tool"
源码Source io/agentscope/core/agui/model/AguiMessage.java:279–281

hasToolCalls

public boolean hasToolCalls()

检查if 此消息有工具调用。

Check if this message has tool calls.

返回Returns boolean
返回布尔值,表示判断结果。true if tool calls are present
源码Source io/agentscope/core/agui/model/AguiMessage.java:288–290

toString

public String toString()

返回 toString 结果。

Returns the to string.

返回Returns String
返回字符串结果。Returns a string.
源码Source io/agentscope/core/agui/model/AguiMessage.java:292–305

equals

public boolean equals(Object o)

设置该参数。

Performs the equals operation.

参数Parameters
名称Name类型Type说明Description
oObjecto(类型 `Object`)。The o.
返回Returns boolean
返回布尔值,表示判断结果。Returns a boolean result.
源码Source io/agentscope/core/agui/model/AguiMessage.java:307–317

hashCode

public int hashCode()

返回 hashCode 结果。

Returns the hash code.

返回Returns int
返回数值结果。Returns a numeric result.
源码Source io/agentscope/core/agui/model/AguiMessage.java:319–322
基于官方固定版本源码静态生成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.