pub struct SwarmManager { /* private fields */ }Expand description
Manages a swarm of sub-agents.
Implementations§
Source§impl SwarmManager
impl SwarmManager
pub fn new() -> Self
pub fn with_limits(self, max_agents: usize, max_depth: usize) -> Self
pub fn with_depth(self, depth: usize) -> Self
Sourcepub fn spawn(
&mut self,
config: SpawnConfig,
agent: Box<dyn Agent>,
tools: ToolRegistry,
parent_ctx: &AgentContext,
) -> Result<AgentId, SwarmError>
pub fn spawn( &mut self, config: SpawnConfig, agent: Box<dyn Agent>, tools: ToolRegistry, parent_ctx: &AgentContext, ) -> Result<AgentId, SwarmError>
Spawn a sub-agent. Returns its ID.
The agent runs in a background tokio task. When complete, a notification is sent through the notification channel.
Sourcepub async fn status(&self, id: &AgentId) -> Option<AgentStatus>
pub async fn status(&self, id: &AgentId) -> Option<AgentStatus>
Get the status of a sub-agent.
Sourcepub async fn status_all(&self) -> Vec<(AgentId, AgentRole, AgentStatus)>
pub async fn status_all(&self) -> Vec<(AgentId, AgentRole, AgentStatus)>
Get status of all agents.
Sourcepub fn take_receiver(
&mut self,
id: &AgentId,
) -> Result<Receiver<SwarmResult>, SwarmError>
pub fn take_receiver( &mut self, id: &AgentId, ) -> Result<Receiver<SwarmResult>, SwarmError>
Take the result receiver for an agent (non-async, fast). Call this under the lock, then drop the lock before awaiting.
Sourcepub fn take_all_receivers(&mut self) -> Vec<(AgentId, Receiver<SwarmResult>)>
pub fn take_all_receivers(&mut self) -> Vec<(AgentId, Receiver<SwarmResult>)>
Take all pending result receivers (non-async, fast).
Sourcepub async fn wait(&mut self, id: &AgentId) -> Result<SwarmResult, SwarmError>
pub async fn wait(&mut self, id: &AgentId) -> Result<SwarmResult, SwarmError>
Wait for a specific agent to complete. Returns its result. Cleans up the agent handle after completion.
Sourcepub async fn wait_all(&mut self) -> Vec<SwarmResult>
pub async fn wait_all(&mut self) -> Vec<SwarmResult>
Wait for all agents to complete. Cleans up all agent handles after completion.
Sourcepub fn cancel_all(&self)
pub fn cancel_all(&self)
Cancel all running agents.
Sourcepub async fn try_recv_notification(&self) -> Option<AgentNotification>
pub async fn try_recv_notification(&self) -> Option<AgentNotification>
Receive the next completion notification (non-blocking).
Sourcepub async fn recv_notification(
&self,
timeout: Duration,
) -> Option<AgentNotification>
pub async fn recv_notification( &self, timeout: Duration, ) -> Option<AgentNotification>
Receive notifications, blocking until one arrives or timeout.
Sourcepub fn agent_count(&self) -> usize
pub fn agent_count(&self) -> usize
Number of agents (including completed with pending results).
Sourcepub fn active_count(&self) -> usize
pub fn active_count(&self) -> usize
Number of agents still holding a result receiver (not yet waited).
Sourcepub fn all_agent_ids(&self) -> Vec<AgentId>
pub fn all_agent_ids(&self) -> Vec<AgentId>
Get all agent IDs.
Sourcepub async fn status_all_formatted(&self) -> String
pub async fn status_all_formatted(&self) -> String
Format all agent statuses as a human-readable string.
Sourcepub async fn wait_with_timeout(
&mut self,
ids: &[AgentId],
timeout: Duration,
) -> Vec<(AgentId, String)>
pub async fn wait_with_timeout( &mut self, ids: &[AgentId], timeout: Duration, ) -> Vec<(AgentId, String)>
Wait for multiple agents with timeout. Returns (id, formatted_result) pairs.
Sourcepub async fn status_summary(&self) -> String
pub async fn status_summary(&self) -> String
Format active agents as a status summary (for environment context).