Skip to main content

Model

Trait Model 

Source
pub trait Model: Send + Sync {
    // Required method
    fn respond<'a>(
        &'a self,
        request: ModelRequest<'a>,
        events: ModelEventSink,
    ) -> BoxFuture<'a, Result<ModelOutput>>;

    // Provided methods
    fn info(&self) -> ModelInfo { ... }
    fn supports_image_input(&self) -> bool { ... }
    fn supports_tool_image_input(&self) -> bool { ... }
    fn supports_realtime_voice(&self) -> bool { ... }
    fn start_realtime_voice(
        &self,
        _request: RealtimeVoiceRequest,
    ) -> BoxFuture<'_, Result<RealtimeVoiceCall>> { ... }
    fn prompt_cache_capability(&self) -> PromptCacheMode { ... }
    fn tool_discovery(&self) -> ToolDiscoveryMode { ... }
    fn pricing(&self) -> Option<ModelPricing> { ... }
    fn fallback_transport<'a>(
        &'a self,
        _session_id: &'a str,
    ) -> BoxFuture<'a, Result<bool>> { ... }
    fn compaction_endpoint(&self) -> bool { ... }
    fn compact<'a>(
        &'a self,
        _request: CompactRequest<'a>,
    ) -> BoxFuture<'a, Result<CompactOutput>> { ... }
}
Expand description

A model provider Adapter used by the agent loop.

Required Methods§

Source

fn respond<'a>( &'a self, request: ModelRequest<'a>, events: ModelEventSink, ) -> BoxFuture<'a, Result<ModelOutput>>

Produces one streamed response.

Normalize provider wire data into crate::protocol::ModelEvent and ModelOutput. Emit only immutable, fully validated crate::protocol::ModelEvent::ToolCallReady calls, in the same order as the final output; the agent may execute them before stream EOF, so the final output must agree. Propagate ModelEventSink failures. The returned future may be dropped on cancellation; implementations own cleanup of any transport work they launch outside that future.

Provided Methods§

Source

fn info(&self) -> ModelInfo

Returns stable display metadata without exposing credentials.

Source

fn supports_image_input(&self) -> bool

Reports whether this provider accepts native image input.

Source

fn supports_tool_image_input(&self) -> bool

Whether images can remain associated with their originating tool call.

Source

fn supports_realtime_voice(&self) -> bool

Reports whether this transport can negotiate a provider-owned realtime voice call.

Source

fn start_realtime_voice( &self, _request: RealtimeVoiceRequest, ) -> BoxFuture<'_, Result<RealtimeVoiceCall>>

Negotiates voice media without exposing provider credentials to the frontend.

Source

fn prompt_cache_capability(&self) -> PromptCacheMode

Reports the provider’s prompt-cache mode without exposing transport details.

Source

fn tool_discovery(&self) -> ToolDiscoveryMode

Reports how this route makes deferred tool schemas callable.

Source

fn pricing(&self) -> Option<ModelPricing>

Returns current token pricing when this provider owns a known billing schedule.

Source

fn fallback_transport<'a>( &'a self, _session_id: &'a str, ) -> BoxFuture<'a, Result<bool>>

Switches a session to its fallback transport once, without sending a request.

Called after retry exhaustion only when replaying the model request is safe. Returns whether a new transport was activated; providers without one return false.

Source

fn compaction_endpoint(&self) -> bool

Reports whether this provider exposes a native compaction endpoint.

Source

fn compact<'a>( &'a self, _request: CompactRequest<'a>, ) -> BoxFuture<'a, Result<CompactOutput>>

Calls the native history-compaction endpoint when advertised.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§