pub struct SubAgentPool { /* private fields */ }Expand description
Pool for managing subagent instances.
Implementations§
Source§impl SubAgentPool
impl SubAgentPool
Sourcepub fn new(max_concurrent: usize, max_depth: usize) -> Self
pub fn new(max_concurrent: usize, max_depth: usize) -> Self
Create a new subagent pool with default history limit (1000 entries).
Sourcepub fn with_max_history(
max_concurrent: usize,
max_depth: usize,
max_history: usize,
) -> Self
pub fn with_max_history( max_concurrent: usize, max_depth: usize, max_history: usize, ) -> Self
Create a new subagent pool with explicit history limit.
Sourcepub async fn spawn(
&self,
task: impl Into<String>,
parent_id: Option<SubAgentId>,
) -> RuntimeResult<Arc<SubAgentHandle>>
pub async fn spawn( &self, task: impl Into<String>, parent_id: Option<SubAgentId>, ) -> RuntimeResult<Arc<SubAgentHandle>>
Spawn a new subagent.
§Errors
Returns an error if the maximum subagent depth is exceeded or concurrency limit is reached.
Sourcepub async fn release(&self, id: &SubAgentId)
pub async fn release(&self, id: &SubAgentId)
Release a subagent from the active pool and move to history.
Releases the semaphore permit so another sub-agent can be spawned. The handle’s status should already be set (completed/failed/timed out) before calling this.
Sourcepub async fn stop(&self, id: &SubAgentId) -> Option<Arc<SubAgentHandle>>
pub async fn stop(&self, id: &SubAgentId) -> Option<Arc<SubAgentHandle>>
Stop a specific subagent: cancel it and move to history.
Sourcepub async fn get(&self, id: &SubAgentId) -> Option<Arc<SubAgentHandle>>
pub async fn get(&self, id: &SubAgentId) -> Option<Arc<SubAgentHandle>>
Get active subagent by ID.
Sourcepub async fn list_active(&self) -> Vec<Arc<SubAgentHandle>>
pub async fn list_active(&self) -> Vec<Arc<SubAgentHandle>>
List active subagents.
Sourcepub async fn active_count(&self) -> usize
pub async fn active_count(&self) -> usize
Get count of active subagents.
Sourcepub fn available_permits(&self) -> usize
pub fn available_permits(&self) -> usize
Get available capacity.
Sourcepub async fn can_spawn_child(&self, parent_id: &SubAgentId) -> bool
pub async fn can_spawn_child(&self, parent_id: &SubAgentId) -> bool
Check if a child can be spawned for the given parent without actually spawning.
Returns true if both depth limit and concurrency permit are available.
Sourcepub fn cancellation_token(&self) -> CancellationToken
pub fn cancellation_token(&self) -> CancellationToken
Get the cancellation token for cooperative cancellation.
Sub-agent executors should select on this token in their run loop. Cancelling this token signals all sub-agents to stop cooperatively.
Sourcepub async fn cancel_all(&self)
pub async fn cancel_all(&self)
Cancel all active subagents and move them to history.
Also cancels the cooperative cancellation token so in-flight sub-agents can observe the cancellation and stop gracefully.
Sourcepub async fn wait_for_completion(&self)
pub async fn wait_for_completion(&self)
Wait until the active pool is empty.
Sourcepub async fn wait_for_completion_timeout(&self, timeout: Duration) -> bool
pub async fn wait_for_completion_timeout(&self, timeout: Duration) -> bool
Wait until the active pool is empty, or the timeout expires.
Returns true if the pool drained before the timeout, false otherwise.
Sourcepub async fn get_children(
&self,
parent_id: &SubAgentId,
) -> Vec<Arc<SubAgentHandle>>
pub async fn get_children( &self, parent_id: &SubAgentId, ) -> Vec<Arc<SubAgentHandle>>
Get direct children of a parent subagent (from both active and completed).
Sourcepub async fn get_subtree(
&self,
parent_id: &SubAgentId,
) -> Vec<Arc<SubAgentHandle>>
pub async fn get_subtree( &self, parent_id: &SubAgentId, ) -> Vec<Arc<SubAgentHandle>>
Get all descendants of a parent subagent (BFS, from both active and completed).
Sourcepub async fn cancel_subtree(&self, parent_id: &SubAgentId) -> usize
pub async fn cancel_subtree(&self, parent_id: &SubAgentId) -> usize
Cancel all active descendants of a parent subagent and move them to history.
Returns the number of subagents cancelled.
Sourcepub async fn history(&self) -> Vec<Arc<SubAgentHandle>>
pub async fn history(&self) -> Vec<Arc<SubAgentHandle>>
Get completed subagents history.
Sourcepub async fn clear_history(&self)
pub async fn clear_history(&self)
Clear completed history.
Sourcepub async fn stats(&self) -> SubAgentPoolStats
pub async fn stats(&self) -> SubAgentPoolStats
Get pool statistics.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for SubAgentPool
impl !RefUnwindSafe for SubAgentPool
impl Send for SubAgentPool
impl Sync for SubAgentPool
impl Unpin for SubAgentPool
impl UnsafeUnpin for SubAgentPool
impl !UnwindSafe for SubAgentPool
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> GetSetFdFlags for T
impl<T> GetSetFdFlags for T
Source§fn get_fd_flags(&self) -> Result<FdFlags, Error>where
T: AsFilelike,
fn get_fd_flags(&self) -> Result<FdFlags, Error>where
T: AsFilelike,
self file descriptor.Source§fn new_set_fd_flags(&self, fd_flags: FdFlags) -> Result<SetFdFlags<T>, Error>where
T: AsFilelike,
fn new_set_fd_flags(&self, fd_flags: FdFlags) -> Result<SetFdFlags<T>, Error>where
T: AsFilelike,
Source§fn set_fd_flags(&mut self, set_fd_flags: SetFdFlags<T>) -> Result<(), Error>where
T: AsFilelike,
fn set_fd_flags(&mut self, set_fd_flags: SetFdFlags<T>) -> Result<(), Error>where
T: AsFilelike,
self file descriptor. Read moreSource§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more