pub trait Model: Send + Sync {
// Required methods
fn api_type(&self) -> ApiType;
fn stream<'life0, 'async_trait>(
&'life0 self,
prompt_blocks: Vec<PromptBlock>,
tools: Vec<ToolDef>,
messages: Vec<ModelMessage>,
params: StreamParams,
cancel: CancellationToken,
) -> Pin<Box<dyn Future<Output = Result<ModelStream, ModelError>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait;
// Provided method
fn provenance(&self) -> Option<String> { ... }
}Expand description
Protocol-agnostic LLM client trait.
Implementations translate PromptBlock and ToolDef into
the API-specific wire format (Anthropic Messages, OpenAI Chat Completions).
Required Methods§
Sourcefn stream<'life0, 'async_trait>(
&'life0 self,
prompt_blocks: Vec<PromptBlock>,
tools: Vec<ToolDef>,
messages: Vec<ModelMessage>,
params: StreamParams,
cancel: CancellationToken,
) -> Pin<Box<dyn Future<Output = Result<ModelStream, ModelError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn stream<'life0, 'async_trait>(
&'life0 self,
prompt_blocks: Vec<PromptBlock>,
tools: Vec<ToolDef>,
messages: Vec<ModelMessage>,
params: StreamParams,
cancel: CancellationToken,
) -> Pin<Box<dyn Future<Output = Result<ModelStream, ModelError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Stream a response from the LLM.
Returns a stream of ModelEvents (text deltas, tool use blocks).
The cancel token allows the caller to abort mid-stream.
Provided Methods§
Sourcefn provenance(&self) -> Option<String>
fn provenance(&self) -> Option<String>
The provider id this client was built for, stamped on the reasoning
it produces so a later request to a different provider does not echo
it back. A client that routes between providers has none of its own:
each of its calls names its provider with ModelEvent::Served.
None for a client built outside a provider route; reasoning from
such a client carries no provenance and is sent wherever it goes.
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".