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

TurnAggregator

class TurnAggregator
源码Source agentscope/agent/_realtime/_aggregator.py:8–75

轮次聚合器,驱动智能体的推理、工具调用与会话执行。位于 agentscope.agent 包。核心成员包括 take、merges_with_previous、reset。

Turn boundaries in speech are inferred, and inferred wrongly often enough to matter: one sentence gets split across two turns when the speaker pauses, and a stray "mm-hmm" gets promoted to a turn of its own. Neither is visible to the provider once it has answered, but both end up in our own context, where they outlive the call.

构造器摘要Constructor Summary

构造器Constructor说明Description
def __init__(merge_window_ms: int = 800, backchannels: frozenset[str] = frozenset(), min_chars: int = 1) -> None
初始化 `TurnAggregator` 实例。
Initialize the aggregator.

方法摘要Method Summary

方法Method说明Description
def take(transcript: str) -> str | None
设置该参数。
Accept a settled transcript and decide whether it is a turn.
def merges_with_previous() -> bool
返回 `merges_with_previous` 结果。
Whether the last :meth:`take` continued the previous turn.
def reset() -> None
清空或重置内部状态。
Forget the previous turn, e.g. on reconnect.

构造器详情Constructor Detail

TurnAggregator

def __init__(merge_window_ms: int = 800, backchannels: frozenset[str] = frozenset(), min_chars: int = 1) -> None

初始化 TurnAggregator 实例。

Initialize the aggregator.

参数Parameters
名称Name类型Type说明Description
merge_window_ms默认default 800intmerge window ms(类型 `int`)。A transcript arriving this soon after the previous turn continues it rather than starting a new one.
backchannels默认default frozenset()frozenset[str]backchannels(类型 `frozenset[str]`)。Acknowledgements that never constitute a turn. Language specific, so empty by default.
min_chars默认default 1int最小字符数(类型 `int`)。Transcripts shorter than this are dropped.
源码Source agentscope/agent/_realtime/_aggregator.py:18–40

方法详情Method Detail

take

def take(transcript: str) -> str | None

设置该参数。

Accept a settled transcript and decide whether it is a turn.

参数Parameters
名称Name类型Type说明Description
transcriptstrtranscript(类型 `str`)。The transcript the provider settled on.
返回Returns str | None
返回str|None。`str | None`:
源码Source agentscope/agent/_realtime/_aggregator.py:42–66

merges_with_previous

def merges_with_previous() -> bool

返回 merges_with_previous 结果。

Whether the last :meth:take continued the previous turn.

返回Returns bool
返回布尔值,表示判断结果。Returns a boolean result.
源码Source agentscope/agent/_realtime/_aggregator.py:68–70

reset

def reset() -> None

清空或重置内部状态。

Forget the previous turn, e.g.

返回Returns None
无返回值。No value is returned.
源码Source agentscope/agent/_realtime/_aggregator.py:72–75
基于官方固定版本源码静态生成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.