AgentSpawnTool
public class AgentSpawnTool
io/agentscope/harness/agent/tool/AgentSpawnTool.java:105–1795智能体 Spawn 工具,封装可被智能体调用的能力。位于 io.agentscope.harness.agent.tool 包。核心成员包括 setGatewayBridge、agentSpawn、agentSend、agentList、AgentSpawnTool、CTX_EXPOSE_TO_USER。
Simple subagent tool for agent-internal use. Much lighter than SessionsTool:
-
agent_spawn— spawn a subagent, run task, return result (sync or async) -
agent_send— send follow-up message to a previously spawned subagent -
agent_list— list active subagents
No sessions, no lanes, no run registry, no announce dispatch. Just "create agent, invoke,
return result". Uses DefaultAgentManager for agent creation and invocation only.
Async tasks (timeout_seconds=0) are submitted to the TaskRepository scoped
by the current session ID from RuntimeContext. This makes task state visible in
workspace storage for cross-node retrieval and recovery after compaction.
Streaming
agent_spawn and agent_send return Mono``<String> so that the
framework's reactive tool-invocation pipeline (see ToolMethodInvoker) can subscribe them
within the parent agent's streaming chain. When a SubagentEventBus is present in the
Reactor Context (injected by AgentBase.createEventStream), every child io.agentscope.core.agent.Event is forwarded to the parent sink in real time, giving consumers
a flattened event stream across the full call hierarchy. When no bus is present (plain call() mode), execution falls back to the non-streaming invokeAgent path with no
overhead.
字段摘要Field Summary
| 字段Field | 类型Type | 说明Description |
|---|---|---|
CTX_EXPOSE_TO_USERstaticfinal | String | CTX EXPOSE 到用户字段。 `RuntimeContext` string key for a per-call override of subagent user-exposure. |
CTX_AGENT_MANAGERstaticfinal | String | CTX 智能体管理器字段。 `RuntimeContext` string key for the immutable subagent registry selected by the
current parent-agent invocation. |
CTX_REMOTE_CONTEXT_ATTRIBUTESstaticfinal | String | CTX 远程上下文属性字段。 `RuntimeContext` string key holding a `Map<String, Object>` of caller-defined
attributes to send with every remote subagent submission of the current call, as
`context.attributes`: |
CTX_FORCE_SYNCstaticfinal | String | CTX FORCE 同步字段。 `RuntimeContext` string key that forces synchronous subagent execution for the current
call. |
CTX_FORCE_SYNC_TIMEOUT_SECONDSstaticfinal | String | CTX FORCE 同步超时秒字段。 Optional `RuntimeContext` override for the sync wait (seconds) when `#CTX_FORCE_SYNC` is enabled. |
构造器摘要Constructor Summary
| 构造器Constructor | 说明Description |
|---|---|
public AgentSpawnTool(DefaultAgentManager agentManager, TaskRepository taskRepository, int parentSpawnDepth) | 初始化 `AgentSpawnTool` 实例。 Creates an `AgentSpawnTool` that derives the active user-id from each tool call's
`RuntimeContext`, rather than a shared supplier — this prevents identity races when a
single agent instance serves concurrent callers. |
public AgentSpawnTool(DefaultAgentManager agentManager, TaskRepository taskRepository, int parentSpawnDepth, SubagentGatewayBridge gatewayBridge) | 初始化 `AgentSpawnTool` 实例。 Creates an `AgentSpawnTool` with an optional gateway bridge for exposing subagents
as user-addressable threads. |
方法摘要Method Summary
| 方法Method | 说明Description |
|---|---|
public void setGatewayBridge(SubagentGatewayBridge gatewayBridge) | 设置 `setGatewayBridge`。 Wires (or re-wires) the gateway bridge used to expose subagents as user-addressable threads. |
public Mono<String> agentSpawn(RuntimeContext runtimeContext, AgentState parentState, String agentId, String task, String label, Integer timeoutSeconds, Boolean exposeToUser) | 执行 `agentSpawn` 方法。 Performs the agent spawn operation. |
public Mono<String> agentSend(RuntimeContext runtimeContext, AgentState parentState, String agentKey, String label, String message, Integer timeoutSeconds) | 执行智能体发送相关操作。 Performs the agent send operation. |
public String agentList() | 返回智能体列表。 Returns the agent list. |
字段详情Field Detail
CTX_EXPOSE_TO_USER
public static final String CTX_EXPOSE_TO_USER
CTX EXPOSE 到用户字段。声明为 public static final String CTX_EXPOSE_TO_USER。
RuntimeContext string key for a per-call override of subagent user-exposure.
io/agentscope/harness/agent/tool/AgentSpawnTool.java:130CTX_AGENT_MANAGER
public static final String CTX_AGENT_MANAGER
CTX 智能体管理器字段。声明为 public static final String CTX_AGENT_MANAGER。
RuntimeContext string key for the immutable subagent registry selected by the current parent-agent invocation.
io/agentscope/harness/agent/tool/AgentSpawnTool.java:138CTX_REMOTE_CONTEXT_ATTRIBUTES
public static final String CTX_REMOTE_CONTEXT_ATTRIBUTES
CTX 远程上下文属性字段。声明为 public static final String CTX_REMOTE_CONTEXT_ATTRIBUTES。
RuntimeContext string key holding a Map of caller-defined attributes to send with every remote subagent submission of the current call, as context.attributes: `RuntimeContext ctx = RuntimeContext.builder() .sessionId("s-1") .put(AgentSpawnTool.CTX_REMOTE_CONTEXT_ATTRIBUTE…
io/agentscope/harness/agent/tool/AgentSpawnTool.java:156–157CTX_FORCE_SYNC
public static final String CTX_FORCE_SYNC
CTX FORCE 同步字段。声明为 public static final String CTX_FORCE_SYNC。
RuntimeContext string key that forces synchronous subagent execution for the current call.
io/agentscope/harness/agent/tool/AgentSpawnTool.java:185CTX_FORCE_SYNC_TIMEOUT_SECONDS
public static final String CTX_FORCE_SYNC_TIMEOUT_SECONDS
CTX FORCE 同步超时秒字段。声明为 public static final String CTX_FORCE_SYNC_TIMEOUT_SECONDS。
Optional RuntimeContext override for the sync wait (seconds) when #CTX_FORCE_SYNC is enabled.
io/agentscope/harness/agent/tool/AgentSpawnTool.java:204–205构造器详情Constructor Detail
AgentSpawnTool
public AgentSpawnTool(DefaultAgentManager agentManager, TaskRepository taskRepository, int parentSpawnDepth)
初始化 AgentSpawnTool 实例。
Creates an AgentSpawnTool that derives the active user-id from each tool call's RuntimeContext, rather than a shared supplier — this prevents identity races when a single agent instance serves concurrent callers.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
agentManager | DefaultAgentManager | 智能体管理器(类型 `DefaultAgentManager`)。factory and invoker for subagents |
taskRepository | TaskRepository | 任务仓库(类型 `TaskRepository`)。background task store |
parentSpawnDepth | int | 父级 Spawn Depth(类型 `int`)。current spawn-depth of the parent (0 for top-level main agent) |
io/agentscope/harness/agent/tool/AgentSpawnTool.java:242–245AgentSpawnTool
public AgentSpawnTool(DefaultAgentManager agentManager, TaskRepository taskRepository, int parentSpawnDepth, SubagentGatewayBridge gatewayBridge)
初始化 AgentSpawnTool 实例。
Creates an AgentSpawnTool with an optional gateway bridge for exposing subagents as user-addressable threads.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
agentManager | DefaultAgentManager | 智能体管理器(类型 `DefaultAgentManager`)。factory and invoker for subagents |
taskRepository | TaskRepository | 任务仓库(类型 `TaskRepository`)。background task store |
parentSpawnDepth | int | 父级 Spawn Depth(类型 `int`)。current spawn-depth of the parent (0 for top-level main agent) |
gatewayBridge | SubagentGatewayBridge | 网关 Bridge(类型 `SubagentGatewayBridge`)。optional bridge for thread exposure; null for standalone mode |
io/agentscope/harness/agent/tool/AgentSpawnTool.java:256–265方法详情Method Detail
setGatewayBridge
public void setGatewayBridge(SubagentGatewayBridge gatewayBridge)
设置 setGatewayBridge。
Wires (or re-wires) the gateway bridge used to expose subagents as user-addressable threads.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
gatewayBridge | SubagentGatewayBridge | 网关 Bridge(类型 `SubagentGatewayBridge`)。the bridge implementation, or `null` to disable exposure |
io/agentscope/harness/agent/tool/AgentSpawnTool.java:278–280agentSpawn
public Mono<String> agentSpawn(RuntimeContext runtimeContext, AgentState parentState, String agentId, String task, String label, Integer timeoutSeconds, Boolean exposeToUser)
执行 agentSpawn 方法。
Performs the agent spawn operation.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
runtimeContext | RuntimeContext | 运行时上下文(类型 `RuntimeContext`)。The runtime context. |
parentState | AgentState | 父级状态(类型 `AgentState`)。The parent state. |
agentId | String | 智能体标识(类型 `String`)。The agent id. |
task | String | 任务(类型 `String`)。The task. |
label | String | 标签(类型 `String`)。The label. |
timeoutSeconds | Integer | 超时秒(类型 `Integer`)。The timeout seconds. |
exposeToUser | Boolean | expose 到用户(类型 `Boolean`)。The expose to user. |
Mono<String>io/agentscope/harness/agent/tool/AgentSpawnTool.java:287–545agentSend
public Mono<String> agentSend(RuntimeContext runtimeContext, AgentState parentState, String agentKey, String label, String message, Integer timeoutSeconds)
执行智能体发送相关操作。
Performs the agent send operation.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
runtimeContext | RuntimeContext | 运行时上下文(类型 `RuntimeContext`)。The runtime context. |
parentState | AgentState | 父级状态(类型 `AgentState`)。The parent state. |
agentKey | String | 智能体键(类型 `String`)。The agent key. |
label | String | 标签(类型 `String`)。The label. |
message | String | 消息(类型 `String`)。The message. |
timeoutSeconds | Integer | 超时秒(类型 `Integer`)。The timeout seconds. |
Mono<String>io/agentscope/harness/agent/tool/AgentSpawnTool.java:547–699agentList
public String agentList()
返回智能体列表。
Returns the agent list.
Stringio/agentscope/harness/agent/tool/AgentSpawnTool.java:701–718