Skip to main content

spawn_and_stream

Function spawn_and_stream 

Source
pub async fn spawn_and_stream<F>(
    runner: &dyn AgentRunner,
    config: &TaskConfig,
    parse_line: F,
    cancel_token: Option<CancellationToken>,
) -> Result<StreamHandle>
where F: Fn(&str) -> Vec<Result<Event>> + Send + Sync + 'static,
Expand description

Spawns an agent subprocess and returns a StreamHandle containing an EventStream and a CancellationToken.

This is the shared scaffolding used by every adapter — the only thing that differs per-agent is arg construction and line parsing.

The parser function returns a Vec so that a single JSON line can produce multiple events (e.g., an assistant message with both text + tool_use blocks).

If cancel_token is None, a new token is created internally.