AS AgentScopeAPI 手册 / API Reference

AgentSpawnTool

public class AgentSpawnTool
源码Source 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_USER
staticfinal
String
CTX EXPOSE 到用户字段。
`RuntimeContext` string key for a per-call override of subagent user-exposure.
CTX_AGENT_MANAGER
staticfinal
String
CTX 智能体管理器字段。
`RuntimeContext` string key for the immutable subagent registry selected by the current parent-agent invocation.
CTX_REMOTE_CONTEXT_ATTRIBUTES
staticfinal
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_SYNC
staticfinal
String
CTX FORCE 同步字段。
`RuntimeContext` string key that forces synchronous subagent execution for the current call.
CTX_FORCE_SYNC_TIMEOUT_SECONDS
staticfinal
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
staticfinal

CTX EXPOSE 到用户字段。声明为 public static final String CTX_EXPOSE_TO_USER。

RuntimeContext string key for a per-call override of subagent user-exposure.

源码Source io/agentscope/harness/agent/tool/AgentSpawnTool.java:130

CTX_AGENT_MANAGER

public static final String CTX_AGENT_MANAGER
staticfinal

CTX 智能体管理器字段。声明为 public static final String CTX_AGENT_MANAGER。

RuntimeContext string key for the immutable subagent registry selected by the current parent-agent invocation.

源码Source io/agentscope/harness/agent/tool/AgentSpawnTool.java:138

CTX_REMOTE_CONTEXT_ATTRIBUTES

public static final String CTX_REMOTE_CONTEXT_ATTRIBUTES
staticfinal

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…

源码Source io/agentscope/harness/agent/tool/AgentSpawnTool.java:156–157

CTX_FORCE_SYNC

public static final String CTX_FORCE_SYNC
staticfinal

CTX FORCE 同步字段。声明为 public static final String CTX_FORCE_SYNC。

RuntimeContext string key that forces synchronous subagent execution for the current call.

源码Source io/agentscope/harness/agent/tool/AgentSpawnTool.java:185

CTX_FORCE_SYNC_TIMEOUT_SECONDS

public static final String CTX_FORCE_SYNC_TIMEOUT_SECONDS
staticfinal

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.

源码Source 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.

参数Parameters
名称Name类型Type说明Description
agentManagerDefaultAgentManager智能体管理器(类型 `DefaultAgentManager`)。factory and invoker for subagents
taskRepositoryTaskRepository任务仓库(类型 `TaskRepository`)。background task store
parentSpawnDepthint父级 Spawn Depth(类型 `int`)。current spawn-depth of the parent (0 for top-level main agent)
源码Source io/agentscope/harness/agent/tool/AgentSpawnTool.java:242–245

AgentSpawnTool

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.

参数Parameters
名称Name类型Type说明Description
agentManagerDefaultAgentManager智能体管理器(类型 `DefaultAgentManager`)。factory and invoker for subagents
taskRepositoryTaskRepository任务仓库(类型 `TaskRepository`)。background task store
parentSpawnDepthint父级 Spawn Depth(类型 `int`)。current spawn-depth of the parent (0 for top-level main agent)
gatewayBridgeSubagentGatewayBridge网关 Bridge(类型 `SubagentGatewayBridge`)。optional bridge for thread exposure; null for standalone mode
源码Source 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.

参数Parameters
名称Name类型Type说明Description
gatewayBridgeSubagentGatewayBridge网关 Bridge(类型 `SubagentGatewayBridge`)。the bridge implementation, or `null` to disable exposure
源码Source io/agentscope/harness/agent/tool/AgentSpawnTool.java:278–280

agentSpawn

public Mono<String> agentSpawn(RuntimeContext runtimeContext, AgentState parentState, String agentId, String task, String label, Integer timeoutSeconds, Boolean exposeToUser)

执行 agentSpawn 方法。

Performs the agent spawn operation.

参数Parameters
名称Name类型Type说明Description
runtimeContextRuntimeContext运行时上下文(类型 `RuntimeContext`)。The runtime context.
parentStateAgentState父级状态(类型 `AgentState`)。The parent state.
agentIdString智能体标识(类型 `String`)。The agent id.
taskString任务(类型 `String`)。The task.
labelString标签(类型 `String`)。The label.
timeoutSecondsInteger超时秒(类型 `Integer`)。The timeout seconds.
exposeToUserBooleanexpose 到用户(类型 `Boolean`)。The expose to user.
返回Returns Mono<String>
返回Mono。Returns mono.
源码Source io/agentscope/harness/agent/tool/AgentSpawnTool.java:287–545

agentSend

public Mono<String> agentSend(RuntimeContext runtimeContext, AgentState parentState, String agentKey, String label, String message, Integer timeoutSeconds)

执行智能体发送相关操作。

Performs the agent send operation.

参数Parameters
名称Name类型Type说明Description
runtimeContextRuntimeContext运行时上下文(类型 `RuntimeContext`)。The runtime context.
parentStateAgentState父级状态(类型 `AgentState`)。The parent state.
agentKeyString智能体键(类型 `String`)。The agent key.
labelString标签(类型 `String`)。The label.
messageString消息(类型 `String`)。The message.
timeoutSecondsInteger超时秒(类型 `Integer`)。The timeout seconds.
返回Returns Mono<String>
返回Mono。Returns mono.
源码Source io/agentscope/harness/agent/tool/AgentSpawnTool.java:547–699

agentList

public String agentList()

返回智能体列表。

Returns the agent list.

返回Returns String
返回字符串结果。Returns a string.
源码Source io/agentscope/harness/agent/tool/AgentSpawnTool.java:701–718
基于官方固定版本源码静态生成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.