pub struct Pool<S: PoolStore> { /* private fields */ }Expand description
A pool of Claude CLI slots.
Created via Pool::builder. Manages slot lifecycle, task routing,
and budget enforcement.
Implementations§
Source§impl Pool<InMemoryStore>
impl Pool<InMemoryStore>
Sourcepub fn builder(claude: Claude) -> PoolBuilder<InMemoryStore>
pub fn builder(claude: Claude) -> PoolBuilder<InMemoryStore>
Create a builder with the default in-memory store.
Source§impl<S: PoolStore + 'static> Pool<S>
impl<S: PoolStore + 'static> Pool<S>
Sourcepub fn builder_with_store(claude: Claude, store: S) -> PoolBuilder<S>
pub fn builder_with_store(claude: Claude, store: S) -> PoolBuilder<S>
Create a builder with a custom store.
Sourcepub async fn run(&self, prompt: &str) -> Result<TaskResult>
pub async fn run(&self, prompt: &str) -> Result<TaskResult>
Run a task synchronously, blocking until completion.
Assigns the task to the next idle slot, executes the prompt, and returns the result.
Sourcepub async fn run_with_config(
&self,
prompt: &str,
task_config: Option<SlotConfig>,
) -> Result<TaskResult>
pub async fn run_with_config( &self, prompt: &str, task_config: Option<SlotConfig>, ) -> Result<TaskResult>
Run a task with per-task config overrides.
Sourcepub async fn run_with_config_and_dir(
&self,
prompt: &str,
task_config: Option<SlotConfig>,
working_dir: Option<PathBuf>,
) -> Result<TaskResult>
pub async fn run_with_config_and_dir( &self, prompt: &str, task_config: Option<SlotConfig>, working_dir: Option<PathBuf>, ) -> Result<TaskResult>
Run a task with per-task config overrides and an optional working directory override.
Sourcepub async fn submit(&self, prompt: &str) -> Result<TaskId>
pub async fn submit(&self, prompt: &str) -> Result<TaskId>
Submit a task for async execution, returning the task ID immediately.
Use Pool::result to poll for completion.
Sourcepub async fn submit_with_config(
&self,
prompt: &str,
task_config: Option<SlotConfig>,
tags: Vec<String>,
) -> Result<TaskId>
pub async fn submit_with_config( &self, prompt: &str, task_config: Option<SlotConfig>, tags: Vec<String>, ) -> Result<TaskId>
Submit a task with config overrides and tags.
Sourcepub async fn result(&self, task_id: &TaskId) -> Result<Option<TaskResult>>
pub async fn result(&self, task_id: &TaskId) -> Result<Option<TaskResult>>
Get the result of a submitted task.
Returns None if the task is still pending/running.
Sourcepub async fn cancel_chain(&self, task_id: &TaskId) -> Result<()>
pub async fn cancel_chain(&self, task_id: &TaskId) -> Result<()>
Cancel a running chain, skipping remaining steps.
Sets the chain’s task state to Cancelled. The currently-executing step
(if any) runs to completion; remaining steps are then skipped. Partial
results are available via Pool::result once the chain finishes.
Sourcepub async fn fan_out(&self, prompts: &[&str]) -> Result<Vec<TaskResult>>
pub async fn fan_out(&self, prompts: &[&str]) -> Result<Vec<TaskResult>>
Execute tasks in parallel across available slots, collecting all results.
Queues excess prompts until a slot becomes idle. Returns once all prompts complete or timeout waiting for slot availability.
Sourcepub async fn submit_chain(
&self,
steps: Vec<ChainStep>,
skills: &SkillRegistry,
options: ChainOptions,
) -> Result<TaskId>
pub async fn submit_chain( &self, steps: Vec<ChainStep>, skills: &SkillRegistry, options: ChainOptions, ) -> Result<TaskId>
Submit a chain for async execution, returning a task ID immediately.
Use Pool::chain_progress to check per-step progress, or
Pool::result to get the final crate::ChainResult (serialized as JSON)
once complete.
Sourcepub async fn fan_out_chains(
&self,
chains: Vec<Vec<ChainStep>>,
skills: &SkillRegistry,
options: ChainOptions,
) -> Result<Vec<TaskId>>
pub async fn fan_out_chains( &self, chains: Vec<Vec<ChainStep>>, skills: &SkillRegistry, options: ChainOptions, ) -> Result<Vec<TaskId>>
Submit multiple chains for parallel execution, returning all task IDs immediately.
Each chain runs on its own slot concurrently. Use Pool::chain_progress to check
per-step progress, or Pool::result to get the final result once complete.
Sourcepub async fn submit_workflow(
&self,
workflow_name: &str,
arguments: HashMap<String, String>,
skills: &SkillRegistry,
workflows: &WorkflowRegistry,
tags: Vec<String>,
) -> Result<TaskId>
pub async fn submit_workflow( &self, workflow_name: &str, arguments: HashMap<String, String>, skills: &SkillRegistry, workflows: &WorkflowRegistry, tags: Vec<String>, ) -> Result<TaskId>
Submit a workflow template for async execution.
Instantiates the workflow by substituting placeholders with arguments, then submits the resulting chain. Returns the task ID immediately.
Sourcepub fn chain_progress(&self, task_id: &TaskId) -> Option<ChainProgress>
pub fn chain_progress(&self, task_id: &TaskId) -> Option<ChainProgress>
Get the progress of an in-flight chain.
Returns None if no chain is tracked for this task ID.
Sourcepub fn set_context(&self, key: impl Into<String>, value: impl Into<String>)
pub fn set_context(&self, key: impl Into<String>, value: impl Into<String>)
Set a shared context value.
Context is injected into slot system prompts at task start.
Sourcepub fn get_context(&self, key: &str) -> Option<String>
pub fn get_context(&self, key: &str) -> Option<String>
Get a shared context value.
Sourcepub fn delete_context(&self, key: &str) -> Option<String>
pub fn delete_context(&self, key: &str) -> Option<String>
Remove a shared context value.
Sourcepub fn list_context(&self) -> Vec<(String, String)>
pub fn list_context(&self) -> Vec<(String, String)>
List all context keys and values.
Sourcepub async fn drain(&self) -> Result<DrainSummary>
pub async fn drain(&self) -> Result<DrainSummary>
Gracefully shut down the pool.
Marks the pool as shut down so no new tasks are accepted, then waits for in-flight tasks to complete.
Sourcepub async fn status(&self) -> Result<PoolStatus>
pub async fn status(&self) -> Result<PoolStatus>
Get a snapshot of pool status.
Sourcepub fn config(&self) -> &PoolConfig
pub fn config(&self) -> &PoolConfig
Get a reference to the pool configuration.
Sourcepub fn start_supervisor(&self) -> Option<SupervisorHandle>
pub fn start_supervisor(&self) -> Option<SupervisorHandle>
Start the background supervisor loop.
The supervisor periodically checks for errored slots and restarts them
(up to PoolConfig::max_restarts). Returns a SupervisorHandle
that can be used to stop the loop.
Returns None if PoolConfig::supervisor_enabled is false.
Sourcepub async fn scale_up(&self, count: usize) -> Result<usize>
pub async fn scale_up(&self, count: usize) -> Result<usize>
Scale up the pool by adding N new slots.
Returns the new total slot count. Fails if the new count exceeds max_slots.
Sourcepub async fn scale_down(&self, count: usize) -> Result<usize>
pub async fn scale_down(&self, count: usize) -> Result<usize>
Scale down the pool by removing N slots.
Removes idle slots first. If not enough idle slots are available, waits for busy slots to complete (with timeout) before removing them. Returns the new total slot count. Fails if the new count drops below min_slots.
Sourcepub async fn set_target_slots(&self, target: usize) -> Result<usize>
pub async fn set_target_slots(&self, target: usize) -> Result<usize>
Set the target number of slots, scaling up or down as needed.