类class
agentscope.consoleConsoleRenderer
class ConsoleRenderer
源码Source
agentscope/console/_renderer.py:78–453控制台渲染器,为框架提供通用类型与基础能力。位于 agentscope.console 包。核心成员包括 reset、render、last_msg。
The renderer prints text/thinking deltas as they arrive, buffers the
concurrently-streamed tool calls/results via
:meth:~agentscope.message.Msg.append_event and prints them as whole
blocks on their end events. The accumulated reply message is available
at :attr:last_msg after (or during) the reply.
示例Example
renderer = ConsoleRenderer()
try:
async for event in agent.reply_stream(msg):
renderer.render(event)
except BaseException:
renderer.reset()
raise
构造器摘要Constructor Summary
| 构造器Constructor | 说明Description |
|---|---|
def __init__(verbosity: Verbosity = 'default', max_tool_result_lines: int | None = 20, console: Console | None = None)… | 初始化 `ConsoleRenderer` 实例。 Initialize the console renderer. |
属性摘要Property Summary
| 属性Property | 说明Description |
|---|---|
last_msg | 获取最后消息。 The reply message accumulated from the rendered events. |
方法摘要Method Summary
| 方法Method | 说明Description |
|---|---|
def reset() -> None | 清空或重置内部状态。 Release all accumulated messages and end any streamed line. |
def render(event: AgentEvent) -> None | 设置渲染。 Render the given agent event to the console. |
构造器详情Constructor Detail
ConsoleRenderer
def __init__(verbosity: Verbosity = 'default', max_tool_result_lines: int | None = 20, console: Console | None = None) -> None
初始化 ConsoleRenderer 实例。
Initialize the console renderer.
参数Parameters
| 名称Name | 类型Type | 说明Description |
|---|---|---|
verbosity默认default 'default' | Verbosity | verbosity(类型 `Verbosity`)。`"quiet"`: only the streamed reply text and errors. - `"default"`: plus thinking, tool calls/results, hint blocks, token usage and human-in-the-loop notices. - `"debug"`: plus lifecycle events and other events that are invisible by default. |
max_tool_result_lines默认default 20 | int | None | 最大工具结果 lines(类型 `int | None`)。Truncate the printed tool results to this number of lines. `None` means no truncation. |
console默认default None | Console | None | 控制台(类型 `Console | None`)。The rich console to print to. A new one on stdout is created if not provided. |
源码Source
agentscope/console/_renderer.py:100–128属性详情Property Detail
last_msg
def last_msg() -> Msg | None
获取最后消息。
The reply message accumulated from the rendered events.
Msg | None
返回消息|None。Returns msg none.
源码Source
agentscope/console/_renderer.py:131–133方法详情Method Detail
reset
def reset() -> None
清空或重置内部状态。
Call this when abandoning a stream or when it raises without a ReplyEndEvent.
None
无返回值。No value is returned.
源码Source
agentscope/console/_renderer.py:135–144render
def render(event: AgentEvent) -> None
设置渲染。
Unknown event types are silently skipped (or printed as a dim line under "debug" verbosity), so that the renderer keeps working when new event types are introduced.
参数Parameters
| 名称Name | 类型Type | 说明Description |
|---|---|---|
event | AgentEvent | 事件到渲染。The event to render. |
None
无返回值。No value is returned.
源码Source
agentscope/console/_renderer.py:146–202