AS AgentScopeAPI 手册 / API Reference
类class agentscope.tui

MessagesUI

class MessagesUI(VerticalScroll)
源码Source agentscope/tui/_messages.py:705–950

消息 UI,为框架提供通用类型与基础能力。位于 agentscope.tui 包,继承自 VerticalScroll。核心成员包括 current_messages、compose、set_messages、update_message、messages。

Render authoritative message snapshots without consuming events. Declared in agentscope.tui. Extends VerticalScroll.

构造器摘要Constructor Summary

构造器Constructor说明Description
def __init__(messages: Sequence[Msg] = (), *, show_thinking: bool = True, show_usage: bool = False, id: str | None = No…
初始化 `MessagesUI` 实例。
Creates a new instance.

属性摘要Property Summary

属性Property说明Description
messages
获取消息。
A safe snapshot of the messages currently being rendered.

属性摘要Attribute Summary

属性Attribute类型Type说明Description值Value
DEFAULT_CSS—
默认 CSS字段。
'\n MessagesUI {\n width: 100%;\n height: 1fr;\n scrollbar-visibility: hidden;\n padding: 0;\n background: transparent;\n }\n\n MessageUI {\n width: 100%;\n height: auto;\n margin: 0;\n padding: 0;\n }\n\n .as-message-user {\n margin-left: 0;\n background: transparent;\n }\n\n .as-message-assistant {\n margin-right: 0;\n background: transparent;\n }\n\n .as-message-header {\n height: 1;\n margin-bottom: 1;\n color: $text-muted;\n text-style: bold;\n }\n\n .as-message-user > .as-message-header {\n color: $foreground;\n }\n\n .as-message-assistant > .as-message-header {\n color: $foreground;\n }\n\n .as-message-footer {\n height: auto;\n color: $text-muted;\n margin-top: 1;\n }\n\n .as-text-block, .as-thinking, .as-tool-group, .as-hint {\n width: 100%;\n height: auto;\n }\n\n .as-text-block {\n padding: 0;\n background: transparent;\n }\n\n .as-thinking, .as-tool-group, .as-hint {\n background: transparent;\n border-top: none;\n padding: 0;\n margin: 0 0 1 0;\n }\n\n .as-thinking:ansi, .as-tool-group:ansi, .as-hint:ansi {\n background: transparent;\n border-top: none;\n }\n\n .as-thinking > CollapsibleTitle,\n .as-tool-group > CollapsibleTitle,\n .as-hint > CollapsibleTitle {\n width: 100%;\n padding: 0 1;\n background: transparent;\n text-style: none;\n }\n\n .as-thinking > CollapsibleTitle,\n .as-hint > CollapsibleTitle {\n color: $text-muted;\n }\n\n .as-tool-group > CollapsibleTitle {\n width: auto;\n padding-left: 0;\n }\n\n .as-thinking > CollapsibleTitle:hover,\n .as-thinking > CollapsibleTitle:focus,\n .as-tool-group > CollapsibleTitle:hover,\n .as-tool-group > CollapsibleTitle:focus,\n .as-hint > CollapsibleTitle:hover,\n .as-hint > CollapsibleTitle:focus {\n background: transparent;\n color: #d8b66f;\n text-style: bold;\n }\n\n .as-thinking > Contents,\n .as-tool-group > Contents,\n .as-hint > Contents {\n height: auto;\n padding: 0 0 0 2;\n }\n\n .as-tool-list {\n width: 100%;\n height: auto;\n }\n\n .as-thinking-body, .as-hint-body {\n padding: 0;\n background: transparent;\n }\n\n .as-tool-call {\n width: 100%;\n height: auto;\n margin-top: 1;\n }\n\n .as-tool-call-title {\n width: 100%;\n height: 1;\n color: $foreground;\n }\n\n .as-tool-body {\n width: 100%;\n height: auto;\n padding-left: 1;\n color: $text-muted;\n background: transparent;\n }\n\n .as-attachment {\n width: 100%;\n height: auto;\n margin-top: 1;\n padding-left: 2;\n color: $text-muted;\n }\n '

方法摘要Method Summary

方法Method说明Description
def current_messages() -> tuple[Msg, ...]
返回当前消息。
Return live messages for coordinated sibling UI components.
def compose() -> ComposeResult
返回 `compose` 结果。
Performs the compose operation.
async def set_messages(messages: Sequence[Msg]) -> Noneasync
设置消息。
Reconcile an authoritative full conversation snapshot.
async def update_message(message: Msg) -> Noneasync
更新消息。
Update one message by ID, appending it if it is new.

构造器详情Constructor Detail

MessagesUI

def __init__(messages: Sequence[Msg] = (), *, show_thinking: bool = True, show_usage: bool = False, id: str | None = None, classes: str | None = None, disabled: bool = False) -> None

初始化 MessagesUI 实例。

Creates a new instance.

参数Parameters
名称Name类型Type说明Description
messages默认default ()Sequence[Msg]消息列表(类型 `Sequence[Msg]`)。The messages.
show_thinkingkw默认default Trueboolshow thinking(类型 `bool`)。The show thinking.
show_usagekw默认default Falseboolshow 用量(类型 `bool`)。The show usage.
idkw默认default Nonestr | None标识(类型 `str | None`)。The id.
classeskw默认default Nonestr | Noneclasses(类型 `str | None`)。The classes.
disabledkw默认default Falsebool已禁用(类型 `bool`)。The disabled.
源码Source agentscope/tui/_messages.py:853–871

属性详情Attribute Detail

DEFAULT_CSS

 = '\n    MessagesUI {\n        width: 100%;\n        height: 1fr;\n        scrollbar-visibility: hidden;\n        padding: 0;\n        background: transparent;\n    }\n\n    MessageUI {\n        width: 100%;\n        height: auto;\n        margin: 0;\n        padding: 0;\n    }\n\n    .as-message-user {\n        margin-left: 0;\n        background: transparent;\n    }\n\n    .as-message-assistant {\n        margin-right: 0;\n        background: transparent;\n    }\n\n    .as-message-header {\n        height: 1;\n        margin-bottom: 1;\n        color: $text-muted;\n        text-style: bold;\n    }\n\n    .as-message-user > .as-message-header {\n        color: $foreground;\n    }\n\n    .as-message-assistant > .as-message-header {\n        color: $foreground;\n    }\n\n    .as-message-footer {\n        height: auto;\n        color: $text-muted;\n        margin-top: 1;\n    }\n\n    .as-text-block, .as-thinking, .as-tool-group, .as-hint {\n        width: 100%;\n        height: auto;\n    }\n\n    .as-text-block {\n        padding: 0;\n        background: transparent;\n    }\n\n    .as-thinking, .as-tool-group, .as-hint {\n        background: transparent;\n        border-top: none;\n        padding: 0;\n        margin: 0 0 1 0;\n    }\n\n    .as-thinking:ansi, .as-tool-group:ansi, .as-hint:ansi {\n        background: transparent;\n        border-top: none;\n    }\n\n    .as-thinking > CollapsibleTitle,\n    .as-tool-group > CollapsibleTitle,\n    .as-hint > CollapsibleTitle {\n        width: 100%;\n        padding: 0 1;\n        background: transparent;\n        text-style: none;\n    }\n\n    .as-thinking > CollapsibleTitle,\n    .as-hint > CollapsibleTitle {\n        color: $text-muted;\n    }\n\n    .as-tool-group > CollapsibleTitle {\n        width: auto;\n        padding-left: 0;\n    }\n\n    .as-thinking > CollapsibleTitle:hover,\n    .as-thinking > CollapsibleTitle:focus,\n    .as-tool-group > CollapsibleTitle:hover,\n    .as-tool-group > CollapsibleTitle:focus,\n    .as-hint > CollapsibleTitle:hover,\n    .as-hint > CollapsibleTitle:focus {\n        background: transparent;\n        color: #d8b66f;\n        text-style: bold;\n    }\n\n    .as-thinking > Contents,\n    .as-tool-group > Contents,\n    .as-hint > Contents {\n        height: auto;\n        padding: 0 0 0 2;\n    }\n\n    .as-tool-list {\n        width: 100%;\n        height: auto;\n    }\n\n    .as-thinking-body, .as-hint-body {\n        padding: 0;\n        background: transparent;\n    }\n\n    .as-tool-call {\n        width: 100%;\n        height: auto;\n        margin-top: 1;\n    }\n\n    .as-tool-call-title {\n        width: 100%;\n        height: 1;\n        color: $foreground;\n    }\n\n    .as-tool-body {\n        width: 100%;\n        height: auto;\n        padding-left: 1;\n        color: $text-muted;\n        background: transparent;\n    }\n\n    .as-attachment {\n        width: 100%;\n        height: auto;\n        margin-top: 1;\n        padding-left: 2;\n        color: $text-muted;\n    }\n    '

默认 CSS字段。

The DEFAULT CSS field.

源码Source agentscope/tui/_messages.py:708

属性详情Property Detail

messages

def messages() -> tuple[Msg, ...]

获取消息。

A safe snapshot of the messages currently being rendered.

返回Returns tuple[Msg, ...]
返回消息,列表。Returns a list of msg.
源码Source agentscope/tui/_messages.py:874–876

方法详情Method Detail

current_messages

def current_messages() -> tuple[Msg, ...]

返回当前消息。

Unlike :attr:messages, this avoids deep copies.

返回Returns tuple[Msg, ...]
返回消息,列表。Returns a list of msg.
源码Source agentscope/tui/_messages.py:878–884

compose

def compose() -> ComposeResult

返回 compose 结果。

Performs the compose operation.

返回Returns ComposeResult
返回ComposeResult。Returns compose result.
源码Source agentscope/tui/_messages.py:886–891

set_messages

async def set_messages(messages: Sequence[Msg]) -> None
async

设置消息。

Reconcile an authoritative full conversation snapshot.

参数Parameters
名称Name类型Type说明Description
messagesSequence[Msg]消息列表(类型 `Sequence[Msg]`)。The messages.
返回Returns None
无返回值。No value is returned.
源码Source agentscope/tui/_messages.py:900–932

update_message

async def update_message(message: Msg) -> None
async

更新消息。

Update one message by ID, appending it if it is new.

参数Parameters
名称Name类型Type说明Description
messageMsg消息(类型 `Msg`)。The message.
返回Returns None
无返回值。No value is returned.
源码Source agentscope/tui/_messages.py:934–950
基于官方固定版本源码静态生成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.