pub struct BackgroundToolTracker { /* private fields */ }Expand description
Tracks in-flight background tool executions for cancellation.
Uses [DashMap] internally so that spawned tasks can remove themselves
upon completion while the control lane concurrently spawns or cancels
other tasks.
Implementations§
Source§impl BackgroundToolTracker
impl BackgroundToolTracker
Sourcepub fn spawn(
&self,
call_id: String,
task: JoinHandle<()>,
cancel: CancellationToken,
)
pub fn spawn( &self, call_id: String, task: JoinHandle<()>, cancel: CancellationToken, )
Register a spawned background task.
The call_id is the unique identifier for the function call (usually
from [FunctionCall::id]). The caller provides both a
[JoinHandle] (for aborting) and a [CancellationToken] (for
cooperative cancellation).
Sourcepub fn cancel(&self, call_ids: &[String])
pub fn cancel(&self, call_ids: &[String])
Cancel specific tool calls by their IDs.
For each matching ID the cancellation token is triggered and the task handle is aborted, providing belt-and-suspenders cleanup. Non-existent IDs are silently ignored.
Sourcepub fn cancel_all(&self)
pub fn cancel_all(&self)
Cancel all in-flight background tasks.
Useful during session shutdown to ensure no orphaned tasks remain.
Sourcepub fn active_ids(&self) -> Vec<String>
pub fn active_ids(&self) -> Vec<String>
Get IDs of active background tool calls.
Sourcepub fn remove(&self, call_id: &str)
pub fn remove(&self, call_id: &str)
Remove a completed task (called when background task finishes).
This is typically invoked by the spawned task itself to clean up the tracker entry once execution is done.
Sourcepub fn active_count(&self) -> usize
pub fn active_count(&self) -> usize
Number of active background tasks.