AS AgentScopeAPI 手册 / API Reference
包package agentscope.message

agentscope.message

module agentscope.message

agentscope.message 属于消息·事件·格式化,统一消息模型与协议转换。 该包共收录 17 个公开类型。

The message module in agentscope.

源码Source agentscope/message/__init__.py:1

类Classes

Base64Source
类class
base64 来源。
The base64 source.
DataBlock
类class
数据块,在智能体、模型与前端之间传递结构化消息和事件。
The data block for binary content (images, audio, video, etc.).
HintBlock
类class
Hint 块,在智能体、模型与前端之间传递结构化消息和事件。
A block used to provide instructions or hints to the LLM during the reasoning-acting loop. When passed to the LLM API, the hint block is converted into a user message.
Msg
类class
统一消息对象
The message class in AgentScope, responsible for information storage and transmission among different agents.
TextBlock
类class
文本块。
The text block.
ThinkingBlock
类class
Thinking 块,在智能体、模型与前端之间传递结构化消息和事件。
The thinking block.
ToolCallBlock
类class
工具调用块。
The tool call block.
ToolCallState
类class
工具调用的状态。
The state of the tool call.
ToolResultBlock
类class
工具结果块。
The tool result block.
ToolResultState
类class
工具结果状态。
The tool result state.
URLSource
类class
URL 来源。
The URL source.
Usage
类class
用量,在智能体、模型与前端之间传递结构化消息和事件。
The token usage information of a message.

函数Functions

AssistantMsg
函数function
构造助手消息
Create an assistant message with role ``"assistant"``.
SystemMsg
函数function
构造系统消息
Create a system message with role ``"system"``.
UserMsg
函数function
构造用户消息
Create a user message with role ``"user"``.

属性Attributes

ContentBlock
字段attribute
—
ContentBlockTypes
字段attribute
—

函数详情Function Details

AssistantMsg

def AssistantMsg(name: str, content: str | list[ContentBlock], metadata: dict | None = None, created_at: str | None = None, finished_at: str | None = None, finished_reason: ReplyFinishedReason | None = None, structured_output: dict | None = None, id: str | None = None, usage: Usage | None = None) -> Msg

创建角色为 assistant 的消息,内容可以是文本或多模态内容块。

Create an assistant message with role "assistant".

参数Parameters
名称Name类型Type说明Description
namestr名称(类型 `str`)。The name of the sender.
contentstr | list[ContentBlock]内容(类型 `str | list[ContentBlock]`)。The message content. A plain string will be automatically wrapped in a :class:`TextBlock`. Any :class:`ContentBlock` subtype is permitted for assistant messages.
metadata默认default Nonedict | None元数据(类型 `dict | None`)。Arbitrary key-value metadata attached to the message. Defaults to an empty dict when not provided.
created_at默认default Nonestr | None已创建 at(类型 `str | None`)。ISO-format timestamp for when the message was created. Defaults to the current time when not provided.
finished_at默认default Nonestr | Nonefinished at(类型 `str | None`)。ISO-format timestamp for when the message was finished. Not set by default for assistant messages.
finished_reason默认default NoneReplyFinishedReason | Nonefinished 推理(类型 `ReplyFinishedReason | None`)。The finished reason for the assistant message.
structured_output默认default Nonedict | None结构化输出(类型 `dict | None`)。The structured output carried by the assistant message.
id默认default Nonestr | None标识(类型 `str | None`)。A unique identifier for the message. A random UUID hex string is generated when not provided.
usage默认default NoneUsage | None用量(类型 `Usage | None`)。The token usage information of the message.
返回Returns Msg
返回消息。`Msg`:
源码Source agentscope/message/_base.py:622–676

SystemMsg

def SystemMsg(name: str, content: str | list[TextBlock], metadata: dict | None = None, created_at: str | None = None, finished_at: str | None = None, finished_reason: ReplyFinishedReason | None = None, id: str | None = None) -> Msg

创建角色为 system 的消息,用于注入系统提示词与全局约束。

Create a system message with role "system".

参数Parameters
名称Name类型Type说明Description
namestr名称(类型 `str`)。The name of the sender.
contentstr | list[TextBlock]内容(类型 `str | list[TextBlock]`)。The message content. A plain string will be automatically wrapped in a :class:`TextBlock`. Only :class:`TextBlock` is allowed for system messages.
metadata默认default Nonedict | None元数据(类型 `dict | None`)。Arbitrary key-value metadata attached to the message. Defaults to an empty dict when not provided.
created_at默认default Nonestr | None已创建 at(类型 `str | None`)。ISO-format timestamp for when the message was created. Defaults to the current time when not provided.
finished_at默认default Nonestr | Nonefinished at(类型 `str | None`)。ISO-format timestamp for when the message was finished. Defaults to the same value as `created_at` when not provided.
finished_reason默认default NoneReplyFinishedReason | Nonefinished 推理(类型 `ReplyFinishedReason | None`)。The finished reason for the system message.
id默认default Nonestr | None标识(类型 `str | None`)。A unique identifier for the message. A random UUID hex string is generated when not provided.
返回Returns Msg
返回消息。`Msg`:
源码Source agentscope/message/_base.py:679–728

UserMsg

def UserMsg(name: str, content: str | list[TextBlock | DataBlock], metadata: dict | None = None, created_at: str | None = None, finished_at: str | None = None, finished_reason: ReplyFinishedReason | None = None, id: str | None = None) -> Msg

创建角色为 user 的消息,用于承载用户输入与多模态内容。

Create a user message with role "user".

参数Parameters
名称Name类型Type说明Description
namestr名称(类型 `str`)。The name of the sender.
contentstr | list[TextBlock | DataBlock]内容(类型 `str | list[TextBlock | DataBlock]`)。The message content. A plain string will be automatically wrapped in a :class:`TextBlock`. Only :class:`TextBlock` and :class:`DataBlock` are allowed for user messages.
metadata默认default Nonedict | None元数据(类型 `dict | None`)。Arbitrary key-value metadata attached to the message. Defaults to an empty dict when not provided.
created_at默认default Nonestr | None已创建 at(类型 `str | None`)。ISO-format timestamp for when the message was created. Defaults to the current time when not provided.
finished_at默认default Nonestr | Nonefinished at(类型 `str | None`)。ISO-format timestamp for when the message was finished. Defaults to the same value as `created_at` when not provided.
finished_reason默认default NoneReplyFinishedReason | Nonefinished 推理(类型 `ReplyFinishedReason | None`)。The reason the message was finished. Defaults to `None` when not provided.
id默认default Nonestr | None标识(类型 `str | None`)。A unique identifier for the message. A random UUID hex string is generated when not provided.
返回Returns Msg
返回消息。`Msg`:
源码Source agentscope/message/_base.py:569–619

属性详情Attribute Details

ContentBlock

TypeAlias = TextBlock | ThinkingBlock | HintBlock | ToolCallBlock | ToolResultBlock | DataBlock

内容块字段。声明为 TypeAlias。

The content block field.

源码Source agentscope/message/_block.py:219

ContentBlockTypes

TypeAlias = Literal['text', 'thinking', 'hint', 'tool_call', 'tool_result', 'data']

内容块类型字段。声明为 TypeAlias。

The content block types field.

源码Source agentscope/message/_block.py:228
基于官方固定版本源码静态生成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.