Skip to main content

StreamProvider

Trait StreamProvider 

Source
pub trait StreamProvider: Send + Sync {
    // Required methods
    fn provider_id(&self) -> &str;
    fn stream<'life0, 'async_trait>(
        &'life0 self,
        config: StreamConfig,
        tx: UnboundedSender<StreamEvent>,
        cancel: CancellationToken,
    ) -> Pin<Box<dyn Future<Output = Result<Message, ProviderError>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait;
}
Expand description

The core provider trait. Implement this for each LLM backend.

Required Methods§

Source

fn provider_id(&self) -> &str

Short, stable identifier for this provider type.

Used as the provider_id component of auto-derived loop_id signatures: loop_id = "{session_id}.{provider_id}.{model_slug}.{N}"

Return a lowercase ASCII string with no spaces (e.g. "anthropic", "openai", "google"). Custom providers should return a unique, stable string.

Source

fn stream<'life0, 'async_trait>( &'life0 self, config: StreamConfig, tx: UnboundedSender<StreamEvent>, cancel: CancellationToken, ) -> Pin<Box<dyn Future<Output = Result<Message, ProviderError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Stream a completion. Send events through tx in real time. Returns the final, fully-assembled assistant Message after the stream ends.

Implementors must:

  • Send StreamEvent::Start when the stream begins
  • Send StreamEvent::TextDelta / ThinkingDelta / ToolCall* as tokens arrive
  • Send StreamEvent::Done { message } or StreamEvent::Error { message } at the end
  • Honor cancel — stop early and return Err(ProviderError::Cancelled)

Implementors§