类class
agentscope.tuiMessagesUI
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 True | bool | show thinking(类型 `bool`)。The show thinking. |
show_usagekw默认default False | bool | show 用量(类型 `bool`)。The show usage. |
idkw默认default None | str | None | 标识(类型 `str | None`)。The id. |
classeskw默认default None | str | None | classes(类型 `str | None`)。The classes. |
disabledkw默认default False | bool | 已禁用(类型 `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.
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.
tuple[Msg, ...]
返回消息,列表。Returns a list of msg.
源码Source
agentscope/tui/_messages.py:878–884compose
def compose() -> ComposeResult
返回 compose 结果。
Performs the compose operation.
ComposeResult
返回ComposeResult。Returns compose result.
源码Source
agentscope/tui/_messages.py:886–891set_messages
async def set_messages(messages: Sequence[Msg]) -> None
async
设置消息。
Reconcile an authoritative full conversation snapshot.
参数Parameters
| 名称Name | 类型Type | 说明Description |
|---|---|---|
messages | Sequence[Msg] | 消息列表(类型 `Sequence[Msg]`)。The messages. |
None
无返回值。No value is returned.
源码Source
agentscope/tui/_messages.py:900–932update_message
async def update_message(message: Msg) -> None
async
更新消息。
Update one message by ID, appending it if it is new.
参数Parameters
| 名称Name | 类型Type | 说明Description |
|---|---|---|
message | Msg | 消息(类型 `Msg`)。The message. |
None
无返回值。No value is returned.
源码Source
agentscope/tui/_messages.py:934–950