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

ChatUI

class ChatUI(Widget)
源码Source agentscope/tui/_chat.py:340–657

聊天 UI,为框架提供通用类型与基础能力。位于 agentscope.tui 包,继承自 Widget。核心成员包括 compose、on_mount、is_reply_parked、set_messages、update_message、watch_input_enabled。

Messages, composer and HITL controls without an Agent dependency. Declared in agentscope.tui. Extends Widget.

嵌套类摘要Nested Class Summary

类Class类型Kind说明Description
Submitted类class
Submitted,为框架提供通用类型与基础能力。
A class in agentscope.tui that provides shared types and foundational utilities.
Confirmed类class
Confirmed,为框架提供通用类型与基础能力。
A class in agentscope.tui that provides shared types and foundational utilities.
ExternalExecutionSubmitted类class
外部执行 Submitted,为框架提供通用类型与基础能力。
A class in agentscope.tui that provides shared types and foundational utilities.
InterruptRequested类class
中断 Requested,为框架提供通用类型与基础能力。
A class in agentscope.tui that provides shared types and foundational utilities.

构造器摘要Constructor Summary

构造器Constructor说明Description
def __init__(messages: Sequence[Msg] = (), *, user_name: str = 'user', input_enabled: bool = True, show_thinking: bool…
初始化 `ChatUI` 实例。
Creates a new instance.

属性摘要Property Summary

属性Property说明Description
messages
获取消息。
Returns the messages.

属性摘要Attribute Summary

属性Attribute类型Type说明Description值Value
input_enabled—
输入已启用字段。
reactive(True)
DEFAULT_CSS—
默认 CSS字段。
'\n ChatUI {\n width: 100%;\n height: 100%;\n layout: vertical;\n padding: 0;\n background: transparent;\n }\n\n ChatUI > MessagesUI {\n height: 1fr;\n padding: 0 1;\n }\n\n ComposerUI, HitlUI {\n width: 100%;\n height: auto;\n min-height: 3;\n padding: 0;\n background: transparent;\n }\n\n .as-section-rule {\n width: 100%;\n height: 1;\n color: #766b5b;\n background: transparent;\n }\n\n #as-composer-input {\n width: 100%;\n height: auto;\n min-height: 1;\n max-height: 10;\n scrollbar-visibility: hidden;\n border: none;\n padding: 0 1;\n background: transparent;\n }\n\n #as-composer-input .text-area--cursor-line {\n background: transparent;\n }\n\n .as-composer-hint, .as-hitl-hint {\n width: 100%;\n height: 1;\n padding: 0 1;\n color: $text-muted;\n }\n\n .as-hitl-options {\n width: 100%;\n height: auto;\n max-height: 10;\n margin-top: 1;\n scrollbar-visibility: hidden;\n border: none;\n padding: 0 1;\n background: transparent;\n }\n\n .as-hitl-options:focus {\n border: none;\n background: transparent;\n background-tint: transparent;\n }\n\n .as-hitl-options > .option-list--option-highlighted,\n .as-hitl-options:focus > .option-list--option-highlighted {\n color: #d8b66f;\n background: transparent;\n text-style: bold;\n }\n\n .as-hitl-options > .option-list--option-hover {\n color: #d8b66f;\n background: transparent;\n }\n\n .as-hitl-title {\n height: 1;\n padding: 0 1;\n text-style: bold;\n color: $foreground;\n }\n\n .as-hitl-body {\n height: auto;\n max-height: 10;\n overflow-y: auto;\n scrollbar-visibility: hidden;\n padding: 0 1;\n background: transparent;\n }\n '

方法摘要Method Summary

方法Method说明Description
def compose() -> ComposeResult
返回 `compose` 结果。
Performs the compose operation.
def on_mount() -> None
处理 `on_mount` 事件。
Handles the mount event.
def is_reply_parked(reply_id: str) -> bool
判断是否 `is_reply_parked`。
Whether a reply is waiting for confirmation or external input.
async def set_messages(messages: Sequence[Msg]) -> Noneasync
设置消息。
Sets the messages.
async def update_message(message: Msg) -> Noneasync
更新消息。
Update one message and its associated interaction controls.
def watch_input_enabled(enabled: bool) -> None
设置该参数。
Performs the watch input enabled operation.

构造器详情Constructor Detail

ChatUI

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

初始化 ChatUI 实例。

Creates a new instance.

参数Parameters
名称Name类型Type说明Description
messages默认default ()Sequence[Msg]消息列表(类型 `Sequence[Msg]`)。The messages.
user_namekw默认default 'user'str用户名称(类型 `str`)。The user name.
input_enabledkw默认default Truebool输入已启用(类型 `bool`)。The input enabled.
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/_chat.py:462–485

属性详情Attribute Detail

input_enabled

 = reactive(True)

输入已启用字段。

The input enabled field.

源码Source agentscope/tui/_chat.py:343

DEFAULT_CSS

 = '\n    ChatUI {\n        width: 100%;\n        height: 100%;\n        layout: vertical;\n        padding: 0;\n        background: transparent;\n    }\n\n    ChatUI > MessagesUI {\n        height: 1fr;\n        padding: 0 1;\n    }\n\n    ComposerUI, HitlUI {\n        width: 100%;\n        height: auto;\n        min-height: 3;\n        padding: 0;\n        background: transparent;\n    }\n\n    .as-section-rule {\n        width: 100%;\n        height: 1;\n        color: #766b5b;\n        background: transparent;\n    }\n\n    #as-composer-input {\n        width: 100%;\n        height: auto;\n        min-height: 1;\n        max-height: 10;\n        scrollbar-visibility: hidden;\n        border: none;\n        padding: 0 1;\n        background: transparent;\n    }\n\n    #as-composer-input .text-area--cursor-line {\n        background: transparent;\n    }\n\n    .as-composer-hint, .as-hitl-hint {\n        width: 100%;\n        height: 1;\n        padding: 0 1;\n        color: $text-muted;\n    }\n\n    .as-hitl-options {\n        width: 100%;\n        height: auto;\n        max-height: 10;\n        margin-top: 1;\n        scrollbar-visibility: hidden;\n        border: none;\n        padding: 0 1;\n        background: transparent;\n    }\n\n    .as-hitl-options:focus {\n        border: none;\n        background: transparent;\n        background-tint: transparent;\n    }\n\n    .as-hitl-options > .option-list--option-highlighted,\n    .as-hitl-options:focus > .option-list--option-highlighted {\n        color: #d8b66f;\n        background: transparent;\n        text-style: bold;\n    }\n\n    .as-hitl-options > .option-list--option-hover {\n        color: #d8b66f;\n        background: transparent;\n    }\n\n    .as-hitl-title {\n        height: 1;\n        padding: 0 1;\n        text-style: bold;\n        color: $foreground;\n    }\n\n    .as-hitl-body {\n        height: auto;\n        max-height: 10;\n        overflow-y: auto;\n        scrollbar-visibility: hidden;\n        padding: 0 1;\n        background: transparent;\n    }\n    '

默认 CSS字段。

The DEFAULT CSS field.

源码Source agentscope/tui/_chat.py:345

属性详情Property Detail

messages

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

获取消息。

Returns the messages.

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

方法详情Method Detail

compose

def compose() -> ComposeResult

返回 compose 结果。

Performs the compose operation.

返回Returns ComposeResult
返回ComposeResult。Returns compose result.
源码Source agentscope/tui/_chat.py:487–500

on_mount

def on_mount() -> None

处理 on_mount 事件。

Handles the mount event.

返回Returns None
无返回值。No value is returned.
源码Source agentscope/tui/_chat.py:502–503

is_reply_parked

def is_reply_parked(reply_id: str) -> bool

判断是否 is_reply_parked。

Whether a reply is waiting for confirmation or external input.

参数Parameters
名称Name类型Type说明Description
reply_idstr回复标识(类型 `str`)。The reply id.
返回Returns bool
返回布尔值,表示判断结果。Returns a boolean result.
源码Source agentscope/tui/_chat.py:512–523

set_messages

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

设置消息。

Sets the messages.

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

update_message

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

更新消息。

Update one message and its associated interaction controls.

参数Parameters
名称Name类型Type说明Description
messageMsg消息(类型 `Msg`)。The message.
返回Returns None
无返回值。No value is returned.
源码Source agentscope/tui/_chat.py:534–541

watch_input_enabled

def watch_input_enabled(enabled: bool) -> None

设置该参数。

Performs the watch input enabled operation.

参数Parameters
名称Name类型Type说明Description
enabledbool已启用(类型 `bool`)。The enabled.
返回Returns None
无返回值。No value is returned.
源码Source agentscope/tui/_chat.py:543–545

嵌套类详情Nested Class Detail

Submitted

class Submitted

Submitted,为框架提供通用类型与基础能力。位于 agentscope.tui 包,继承自 Message。

A class in agentscope.tui that provides shared types and foundational utilities. Declared in agentscope.tui. Extends Message.

Confirmed

class Confirmed

Confirmed,为框架提供通用类型与基础能力。位于 agentscope.tui 包,继承自 Message。

A class in agentscope.tui that provides shared types and foundational utilities. Declared in agentscope.tui. Extends Message.

ExternalExecutionSubmitted

class ExternalExecutionSubmitted

外部执行 Submitted,为框架提供通用类型与基础能力。位于 agentscope.tui 包,继承自 Message。

A class in agentscope.tui that provides shared types and foundational utilities. Declared in agentscope.tui. Extends Message.

InterruptRequested

class InterruptRequested

中断 Requested,为框架提供通用类型与基础能力。位于 agentscope.tui 包,继承自 Message。

A class in agentscope.tui that provides shared types and foundational utilities. Declared in agentscope.tui. Extends Message.

基于官方固定版本源码静态生成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.