AS AgentScopeAPI 手册 / API Reference

DynamicSubagentsMiddleware

public class DynamicSubagentsMiddleware implements HarnessRuntimeMiddleware
源码Source io/agentscope/harness/agent/middleware/DynamicSubagentsMiddleware.java:66–271

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

Dynamic counterpart to SubagentsMiddleware that re-resolves the registered subagent set on every reasoning step, supporting per-user isolation through the workspace AbstractFilesystem (e.g. CompositeFilesystem routing user-scoped writes into a remote Store).

Two-layer load (mirrors the previous DynamicSubagentsHook override semantics):

  • Layer 1 (override) — filesystem.glob("*.md", "subagents") + per-file filesystem.read. The backend's NamespaceFactory is applied transparently so each user sees their own slice of the store.

  • Layer 2 (base) — AgentSpecLoader.loadFromDirectory reads the local workspace subagents/ directory directly.

  • Merge — same-name entries from Layer 1 override Layer 2; programmatic (builder-registered) entries are preserved as the static prefix and same-name dynamic declarations override them too.

构造器摘要Constructor Summary

构造器Constructor说明Description
public DynamicSubagentsMiddleware(List<SubagentEntry> staticEntries, AbstractFilesystem filesystem, Path mainWorkspace, Function<SubagentDeclaration, SubagentFactory> factoryBuilder, DefaultAgentManager agentManager, Object subagentTool, TaskRepository taskRepository)
初始化 `DynamicSubagentsMiddleware` 实例。
Creates a new instance.

方法摘要Method Summary

方法Method说明Description
public DynamicSubagentsMiddleware 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` when none is owned.
public List<Object> getTools()
获取工具。
Returns the tool instances this middleware contributes to the agent toolkit.
public TaskRepository getTaskRepository()
获取任务仓库。
Returns the task repository.
public Flux<AgentEvent> onReasoning(Agent agent, RuntimeContext ctx, ReasoningInput input, Function<ReasoningInput, Flux<AgentEvent>> next)
处理推理事件。
Performs the on reasoning operation.

构造器详情Constructor Detail

DynamicSubagentsMiddleware

public DynamicSubagentsMiddleware(List<SubagentEntry> staticEntries, AbstractFilesystem filesystem, Path mainWorkspace, Function<SubagentDeclaration, SubagentFactory> factoryBuilder, DefaultAgentManager agentManager, Object subagentTool, TaskRepository taskRepository)

初始化 DynamicSubagentsMiddleware 实例。

Creates a new instance.

参数Parameters
名称Name类型Type说明Description
staticEntriesList<SubagentEntry>static 条目(类型 `List`)。The static entries.
filesystemAbstractFilesystem文件系统(类型 `AbstractFilesystem`)。The filesystem.
mainWorkspacePath主工作区(类型 `Path`)。The main workspace.
factoryBuilderFunction<SubagentDeclaration, SubagentFactory>工厂构建器(类型 `Function`)。The factory builder.
agentManagerDefaultAgentManager智能体管理器(类型 `DefaultAgentManager`)。The agent manager.
subagentToolObject子智能体工具(类型 `Object`)。The subagent tool.
taskRepositoryTaskRepository任务仓库(类型 `TaskRepository`)。The task repository.
源码Source io/agentscope/harness/agent/middleware/DynamicSubagentsMiddleware.java:82–102

方法详情Method Detail

setGatewayBridge

public DynamicSubagentsMiddleware 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.
返回Returns DynamicSubagentsMiddleware
返回DynamicSubagentsMiddleware。Returns dynamic subagents middleware.
源码Source io/agentscope/harness/agent/middleware/DynamicSubagentsMiddleware.java:109–124

getAgentManager

public DefaultAgentManager getAgentManager()

获取智能体管理器。

Returns the internal DefaultAgentManager that can re-materialize subagents, or null when none is owned.

返回Returns DefaultAgentManager
返回DefaultAgentManager。Returns default agent manager.
源码Source io/agentscope/harness/agent/middleware/DynamicSubagentsMiddleware.java:131–133

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/DynamicSubagentsMiddleware.java:139–141

getTaskRepository

public TaskRepository getTaskRepository()

获取任务仓库。

Returns the task repository.

返回Returns TaskRepository
返回TaskRepository。Returns task repository.
源码Source io/agentscope/harness/agent/middleware/DynamicSubagentsMiddleware.java:143–145

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/DynamicSubagentsMiddleware.java:147–172

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