Skip to main content

spawn_subagent

Function spawn_subagent 

Source
pub async fn spawn_subagent<F, Fut, T>(
    thread_mgr: SharedThreadManager,
    options: SpawnOptions,
    task_fn: F,
) -> SubtaskHandle<T>
where F: FnOnce(CancellationToken, SharedThreadManager) -> Fut + Send + 'static, Fut: Future<Output = Result<T, String>> + Send + 'static, T: Send + 'static,
Expand description

Spawn a subagent as an async subtask.

The task_fn receives a CancellationToken and a SharedThreadManager. It should check the token periodically and return a result.

Returns a SubtaskHandle that can be joined to get the result.

§Example

let handle = spawn_subagent(
    thread_mgr.clone(),
    SpawnOptions::new("Research Task")
        .with_description("Searching for information"),
    |token, mgr| async move {
        // Do async work, checking token.is_cancelled()
        Ok("result data".to_string())
    },
).await;

// Later, join to get the result
let result = handle.join().await;