Skip to main content

Pool

Struct Pool 

Source
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>

Source

pub fn builder(claude: Claude) -> PoolBuilder<InMemoryStore>

Create a builder with the default in-memory store.

Source§

impl<S: PoolStore + 'static> Pool<S>

Source

pub fn builder_with_store(claude: Claude, store: S) -> PoolBuilder<S>

Create a builder with a custom store.

Source

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.

Source

pub async fn run_with_config( &self, prompt: &str, task_config: Option<SlotConfig>, ) -> Result<TaskResult>

Run a task with per-task config overrides.

Source

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.

Source

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.

Source

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.

Source

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.

Source

pub async fn cancel(&self, task_id: &TaskId) -> Result<()>

Cancel a pending or running task.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

pub fn get_context(&self, key: &str) -> Option<String>

Get a shared context value.

Source

pub fn delete_context(&self, key: &str) -> Option<String>

Remove a shared context value.

Source

pub fn list_context(&self) -> Vec<(String, String)>

List all context keys and values.

Source

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.

Source

pub async fn status(&self) -> Result<PoolStatus>

Get a snapshot of pool status.

Source

pub fn store(&self) -> &S

Get a reference to the store.

Source

pub fn config(&self) -> &PoolConfig

Get a reference to the pool configuration.

Source

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.

Source

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.

Source

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.

Source

pub async fn set_target_slots(&self, target: usize) -> Result<usize>

Set the target number of slots, scaling up or down as needed.

Trait Implementations§

Source§

impl<S: PoolStore> Clone for Pool<S>

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more

Auto Trait Implementations§

§

impl<S> Freeze for Pool<S>

§

impl<S> !RefUnwindSafe for Pool<S>

§

impl<S> Send for Pool<S>

§

impl<S> Sync for Pool<S>

§

impl<S> Unpin for Pool<S>

§

impl<S> UnsafeUnpin for Pool<S>

§

impl<S> !UnwindSafe for Pool<S>

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. 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