AS AgentScopeAPI 手册 / API Reference

Builder

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

方法Method说明Description
public Builder id(String id)
设置标识。
Sets the unique identifier for the message.
public Builder name(String name)
设置可选名称用于消息。
Sets the optional name for the message.
public Builder role(MsgRole role)
设置角色用于消息。
Sets the role for the message.
public Builder content(List<ContentBlock> content)
设置内容。
Set content from a list of content blocks.
public Builder content(ContentBlock block)
设置内容。
Set content from a single content block (convenience method).
public Builder content(ContentBlock... blocks)
设置内容。
Set content from varargs content blocks (convenience method).
public Builder textContent(String text)
设置文本内容。
Set text content from a string.
public Builder metadata(Map<String, Object> metadata)
设置元数据用于结构化输出。
Set metadata for structured output.
public Builder timestamp(String timestamp)
设置时间戳用于消息。
Sets the timestamp for the message.
public Builder usage(ChatUsage usage)
设置用量。
Sets the token usage information for this message.
public Builder generateReason(GenerateReason reason)
设置该配置项。
Performs the generate reason operation.
public Msg build()
构建并返回最终实例。
Builds a new message instance with the configured properties.

字段详情Field Detail

id

protected String id

标识字段。声明为 protected String id。

The id field.

源码Source io/agentscope/core/message/Msg.java:717

name

protected String name

名称字段。声明为 protected String name。

The name field.

源码Source io/agentscope/core/message/Msg.java:719

role

protected MsgRole role

角色字段。声明为 protected MsgRole role。

The role field.

源码Source io/agentscope/core/message/Msg.java:721

content

protected List<ContentBlock> content

内容字段。声明为 protected List content。

The content field.

源码Source io/agentscope/core/message/Msg.java:723

metadata

protected Map<String, Object> metadata

元数据字段。声明为 protected Map metadata。

The metadata field.

源码Source io/agentscope/core/message/Msg.java:725

timestamp

protected String timestamp

时间戳字段。声明为 protected String timestamp。

The timestamp field.

源码Source io/agentscope/core/message/Msg.java:727

usage

protected ChatUsage usage

用量字段。声明为 protected ChatUsage usage。

The usage field.

源码Source io/agentscope/core/message/Msg.java:729

构造器详情Constructor Detail

Builder

public Builder()

初始化 Builder 实例。

Creates a new builder with a randomly generated message ID.

源码Source io/agentscope/core/message/Msg.java:734–736

方法详情Method Detail

id

public Builder id(String id)

设置标识。

Sets the unique identifier for the message.

参数Parameters
名称Name类型Type说明Description
idString消息标识。The message ID
返回Returns Builder
返回当前实例,以支持链式调用。This builder for chaining
源码Source io/agentscope/core/message/Msg.java:744–747

name

public Builder name(String name)

设置可选名称用于消息。

Sets the optional name for the message.

参数Parameters
名称Name类型Type说明Description
nameString消息名称。The message name
返回Returns Builder
返回当前实例,以支持链式调用。This builder for chaining
源码Source io/agentscope/core/message/Msg.java:762–765

role

public Builder role(MsgRole role)

设置角色用于消息。

Sets the role for the message.

参数Parameters
名称Name类型Type说明Description
roleMsgRole角色(类型 `MsgRole`)。The message role (user, assistant, system, or tool)
返回Returns Builder
返回当前实例,以支持链式调用。This builder for chaining
源码Source io/agentscope/core/message/Msg.java:773–776

content

public Builder content(List<ContentBlock> content)

设置内容。

Set content from a list of content blocks.

参数Parameters
名称Name类型Type说明Description
contentList<ContentBlock>内容(类型 `List`)。List of content blocks
返回Returns Builder
返回当前实例,以支持链式调用。This builder
源码Source io/agentscope/core/message/Msg.java:783–786

content

public Builder content(ContentBlock block)

设置内容。

Set content from a single content block (convenience method).

参数Parameters
名称Name类型Type说明Description
blockContentBlock内容块(类型 `ContentBlock`)。Single content block
返回Returns Builder
返回当前实例,以支持链式调用。This builder
源码Source io/agentscope/core/message/Msg.java:794–797

content

public Builder content(ContentBlock... blocks)

设置内容。

Set content from varargs content blocks (convenience method).

参数Parameters
名称Name类型Type说明Description
blocks varargsContentBlock...内容块列表(类型 `ContentBlock...`)。Content blocks
返回Returns Builder
返回当前实例,以支持链式调用。This builder
源码Source io/agentscope/core/message/Msg.java:804–807

textContent

public Builder textContent(String text)

设置文本内容。

Set text content from a string.

参数Parameters
名称Name类型Type说明Description
textString文本(类型 `String`)。Text content
返回Returns Builder
返回当前实例,以支持链式调用。This builder
源码Source io/agentscope/core/message/Msg.java:814–817

metadata

public Builder metadata(Map<String, Object> metadata)

设置元数据用于结构化输出。

Set metadata for structured output.

参数Parameters
名称Name类型Type说明Description
metadataMap<String, Object>元数据(类型 `Map`)。Metadata map
返回Returns Builder
返回当前实例,以支持链式调用。This builder
源码Source io/agentscope/core/message/Msg.java:824–827

timestamp

public Builder timestamp(String timestamp)

设置时间戳用于消息。

Sets the timestamp for the message.

参数Parameters
名称Name类型Type说明Description
timestampString时间戳(类型 `String`)。The timestamp string
返回Returns Builder
返回当前实例,以支持链式调用。This builder for chaining
源码Source io/agentscope/core/message/Msg.java:835–839

usage

public Builder usage(ChatUsage usage)

设置用量。

Sets the token usage information for this message.

参数Parameters
名称Name类型Type说明Description
usageChatUsage用量(类型 `ChatUsage`)。The ChatUsage containing token counts
返回Returns Builder
返回当前实例,以支持链式调用。This builder for chaining
源码Source io/agentscope/core/message/Msg.java:856–859

generateReason

public Builder generateReason(GenerateReason reason)

设置该配置项。

Performs the generate reason operation.

参数Parameters
名称Name类型Type说明Description
reasonGenerateReason原因(类型 `GenerateReason`)。The reason.
返回Returns Builder
返回当前实例,以支持链式调用。Returns the current instance for chaining.
源码Source io/agentscope/core/message/Msg.java:861–871

build

public Msg build()

构建并返回最终实例。

Builds a new message instance with the configured properties.

返回Returns Msg
一种新的不可变消息。A new immutable message
源码Source io/agentscope/core/message/Msg.java:879–881
基于官方固定版本源码静态生成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.