Skip to main content

SwarmManager

Struct SwarmManager 

Source
pub struct SwarmManager { /* private fields */ }
Expand description

Manages a swarm of sub-agents.

Implementations§

Source§

impl SwarmManager

Source

pub fn new() -> Self

Source

pub fn with_limits(self, max_agents: usize, max_depth: usize) -> Self

Source

pub fn with_depth(self, depth: usize) -> Self

Source

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.

Source

pub async fn status(&self, id: &AgentId) -> Option<AgentStatus>

Get the status of a sub-agent.

Source

pub async fn status_all(&self) -> Vec<(AgentId, AgentRole, AgentStatus)>

Get status of all agents.

Source

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.

Source

pub fn take_all_receivers(&mut self) -> Vec<(AgentId, Receiver<SwarmResult>)>

Take all pending result receivers (non-async, fast).

Source

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.

Source

pub async fn wait_all(&mut self) -> Vec<SwarmResult>

Wait for all agents to complete. Cleans up all agent handles after completion.

Source

pub fn cancel(&self, id: &AgentId) -> Result<(), SwarmError>

Cancel a specific agent.

Source

pub fn cancel_all(&self)

Cancel all running agents.

Source

pub async fn try_recv_notification(&self) -> Option<AgentNotification>

Receive the next completion notification (non-blocking).

Source

pub async fn recv_notification( &self, timeout: Duration, ) -> Option<AgentNotification>

Receive notifications, blocking until one arrives or timeout.

Source

pub fn cleanup(&mut self, id: &AgentId)

Remove a completed agent handle (cleanup).

Source

pub fn agent_count(&self) -> usize

Number of agents (including completed with pending results).

Source

pub fn active_count(&self) -> usize

Number of agents still holding a result receiver (not yet waited).

Source

pub fn all_agent_ids(&self) -> Vec<AgentId>

Get all agent IDs.

Source

pub async fn status_all_formatted(&self) -> String

Format all agent statuses as a human-readable string.

Source

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.

Source

pub async fn status_summary(&self) -> String

Format active agents as a status summary (for environment context).

Trait Implementations§

Source§

impl Default for SwarmManager

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more