pub struct SubAgentManager { /* private fields */ }Expand description
Manages named sub-agent configurations and spawns them.
Generic over nothing — the provider and context are passed at spawn time
because Provider and ContextStrategy use RPITIT and are not dyn-compatible.
Implementations§
Source§impl SubAgentManager
impl SubAgentManager
Sourcepub fn register(&mut self, name: impl Into<String>, config: SubAgentConfig)
pub fn register(&mut self, name: impl Into<String>, config: SubAgentConfig)
Register a named sub-agent configuration.
Sourcepub fn get(&self, name: &str) -> Option<&SubAgentConfig>
pub fn get(&self, name: &str) -> Option<&SubAgentConfig>
Get a registered sub-agent configuration by name.
Sourcepub async fn spawn<P: Provider, C: ContextStrategy>(
&self,
name: &str,
provider: P,
context: C,
parent_tools: &ToolRegistry,
user_message: Message,
tool_ctx: &ToolContext,
current_depth: usize,
) -> Result<AgentResult, SubAgentError>
pub async fn spawn<P: Provider, C: ContextStrategy>( &self, name: &str, provider: P, context: C, parent_tools: &ToolRegistry, user_message: Message, tool_ctx: &ToolContext, current_depth: usize, ) -> Result<AgentResult, SubAgentError>
Spawn a sub-agent by name, running it to completion.
Filters the parent’s tool registry to only include tools listed in the sub-agent’s configuration. Takes the provider and context strategy as generics because they use RPITIT.
§Errors
Returns SubAgentError::NotFound if the name is not registered.
Returns SubAgentError::MaxDepthExceeded if current_depth >= config.max_depth.
Returns SubAgentError::Loop if the sub-agent’s loop fails.
Sourcepub async fn spawn_parallel<P, C>(
&self,
tasks: Vec<(String, P, C, Message)>,
parent_tools: &ToolRegistry,
tool_ctx: &ToolContext,
current_depth: usize,
) -> Vec<Result<AgentResult, SubAgentError>>where
P: Provider,
C: ContextStrategy,
pub async fn spawn_parallel<P, C>(
&self,
tasks: Vec<(String, P, C, Message)>,
parent_tools: &ToolRegistry,
tool_ctx: &ToolContext,
current_depth: usize,
) -> Vec<Result<AgentResult, SubAgentError>>where
P: Provider,
C: ContextStrategy,
Spawn multiple sub-agents concurrently with the same parent tools and context.
Each entry is (name, provider, context, user_message). All share the
same parent tools and tool context. Results are returned in the same
order as the input.
Sub-agents run concurrently on the current task via futures::future::join_all,
which interleaves their execution without requiring 'static bounds. This
avoids the tokio::spawn limitation where Provider and ContextStrategy
RPITIT types are not 'static.
§Errors
Each element of the returned Vec is an independent Result. All
sub-agents are executed regardless of earlier failures.