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

ConsoleRenderer

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'Verbosityverbosity(类型 `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 20int | None最大工具结果 lines(类型 `int | None`)。Truncate the printed tool results to this number of lines. `None` means no truncation.
console默认default NoneConsole | 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.

返回Returns 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.

返回Returns None
无返回值。No value is returned.
源码Source agentscope/console/_renderer.py:135–144

render

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
eventAgentEvent事件到渲染。The event to render.
返回Returns None
无返回值。No value is returned.
源码Source agentscope/console/_renderer.py:146–202
基于官方固定版本源码静态生成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.