Skip to main content

drive

Function drive 

Source
pub async fn drive<F, Fut>(
    algorithm: Arc<dyn Algorithm>,
    ctx: Context,
    request: Request,
    observer: Option<RunObserver>,
    serve: F,
) -> Result<(Vec<Arc<dyn Decision>>, Response)>
where F: Fn(CallLlmRequest) -> Fut, Fut: Future<Output = Result<()>>,
Expand description

Drive Algorithm::run_stream to completion, handing each offloaded call to serve.

Returns the final Response and the trace of Decisions the algorithm published. observer, when present, is passed through to run_stream.

serve owns the call: it performs it however the host likes and must fulfill the promise with CallLlmRequest::respond. A failed model call belongs in respond — the algorithm may route around it. Returning Err from serve aborts the whole run, so reserve it for infrastructure failures. Calls are served concurrently, so an algorithm that offloads several at once (hedging, fan-out) gets real parallelism.

libsy performs no I/O; this is only the mechanics of consuming its own step stream, kept here so every host does not reimplement the same loop. switchyard-llm-client’s run is this function plus an HTTP client.