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
impl AgentPool
Sourcepub 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
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.
Sourcepub async fn spawn_agent(
&self,
task: Task,
config: Option<TaskAgentConfig>,
) -> Result<String>
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.
Sourcepub async fn spawn_agent_with_context(
&self,
task: Task,
context: Arc<AgentContext>,
config: Option<TaskAgentConfig>,
) -> Result<String>
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.
Sourcepub async fn get_status(&self, agent_id: &str) -> Option<TaskAgentStatus>
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.
Sourcepub async fn get_task(&self, agent_id: &str) -> Option<Task>
pub async fn get_task(&self, agent_id: &str) -> Option<Task>
Get a snapshot of the task assigned to an agent.
Sourcepub async fn stop_agent(&self, agent_id: &str) -> Result<()>
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.
Sourcepub async fn await_completion(&self, agent_id: &str) -> Result<TaskAgentResult>
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.
Sourcepub async fn list_active(&self) -> Vec<(String, TaskAgentStatus)>
pub async fn list_active(&self) -> Vec<(String, TaskAgentStatus)>
List all agents currently in the pool with their status.
Sourcepub async fn active_count(&self) -> usize
pub async fn active_count(&self) -> usize
Number of agents currently in the pool (running or pending cleanup).
Sourcepub async fn is_running(&self, agent_id: &str) -> bool
pub async fn is_running(&self, agent_id: &str) -> bool
Returns true if the agent is still running (join handle not finished).
Sourcepub async fn cleanup_completed(&self) -> Vec<(String, Result<TaskAgentResult>)>
pub async fn cleanup_completed(&self) -> Vec<(String, Result<TaskAgentResult>)>
Remove all finished agents from the pool and return their results.
Sourcepub async fn await_all(&self) -> Vec<(String, Result<TaskAgentResult>)>
pub async fn await_all(&self) -> Vec<(String, Result<TaskAgentResult>)>
Wait for every agent in the pool to finish.
Sourcepub async fn stats(&self) -> AgentPoolStats
pub async fn stats(&self) -> AgentPoolStats
Get a statistical snapshot of the pool.
Sourcepub fn file_lock_manager(&self) -> Arc<FileLockManager>
pub fn file_lock_manager(&self) -> Arc<FileLockManager>
Get the shared file lock manager.
Sourcepub fn communication_hub(&self) -> Arc<CommunicationHub>
pub fn communication_hub(&self) -> Arc<CommunicationHub>
Get the shared communication hub.