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§
Sourcefn provider_id(&self) -> &str
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.
Sourcefn 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,
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::Startwhen the stream begins - Send
StreamEvent::TextDelta/ThinkingDelta/ToolCall*as tokens arrive - Send
StreamEvent::Done { message }orStreamEvent::Error { message }at the end - Honor
cancel— stop early and returnErr(ProviderError::Cancelled)
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".