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

TeamMemberLoopMiddleware

class TeamMemberLoopMiddleware(MiddlewareBase)
源码Source agentscope/app/middleware/_team_member_middleware.py:21–220

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

  1. The member should end its reply by calling TeamSay tool to report to the team leader.
  2. When exceeds the max iteration numbers, the agent is guided to send team leader a message to ask for permission to continue the operation.

A member that keeps ending without reporting is nudged at most max_nudges times; after that the reply is released as an ERROR so it terminates and the failure travels the normal error path instead of looping under the session lock forever.

构造器摘要Constructor Summary

构造器Constructor说明Description
def __init__(leader_name: str, max_nudges: int = 3) -> None
初始化 `TeamMemberLoopMiddleware` 实例。
Initialize the middleware.

方法摘要Method Summary

方法Method说明Description
async def on_reply(agent: 'Agent', input_kwargs: dict, next_handler: Callable[..., AsyncGenerator]) -> AsyncGeneratorasync
拦截并扩展回复流程。
Discard normal `ReplyEndEvent`s until `TeamSay` reports success.

构造器详情Constructor Detail

TeamMemberLoopMiddleware

def __init__(leader_name: str, max_nudges: int = 3) -> None

初始化 TeamMemberLoopMiddleware 实例。

Initialize the middleware.

参数Parameters
名称Name类型Type说明Description
leader_namestr负责人名称(类型 `str`)。The name of the team leader, i.e. the only valid `TeamSay(to=...)` target that counts as a report.
max_nudges默认default 3int最大 nudges(类型 `int`)。How many times one reply may be forced to continue before it is failed instead.
源码Source agentscope/app/middleware/_team_member_middleware.py:35–48

方法详情Method Detail

on_reply

async def on_reply(agent: 'Agent', input_kwargs: dict, next_handler: Callable[..., AsyncGenerator]) -> AsyncGenerator
async

拦截并扩展回复流程。

Discard normal ReplyEndEvents until TeamSay reports success.

参数Parameters
名称Name类型Type说明Description
agent'Agent'智能体(类型 `'Agent'`)。The replying member agent. Its context receives the reminder hints, and its `cur_iter` is relaxed so a nudged reply can still act.
input_kwargsdict输入关键字参数(类型 `dict`)。The reply arguments, forwarded to `next_handler` unchanged.
next_handlerCallable[..., AsyncGenerator]下一个处理器(类型 `Callable[..., AsyncGenerator]`)。The rest of the middleware chain.
返回Returns AsyncGenerator
返回AsyncGenerator。`AgentEvent | Msg`:
源码Source agentscope/app/middleware/_team_member_middleware.py:113–220

继承成员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.