AS AgentScopeAPI 手册 / API Reference
类class agentscope.app.middleware

InboxMiddleware

class InboxMiddleware(MiddlewareBase)
源码Source agentscope/app/middleware/_inbox_middleware.py:24–136

收件箱中间件,在智能体执行流程中提供横切扩展。位于 agentscope.app.middleware 包,继承自 MiddlewareBase。核心成员包括 on_reasoning。

Each entry in the inbox is a serialised :class:~agentscope.message.HintBlock. The middleware deserializes them, appends to the last assistant message in agent.state.context, and yields a one-shot HintBlockEvent for each so the front-end sees them.

构造器摘要Constructor Summary

构造器Constructor说明Description
def __init__(message_bus: MessageBus, max_count: int = 100) -> None
初始化 `InboxMiddleware` 实例。
Initialise the middleware.

方法摘要Method Summary

方法Method说明Description
async def on_reasoning(agent: Agent, input_kwargs: dict, next_handler: Callable[..., AsyncGenerator]) -> AsyncGenerator…async
拦截并扩展推理阶段。
Drain the inbox, inject HintBlocks into context, yield events, then continue with downstream reasoning.

构造器详情Constructor Detail

InboxMiddleware

def __init__(message_bus: MessageBus, max_count: int = 100) -> None

初始化 InboxMiddleware 实例。

Initialise the middleware.

参数Parameters
名称Name类型Type说明Description
message_busMessageBus消息总线(类型 `MessageBus`)。The application-level message bus.
max_count默认default 100int最大数量(类型 `int`)。Maximum entries drained per reasoning step.
源码Source agentscope/app/middleware/_inbox_middleware.py:41–55

方法详情Method Detail

on_reasoning

async def on_reasoning(agent: Agent, input_kwargs: dict, next_handler: Callable[..., AsyncGenerator]) -> AsyncGenerator[Any, None]
async

拦截并扩展推理阶段。

Drain the inbox, inject HintBlocks into context, yield events, then continue with downstream reasoning.

参数Parameters
名称Name类型Type说明Description
agentAgent智能体(类型 `Agent`)。The executing agent. `agent.state.session_id` selects the inbox to drain.
input_kwargsdict输入关键字参数(类型 `dict`)。Reasoning input kwargs (contains `tool_choice`); forwarded unchanged to `next_handler`.
next_handlerCallable[..., AsyncGenerator]下一个处理器(类型 `Callable[..., AsyncGenerator]`)。The downstream middleware or core reasoning logic.
返回Returns AsyncGenerator[Any, None]
以异步流的形式返回任意,None。`Any`:
源码Source agentscope/app/middleware/_inbox_middleware.py:57–136

继承成员Inherited Members

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