AS AgentScopeAPI 手册 / API Reference

SubagentsMiddleware

public class SubagentsMiddleware implements HarnessRuntimeMiddleware
源码Source io/agentscope/harness/agent/middleware/SubagentsMiddleware.java:75–728

Subagents 中间件,在智能体执行流程中提供横切扩展。位于 io.agentscope.harness.agent.middleware 包,实现 HarnessRuntimeMiddleware。核心成员包括 enableAgentGenerateTool、getTaskRepository、wireMessageBus、setGatewayBridge、getAgentManager、getTools。

Middleware that provides the managed subagent mechanism.

In default mode (standalone harness setup), this middleware creates an AgentSpawnTool backed by a DefaultAgentManager. In session mode (orchestrated via AgentBootstrap), an external tool (typically SessionsTool) is injected, replacing the default AgentSpawnTool.

Responsibilities:

  • Exposes the subagent tool and TaskTool as agent tools (callers query via #getTools() and register them on the toolkit at orchestration time).

  • On every #onAgent, reloads subagent declarations from the workspace filesystem (namespace-scoped) to support per-user subagent isolation.

  • Prepends rich subagent usage guidance and current async task summary to the leading SYSTEM message of every ReasoningInput. Because the framework rebuilds the SYSTEM message from a frozen base each iteration, this is safe — content never accumulates across iterations.

构造器摘要Constructor Summary

构造器Constructor说明Description
public SubagentsMiddleware(List<SubagentEntry> entries, TaskRepository taskRepository, WorkspaceManager workspaceManager, AbstractFilesystem filesystem, Path mainWorkspace, Function<SubagentDeclaration, SubagentFactory> factoryBuilder)
初始化 `SubagentsMiddleware` 实例。
Default mode: creates `AgentSpawnTool` + `DefaultAgentManager` internally.
public SubagentsMiddleware(List<SubagentEntry> entries, TaskRepository taskRepository, WorkspaceManager workspaceManager)
初始化 `SubagentsMiddleware` 实例。
Default mode without dynamic reload support.
public SubagentsMiddleware(List<SubagentEntry> entries, Object externalSubagentTool, TaskRepository taskRepository)
初始化 `SubagentsMiddleware` 实例。
AgentStateStore mode: uses the externally provided tool (typically `SessionsTool`).

方法摘要Method Summary

方法Method说明Description
public SubagentsMiddleware enableAgentGenerateTool(SubagentSpecGenerator generator)
启用 `enableAgentGenerateTool`。
Enables the `agent_generate` tool, which lets the LLM author new subagent specs from a description.
public TaskRepository getTaskRepository()
获取任务仓库。
Returns the `TaskRepository` used by this middleware.
public SubagentsMiddleware wireMessageBus(io.agentscope.harness.agent.bus.MessageBus messageBus, String agentId)
执行 `wireMessageBus` 方法。
Wires a `io.agentscope.harness.agent.bus.MessageBus` so that background task completions are pushed to the session inbox and a wakeup signal is enqueued.
public SubagentsMiddleware setGatewayBridge(io.agentscope.harness.agent.gateway.SubagentGatewayBridge bridge)
设置 `setGatewayBridge`。
Wires a gateway bridge into the internal `AgentSpawnTool`, enabling spawned subagents to be exposed as user-addressable threads.
public DefaultAgentManager getAgentManager()
获取智能体管理器。
Returns the internal `DefaultAgentManager` that can re-materialize subagents, or `null` in session mode (external tool).
public List<Object> getTools()
获取工具。
Returns the tool instances this middleware contributes to the agent toolkit.
public Flux<AgentEvent> onAgent(Agent agent, RuntimeContext ctx, AgentInput input, Function<AgentInput, Flux<AgentEvent>> next)
处理智能体事件。
Performs the on agent operation.
public Flux<AgentEvent> onReasoning(Agent agent, RuntimeContext ctx, ReasoningInput input, Function<ReasoningInput, Flux<AgentEvent>> next)
处理推理事件。
Performs the on reasoning operation.
public static String renderSubagentSection(List<SubagentEntry> entries, boolean isSessionMode)
static
渲染 `renderSubagentSection`。
Renders the `## Subagents` system-prompt section for the supplied entries.
public static String buildTaskSummary(TaskRepository repo, RuntimeContext ctx)
static
构建任务摘要。
Builds a concise summary of in-flight tasks for the current session, or `null` if none.

构造器详情Constructor Detail

SubagentsMiddleware

public SubagentsMiddleware(List<SubagentEntry> entries, TaskRepository taskRepository, WorkspaceManager workspaceManager, AbstractFilesystem filesystem, Path mainWorkspace, Function<SubagentDeclaration, SubagentFactory> factoryBuilder)

初始化 SubagentsMiddleware 实例。

Default mode: creates AgentSpawnTool + DefaultAgentManager internally.

参数Parameters
名称Name类型Type说明Description
entriesList<SubagentEntry>条目(类型 `List`)。The entries.
taskRepositoryTaskRepository任务仓库(类型 `TaskRepository`)。The task repository.
workspaceManagerWorkspaceManager工作区管理器(类型 `WorkspaceManager`)。The workspace manager.
filesystemAbstractFilesystem文件系统(类型 `AbstractFilesystem`)。The filesystem.
mainWorkspacePath主工作区(类型 `Path`)。The main workspace.
factoryBuilderFunction<SubagentDeclaration, SubagentFactory>工厂构建器(类型 `Function`)。The factory builder.
源码Source io/agentscope/harness/agent/middleware/SubagentsMiddleware.java:200–219

SubagentsMiddleware

public SubagentsMiddleware(List<SubagentEntry> entries, TaskRepository taskRepository, WorkspaceManager workspaceManager)

初始化 SubagentsMiddleware 实例。

Default mode without dynamic reload support.

参数Parameters
名称Name类型Type说明Description
entriesList<SubagentEntry>条目(类型 `List`)。The entries.
taskRepositoryTaskRepository任务仓库(类型 `TaskRepository`)。The task repository.
workspaceManagerWorkspaceManager工作区管理器(类型 `WorkspaceManager`)。The workspace manager.
源码Source io/agentscope/harness/agent/middleware/SubagentsMiddleware.java:224–229

SubagentsMiddleware

public SubagentsMiddleware(List<SubagentEntry> entries, Object externalSubagentTool, TaskRepository taskRepository)

初始化 SubagentsMiddleware 实例。

AgentStateStore mode: uses the externally provided tool (typically SessionsTool).

参数Parameters
名称Name类型Type说明Description
entriesList<SubagentEntry>条目(类型 `List`)。The entries.
externalSubagentToolObject外部子智能体工具(类型 `Object`)。The external subagent tool.
taskRepositoryTaskRepository任务仓库(类型 `TaskRepository`)。The task repository.
源码Source io/agentscope/harness/agent/middleware/SubagentsMiddleware.java:234–249

方法详情Method Detail

enableAgentGenerateTool

public SubagentsMiddleware enableAgentGenerateTool(SubagentSpecGenerator generator)

启用 enableAgentGenerateTool。

Enables the agent_generate tool, which lets the LLM author new subagent specs from a description.

参数Parameters
名称Name类型Type说明Description
generatorSubagentSpecGeneratorgenerator(类型 `SubagentSpecGenerator`)。a `SubagentSpecGenerator` backed by the model that should author specs
返回Returns SubagentsMiddleware
返回SubagentsMiddleware。this middleware for chaining
源码Source io/agentscope/harness/agent/middleware/SubagentsMiddleware.java:263–270

getTaskRepository

public TaskRepository getTaskRepository()

获取任务仓库。

Returns the TaskRepository used by this middleware.

返回Returns TaskRepository
返回TaskRepository。Returns task repository.
源码Source io/agentscope/harness/agent/middleware/SubagentsMiddleware.java:273–275

wireMessageBus

public SubagentsMiddleware wireMessageBus(io.agentscope.harness.agent.bus.MessageBus messageBus, String agentId)

执行 wireMessageBus 方法。

Wires a io.agentscope.harness.agent.bus.MessageBus so that background task completions are pushed to the session inbox and a wakeup signal is enqueued.

参数Parameters
名称Name类型Type说明Description
messageBusio.agentscope.harness.agent.bus.MessageBus应用消息总线。the application message bus
agentIdString智能体标识(类型 `String`)。the parent agent id (for wakeup routing)
返回Returns SubagentsMiddleware
返回SubagentsMiddleware。this middleware for chaining
源码Source io/agentscope/harness/agent/middleware/SubagentsMiddleware.java:290–336

setGatewayBridge

public SubagentsMiddleware setGatewayBridge(io.agentscope.harness.agent.gateway.SubagentGatewayBridge bridge)

设置 setGatewayBridge。

Wires a gateway bridge into the internal AgentSpawnTool, enabling spawned subagents to be exposed as user-addressable threads.

参数Parameters
名称Name类型Type说明Description
bridgeio.agentscope.harness.agent.gateway.SubagentGatewayBridgebridge(类型 `io.agentscope.harness.agent.gateway.SubagentGatewayBridge`)。the bridge implementation (typically obtained from `io.agentscope.harness.agent.gateway.GatewayBootstrap#gatewayBridge()`)
返回Returns SubagentsMiddleware
返回SubagentsMiddleware。this middleware for chaining
源码Source io/agentscope/harness/agent/middleware/SubagentsMiddleware.java:346–362

getAgentManager

public DefaultAgentManager getAgentManager()

获取智能体管理器。

Returns the internal DefaultAgentManager that can re-materialize subagents, or null in session mode (external tool).

返回Returns DefaultAgentManager
返回DefaultAgentManager。Returns default agent manager.
源码Source io/agentscope/harness/agent/middleware/SubagentsMiddleware.java:369–371

getTools

public List<Object> getTools()

获取工具。

Returns the tool instances this middleware contributes to the agent toolkit.

返回Returns List<Object>
返回列出。Returns list.
源码Source io/agentscope/harness/agent/middleware/SubagentsMiddleware.java:380–389

onAgent

public Flux<AgentEvent> onAgent(Agent agent, RuntimeContext ctx, AgentInput input, Function<AgentInput, Flux<AgentEvent>> next)

处理智能体事件。

Performs the on agent operation.

参数Parameters
名称Name类型Type说明Description
agentAgent智能体(类型 `Agent`)。The agent.
ctxRuntimeContext运行时上下文(类型 `RuntimeContext`)。The ctx.
inputAgentInput输入消息(类型 `AgentInput`)。The input.
nextFunction<AgentInput, Flux<AgentEvent>>下一个(类型 `Function >`)。The next.
返回Returns Flux<AgentEvent>
返回Flux。Returns flux.
源码Source io/agentscope/harness/agent/middleware/SubagentsMiddleware.java:391–401

onReasoning

public Flux<AgentEvent> onReasoning(Agent agent, RuntimeContext ctx, ReasoningInput input, Function<ReasoningInput, Flux<AgentEvent>> next)

处理推理事件。

Performs the on reasoning operation.

参数Parameters
名称Name类型Type说明Description
agentAgent智能体(类型 `Agent`)。The agent.
ctxRuntimeContext运行时上下文(类型 `RuntimeContext`)。The ctx.
inputReasoningInput输入消息(类型 `ReasoningInput`)。The input.
nextFunction<ReasoningInput, Flux<AgentEvent>>下一个(类型 `Function >`)。The next.
返回Returns Flux<AgentEvent>
返回Flux。Returns flux.
源码Source io/agentscope/harness/agent/middleware/SubagentsMiddleware.java:403–481

renderSubagentSection

public static String renderSubagentSection(List<SubagentEntry> entries, boolean isSessionMode)
static

渲染 renderSubagentSection。

Renders the ## Subagents system-prompt section for the supplied entries.

参数Parameters
名称Name类型Type说明Description
entriesList<SubagentEntry>条目(类型 `List`)。The entries.
isSessionModeboolean是会话模式(类型 `boolean`)。The is session mode.
返回Returns String
返回字符串结果。Returns a string.
源码Source io/agentscope/harness/agent/middleware/SubagentsMiddleware.java:653–663

buildTaskSummary

public static String buildTaskSummary(TaskRepository repo, RuntimeContext ctx)
static

构建任务摘要。

Builds a concise summary of in-flight tasks for the current session, or null if none.

参数Parameters
名称Name类型Type说明Description
repoTaskRepository仓库(类型 `TaskRepository`)。The repo.
ctxRuntimeContext运行时上下文(类型 `RuntimeContext`)。The ctx.
返回Returns String
返回字符串结果。Returns a string.
源码Source io/agentscope/harness/agent/middleware/SubagentsMiddleware.java:685–727

继承成员Inherited Members

继承自Methods inherited from MiddlewareBase
基于官方固定版本源码静态生成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.