Class DefaultAgentManager
This is the agent-internal layer. It has no session registry, no lane
management, no run tracking. The
agent-internal AgentSpawnTool uses this directly for
lightweight subagent invocation.
-
Constructor Summary
ConstructorsConstructorDescriptionDefaultAgentManager(List<SubagentEntry> entries, WorkspaceManager workspaceManager) Builds a manager from subagent entries (factories plus optionalSubagentDeclarationmetadata for remote configuration). -
Method Summary
Modifier and TypeMethodDescriptionio.agentscope.core.agent.AgentcreateAgent(String agentId, io.agentscope.core.agent.RuntimeContext parentRc) Creates a new agent instance from the registered factory.Optional<io.agentscope.core.agent.Agent>createAgentIfPresent(String agentId, io.agentscope.core.agent.RuntimeContext parentRc) Race-safe lookup-and-create.Immutable view of registered subagent factories keyed byagent_id.getDeclaration(String agentId) Optional declaration metadata for the givenagent_id(e.g. remote URL).booleanWhether a factory is registered for the given agent id.reactor.core.publisher.Mono<io.agentscope.core.message.Msg>invokeAgent(io.agentscope.core.agent.Agent agent, String sessionId, String userId, String prompt) Invokes an agent with a user prompt.reactor.core.publisher.Mono<io.agentscope.core.message.Msg>invokeAgent(io.agentscope.core.agent.Agent agent, String sessionId, String userId, String prompt, io.agentscope.core.agent.RuntimeContext parentRc) reactor.core.publisher.Flux<io.agentscope.core.agent.Event>invokeAgentStream(io.agentscope.core.agent.Agent agent, String sessionId, String userId, String prompt, io.agentscope.core.agent.EventSource source, io.agentscope.core.agent.StreamOptions options) Invokes an agent and returns its execution as a taggedFluxofEvents.reactor.core.publisher.Flux<io.agentscope.core.agent.Event>invokeAgentStream(io.agentscope.core.agent.Agent agent, String sessionId, String userId, String prompt, io.agentscope.core.agent.EventSource source, io.agentscope.core.agent.StreamOptions options, io.agentscope.core.agent.RuntimeContext parentRc) booleanisPrimaryOnly(String agentId) ReturnstruewhenagentIdis registered with aPRIMARY-only declaration.voidrefreshEntries(List<SubagentEntry> entries) Replaces the current set of entries with a new snapshot.voidreplaceAgents(List<SubagentEntry> entries) Atomic alias ofrefreshEntries(List)used byDynamicSubagentsMiddlewareto swap the registered subagent set on every reasoning step.
-
Constructor Details
-
DefaultAgentManager
Builds a manager from subagent entries (factories plus optionalSubagentDeclarationmetadata for remote configuration).
-
-
Method Details
-
refreshEntries
Replaces the current set of entries with a new snapshot. -
replaceAgents
Atomic alias ofrefreshEntries(List)used byDynamicSubagentsMiddlewareto swap the registered subagent set on every reasoning step. The two volatile reference assignments below ensure any concurrent reader observes either the previous snapshot or the new one fully — never a partial state. -
createAgentIfPresent
public Optional<io.agentscope.core.agent.Agent> createAgentIfPresent(String agentId, io.agentscope.core.agent.RuntimeContext parentRc) Race-safe lookup-and-create. ReturnsOptional.empty()when no factory is registered foragentIdat the moment of the volatile read, when the registered declaration isSubagentDeclaration.Mode.PRIMARY-only (cannot be spawned as a subagent), otherwise returns a freshly created agent. Preferred over the two-stephasAgent(String)+createAgent(String, RuntimeContext)pair when the registry may be replaced concurrently (e.g. dynamic reload between calls).parentRcis forwarded toSubagentFactory.create(RuntimeContext)so child agents can bucket their persisted state by parent identity. PassRuntimeContext.empty()when no parent context is available. -
isPrimaryOnly
ReturnstruewhenagentIdis registered with aPRIMARY-only declaration. LetsAgentSpawnToolproduce a more helpful error message ("PRIMARY-only, cannot be spawned") instead of the generic "Unknown agent_id" whencreateAgentIfPresent(java.lang.String, io.agentscope.core.agent.RuntimeContext)returns empty. -
hasAgent
Whether a factory is registered for the given agent id. -
getAgentFactories
Immutable view of registered subagent factories keyed byagent_id. -
getDeclaration
Optional declaration metadata for the givenagent_id(e.g. remote URL). -
createAgent
public io.agentscope.core.agent.Agent createAgent(String agentId, io.agentscope.core.agent.RuntimeContext parentRc) Creates a new agent instance from the registered factory.- Throws:
IllegalArgumentException- if no factory is registered for the given id
-
invokeAgent
public reactor.core.publisher.Mono<io.agentscope.core.message.Msg> invokeAgent(io.agentscope.core.agent.Agent agent, String sessionId, String userId, String prompt) Invokes an agent with a user prompt. Handles both plainAgentandHarnessAgent(injectsRuntimeContextfor the latter).For
HarnessAgentchildren,userIdis propagated so that isolation-key resolution (e.g.USER-scoped sandbox slots) works correctly. A freshsessionIdis always assigned independently of the parent session.- Parameters:
agent- the agent to invokesessionId- a new, child-specific session iduserId- the parent's user-id (may benull)prompt- the user message to send
-
invokeAgent
-
invokeAgentStream
public reactor.core.publisher.Flux<io.agentscope.core.agent.Event> invokeAgentStream(io.agentscope.core.agent.Agent agent, String sessionId, String userId, String prompt, io.agentscope.core.agent.EventSource source, io.agentscope.core.agent.StreamOptions options) Invokes an agent and returns its execution as a taggedFluxofEvents.Every event in the returned flux carries an
EventSourcebuilt fromsourcecombined with the child'sagentId/sessionId. This allows parent consumers to identify which subagent emitted each event without out-of-band metadata.The
parentSourceargument should be theEventSourcealready stored in the parent's Reactor Context (if any). When the parent itself is a subagent, its path is used as the prefix so the full call-hierarchy path is preserved across multiple nesting levels.- Parameters:
agent- the agent to invokesessionId- a new, child-specific session iduserId- the parent's user-id (may benull)prompt- the user message to sendsource- theEventSourcethat will be stamped onto every emitted eventoptions- stream configuration passed to the child agent- Returns:
Fluxof tagged events; never null
-
invokeAgentStream
public reactor.core.publisher.Flux<io.agentscope.core.agent.Event> invokeAgentStream(io.agentscope.core.agent.Agent agent, String sessionId, String userId, String prompt, io.agentscope.core.agent.EventSource source, io.agentscope.core.agent.StreamOptions options, io.agentscope.core.agent.RuntimeContext parentRc) -
getWorkspaceManager
-