类class
agentscope.app.middlewareTeamMemberLoopMiddleware
class TeamMemberLoopMiddleware(MiddlewareBase)
源码Source
agentscope/app/middleware/_team_member_middleware.py:21–220团队成员循环中间件,在智能体执行流程中提供横切扩展。位于 agentscope.app.middleware 包,继承自 MiddlewareBase。核心成员包括 on_reply。
- The member should end its reply by calling
TeamSaytool to report to the team leader. - 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_name | str | 负责人名称(类型 `str`)。The name of the team leader, i.e. the only valid `TeamSay(to=...)` target that counts as a report. |
max_nudges默认default 3 | int | 最大 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_kwargs | dict | 输入关键字参数(类型 `dict`)。The reply arguments, forwarded to `next_handler` unchanged. |
next_handler | Callable[..., AsyncGenerator] | 下一个处理器(类型 `Callable[..., AsyncGenerator]`)。The rest of the middleware chain. |
AsyncGenerator
返回AsyncGenerator。`AgentEvent | Msg`:
源码Source
agentscope/app/middleware/_team_member_middleware.py:113–220