Builder
public static class Builder
io/agentscope/core/message/Msg.java:715–882构建器,用于构建并配置目标实例。位于 io.agentscope.core.message 包。核心成员包括 id、name、role、content、textContent、metadata。
A class in io.agentscope.core.message that carries structured messages and events between agents, models and UIs. Declared in io.agentscope.core.message.
字段摘要Field Summary
| 字段Field | 类型Type | 说明Description |
|---|---|---|
id | String | 标识字段。 The id field. |
name | String | 名称字段。 The name field. |
role | MsgRole | 角色字段。 The role field. |
content | List<ContentBlock> | 内容字段。 The content field. |
metadata | Map<String, Object> | 元数据字段。 The metadata field. |
timestamp | String | 时间戳字段。 The timestamp field. |
usage | ChatUsage | 用量字段。 The usage field. |
构造器摘要Constructor Summary
| 构造器Constructor | 说明Description |
|---|---|
public Builder() | 初始化 `Builder` 实例。 Creates a new builder with a randomly generated message ID. |
方法摘要Method Summary
字段详情Field Detail
id
protected String id
标识字段。声明为 protected String id。
The id field.
io/agentscope/core/message/Msg.java:717name
protected String name
名称字段。声明为 protected String name。
The name field.
io/agentscope/core/message/Msg.java:719role
protected MsgRole role
角色字段。声明为 protected MsgRole role。
The role field.
io/agentscope/core/message/Msg.java:721content
protected List<ContentBlock> content
内容字段。声明为 protected List content。
The content field.
io/agentscope/core/message/Msg.java:723metadata
protected Map<String, Object> metadata
元数据字段。声明为 protected Map metadata。
The metadata field.
io/agentscope/core/message/Msg.java:725timestamp
protected String timestamp
时间戳字段。声明为 protected String timestamp。
The timestamp field.
io/agentscope/core/message/Msg.java:727usage
protected ChatUsage usage
用量字段。声明为 protected ChatUsage usage。
The usage field.
io/agentscope/core/message/Msg.java:729构造器详情Constructor Detail
Builder
public Builder()
初始化 Builder 实例。
Creates a new builder with a randomly generated message ID.
io/agentscope/core/message/Msg.java:734–736方法详情Method Detail
id
public Builder id(String id)
设置标识。
Sets the unique identifier for the message.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
id | String | 消息标识。The message ID |
Builderio/agentscope/core/message/Msg.java:744–747name
public Builder name(String name)
设置可选名称用于消息。
Sets the optional name for the message.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
name | String | 消息名称。The message name |
Builderio/agentscope/core/message/Msg.java:762–765role
public Builder role(MsgRole role)
设置角色用于消息。
Sets the role for the message.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
role | MsgRole | 角色(类型 `MsgRole`)。The message role (user, assistant, system, or tool) |
Builderio/agentscope/core/message/Msg.java:773–776content
public Builder content(List<ContentBlock> content)
设置内容。
Set content from a list of content blocks.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
content | List<ContentBlock> | 内容(类型 `List`)。List of content blocks |
Builderio/agentscope/core/message/Msg.java:783–786content
public Builder content(ContentBlock block)
设置内容。
Set content from a single content block (convenience method).
| 名称Name | 类型Type | 说明Description |
|---|---|---|
block | ContentBlock | 内容块(类型 `ContentBlock`)。Single content block |
Builderio/agentscope/core/message/Msg.java:794–797content
public Builder content(ContentBlock... blocks)
设置内容。
Set content from varargs content blocks (convenience method).
| 名称Name | 类型Type | 说明Description |
|---|---|---|
blocks varargs | ContentBlock... | 内容块列表(类型 `ContentBlock...`)。Content blocks |
Builderio/agentscope/core/message/Msg.java:804–807textContent
public Builder textContent(String text)
设置文本内容。
Set text content from a string.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
text | String | 文本(类型 `String`)。Text content |
Builderio/agentscope/core/message/Msg.java:814–817metadata
public Builder metadata(Map<String, Object> metadata)
设置元数据用于结构化输出。
Set metadata for structured output.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
metadata | Map<String, Object> | 元数据(类型 `Map`)。Metadata map |
Builderio/agentscope/core/message/Msg.java:824–827timestamp
public Builder timestamp(String timestamp)
设置时间戳用于消息。
Sets the timestamp for the message.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
timestamp | String | 时间戳(类型 `String`)。The timestamp string |
Builderio/agentscope/core/message/Msg.java:835–839usage
public Builder usage(ChatUsage usage)
设置用量。
Sets the token usage information for this message.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
usage | ChatUsage | 用量(类型 `ChatUsage`)。The ChatUsage containing token counts |
Builderio/agentscope/core/message/Msg.java:856–859generateReason
public Builder generateReason(GenerateReason reason)
设置该配置项。
Performs the generate reason operation.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
reason | GenerateReason | 原因(类型 `GenerateReason`)。The reason. |
Builderio/agentscope/core/message/Msg.java:861–871build
public Msg build()
构建并返回最终实例。
Builds a new message instance with the configured properties.
Msgio/agentscope/core/message/Msg.java:879–881