Skip to main content

AgentPool

Struct AgentPool 

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

Manages a pool of background TaskAgents.

All agents share the same provider, tool executor, communication hub, file lock manager, and working directory. Each agent gets its own conversation history and working set.

Implementations§

Source§

impl AgentPool

Source

pub fn new( max_agents: usize, provider: Arc<dyn Provider>, tool_executor: Arc<dyn ToolExecutor>, communication_hub: Arc<CommunicationHub>, file_lock_manager: Arc<FileLockManager>, working_directory: impl Into<String>, ) -> Self

Create a new agent pool.

§Parameters
  • max_agents: maximum number of concurrently running agents.
  • provider: AI provider shared by all agents.
  • tool_executor: tool executor shared by all agents.
  • communication_hub: inter-agent message bus.
  • file_lock_manager: file coordination across agents.
  • working_directory: default working directory for spawned agents.
Source

pub async fn spawn_agent( &self, task: Task, config: Option<TaskAgentConfig>, ) -> Result<String>

Spawn a new task agent and start it on a Tokio background task.

Returns the agent ID. Use await_completion to wait for the result.

Returns an error if the pool is already at capacity.

Source

pub async fn spawn_agent_with_context( &self, task: Task, context: Arc<AgentContext>, config: Option<TaskAgentConfig>, ) -> Result<String>

Spawn a new task agent with a custom AgentContext.

Unlike spawn_agent which uses the pool’s default working directory, this method accepts a pre-built context. This is useful for workers that run in isolated worktrees with per-agent working directories.

Returns the agent ID.

Source

pub async fn get_status(&self, agent_id: &str) -> Option<TaskAgentStatus>

Get the current status of an agent.

Returns None if the agent is not in the pool.

Source

pub async fn get_task(&self, agent_id: &str) -> Option<Task>

Get a snapshot of the task assigned to an agent.

Source

pub async fn stop_agent(&self, agent_id: &str) -> Result<()>

Abort an agent and remove it from the pool.

File locks held by the agent are released immediately.

Source

pub async fn await_completion(&self, agent_id: &str) -> Result<TaskAgentResult>

Wait for an agent to finish and return its result.

The agent is removed from the pool once it completes.

Source

pub async fn list_active(&self) -> Vec<(String, TaskAgentStatus)>

List all agents currently in the pool with their status.

Source

pub async fn active_count(&self) -> usize

Number of agents currently in the pool (running or pending cleanup).

Source

pub async fn is_running(&self, agent_id: &str) -> bool

Returns true if the agent is still running (join handle not finished).

Source

pub async fn cleanup_completed(&self) -> Vec<(String, Result<TaskAgentResult>)>

Remove all finished agents from the pool and return their results.

Source

pub async fn await_all(&self) -> Vec<(String, Result<TaskAgentResult>)>

Wait for every agent in the pool to finish.

Source

pub async fn shutdown(&self)

Abort all agents and clear the pool.

Source

pub async fn stats(&self) -> AgentPoolStats

Get a statistical snapshot of the pool.

Source

pub fn file_lock_manager(&self) -> Arc<FileLockManager>

Get the shared file lock manager.

Source

pub fn communication_hub(&self) -> Arc<CommunicationHub>

Get the shared communication hub.

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> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
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> Same for T

Source§

type Output = T

Should always be Self
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
Source§

impl<T> ErasedDestructor for T
where T: 'static,