Skip to main content

LLMProvider

Trait LLMProvider 

Source
pub trait LLMProvider: Send + Sync {
Show 32 methods // Required methods fn name(&self) -> &str; fn generate<'life0, 'async_trait>( &'life0 self, request: LLMRequest, ) -> Pin<Box<dyn Future<Output = Result<LLMResponse, LLMError>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait; fn supported_models(&self) -> Vec<String>; fn validate_request(&self, request: &LLMRequest) -> Result<(), LLMError>; // Provided methods fn supports_decisions(&self) -> bool { ... } fn decide_choice<'life0, 'async_trait>( &'life0 self, _request: ChoiceDecisionRequest, ) -> Pin<Box<dyn Future<Output = Result<ChoiceDecisionResponse, LLMError>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait { ... } fn backend_kind(&self) -> BackendKind { ... } fn supports_streaming(&self) -> bool { ... } fn supports_non_streaming(&self, _model: &str) -> bool { ... } fn supports_reasoning(&self, _model: &str) -> bool { ... } fn supports_reasoning_effort(&self, _model: &str) -> bool { ... } fn supported_reasoning_efforts( &self, model: &str, ) -> &'static [&'static str] { ... } fn sampling_overrides(&self, _model: &str) -> SamplingOverrides { ... } fn supports_tools(&self, _model: &str) -> bool { ... } fn supports_parallel_tool_config(&self, _model: &str) -> bool { ... } fn supports_structured_output(&self, _model: &str) -> bool { ... } fn supports_context_caching(&self, _model: &str) -> bool { ... } fn supports_vision(&self, _model: &str) -> bool { ... } fn supports_responses_compaction(&self, _model: &str) -> bool { ... } fn supports_native_allowed_tools(&self, _model: &str) -> bool { ... } fn supports_context_edits(&self, _model: &str) -> bool { ... } fn supports_turn_scoped_system_messages(&self, _model: &str) -> bool { ... } fn supports_manual_openai_compaction(&self, _model: &str) -> bool { ... } fn supports_native_inline_compaction(&self, _model: &str) -> bool { ... } fn manual_openai_compaction_unavailable_message( &self, model: &str, ) -> String { ... } fn effective_context_size(&self, model: &str) -> usize { ... } fn compact_history<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, _model: &'life1 str, _history: &'life2 [Message], ) -> Pin<Box<dyn Future<Output = Result<Vec<Message>, LLMError>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait { ... } fn compact_history_with_options<'life0, 'life1, 'life2, 'life3, 'async_trait>( &'life0 self, _model: &'life1 str, _history: &'life2 [Message], _options: &'life3 ResponsesCompactionOptions, ) -> Pin<Box<dyn Future<Output = Result<Vec<Message>, LLMError>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait, 'life3: 'async_trait { ... } fn stream<'life0, 'async_trait>( &'life0 self, request: LLMRequest, ) -> Pin<Box<dyn Future<Output = Result<LLMStream, LLMError>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait { ... } fn stream_normalized<'life0, 'async_trait>( &'life0 self, request: LLMRequest, ) -> Pin<Box<dyn Future<Output = Result<LLMNormalizedStream, LLMError>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait { ... } fn start_copilot_prompt_session<'a>( &'a self, _request: LLMRequest, _tools: &'a [ToolDefinition], ) -> Option<CopilotPromptSessionFuture<'a>> { ... } fn get_balance<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = Result<Option<BalanceInfo>, LLMError>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait { ... }
}
Expand description

Universal LLM provider trait

Required Methods§

Source

fn name(&self) -> &str

Provider name (e.g., “gemini”, “openai”, “anthropic”)

Source

fn generate<'life0, 'async_trait>( &'life0 self, request: LLMRequest, ) -> Pin<Box<dyn Future<Output = Result<LLMResponse, LLMError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Generate completion

Source

fn supported_models(&self) -> Vec<String>

Get supported models

Source

fn validate_request(&self, request: &LLMRequest) -> Result<(), LLMError>

Validate request for this provider

Provided Methods§

Source

fn supports_decisions(&self) -> bool

Whether this instance can use the direct API-key Decisions endpoint. Capability checks must not discover credentials or dispatch requests.

Source

fn decide_choice<'life0, 'async_trait>( &'life0 self, _request: ChoiceDecisionRequest, ) -> Pin<Box<dyn Future<Output = Result<ChoiceDecisionResponse, LLMError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Evaluate one text-only choice question. Unsupported providers do no I/O.

Source

fn backend_kind(&self) -> BackendKind

The canonical backend kind for this provider.

Defaults to matching on name() against the well-known provider names. Providers should override this when their name does not match the canonical mapping (e.g., dynamic names).

Source

fn supports_streaming(&self) -> bool

Whether the provider has native streaming support

Source

fn supports_non_streaming(&self, _model: &str) -> bool

Whether the provider can service non-streaming generation requests for the model.

Source

fn supports_reasoning(&self, _model: &str) -> bool

Whether the provider surfaces structured reasoning traces for the given model

Source

fn supports_reasoning_effort(&self, _model: &str) -> bool

Whether the provider accepts configurable reasoning effort for the model

Source

fn supported_reasoning_efforts(&self, model: &str) -> &'static [&'static str]

Exact levels accepted by this route; providers may override catalog metadata.

Source

fn sampling_overrides(&self, _model: &str) -> SamplingOverrides

Provider/model-specific sampling parameter overrides.

Custom-provider profiles may pin exact sampling values per model; every field defaults to None, meaning the agent loop’s global config value applies unchanged.

Source

fn supports_tools(&self, _model: &str) -> bool

Whether the provider supports structured tool calling for the given model

Source

fn supports_parallel_tool_config(&self, _model: &str) -> bool

Whether the provider understands parallel tool configuration payloads

Source

fn supports_structured_output(&self, _model: &str) -> bool

Whether the provider supports structured output (JSON schema guarantees)

Source

fn supports_context_caching(&self, _model: &str) -> bool

Whether the provider supports prompt/context caching

Source

fn supports_vision(&self, _model: &str) -> bool

Whether the provider supports vision (image analysis) for given model

Source

fn supports_responses_compaction(&self, _model: &str) -> bool

Whether the provider supports Responses API server-side compaction.

Source

fn supports_native_allowed_tools(&self, _model: &str) -> bool

Whether the request path can enforce a provider-native allowed_tools subset.

Source

fn supports_context_edits(&self, _model: &str) -> bool

Whether the provider supports provider-native context editing such as tool-result clearing.

Source

fn supports_turn_scoped_system_messages(&self, _model: &str) -> bool

Whether the selected provider/model can carry Anthropic’s native turn-scoped system-message lifecycle field on the wire.

This is intentionally narrower than Self::supports_context_edits: a provider can expose Anthropic-shaped requests without supporting the clear_at field, and a provider name does not necessarily identify the wire protocol for every model. The runtime keeps the typed marker in canonical history either way, translating it to an ordinary system or history directive when this capability is false.

Source

fn supports_manual_openai_compaction(&self, _model: &str) -> bool

Whether the provider supports the interactive manual /compact command path.

This is narrower than general Responses compaction support and may exclude compatible endpoints that do not match VT Code’s native OpenAI UX contract.

Source

fn supports_native_inline_compaction(&self, _model: &str) -> bool

Whether the provider supports threshold-triggered inline compaction via request fields (Anthropic compact_20260112).

This is distinct from supports_responses_compaction, which is overloaded: OpenAI-compatible endpoints report it for their standalone /responses/compact endpoint while Anthropic reports it for inline compaction. Only the latter can be driven through generate with a compact_20260112 context-management edit, so the unified compaction dispatch uses this method (not the overloaded flag) to pick the NativeInline strategy and avoid sending an Anthropic-specific payload to an OpenAI-compatible endpoint (which would only be rejected and fall back to local summarization anyway).

Source

fn manual_openai_compaction_unavailable_message(&self, model: &str) -> String

Explain why the --native-only manual /compact path is unavailable.

This message only surfaces when the user explicitly passes --native-only and the provider does not expose a native server-side compaction endpoint. The plain /compact command is provider-agnostic and always falls back to local summarization, so it is never refused on capability grounds.

Source

fn effective_context_size(&self, model: &str) -> usize

Get the effective context window size for a model.

Curated catalog capacity is the default for providers that do not have a narrower route-specific limit. Adapters with an explicit endpoint ceiling can still override this method and keep that ceiling intact.

Source

fn compact_history<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, _model: &'life1 str, _history: &'life2 [Message], ) -> Pin<Box<dyn Future<Output = Result<Vec<Message>, LLMError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait,

Compact conversation history using provider-native Responses /compact support when available.

Source

fn compact_history_with_options<'life0, 'life1, 'life2, 'life3, 'async_trait>( &'life0 self, _model: &'life1 str, _history: &'life2 [Message], _options: &'life3 ResponsesCompactionOptions, ) -> Pin<Box<dyn Future<Output = Result<Vec<Message>, LLMError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait, 'life3: 'async_trait,

Compact conversation history with standalone Responses compaction options.

Source

fn stream<'life0, 'async_trait>( &'life0 self, request: LLMRequest, ) -> Pin<Box<dyn Future<Output = Result<LLMStream, LLMError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Stream completion (optional)

Source

fn stream_normalized<'life0, 'async_trait>( &'life0 self, request: LLMRequest, ) -> Pin<Box<dyn Future<Output = Result<LLMNormalizedStream, LLMError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Normalized streaming contract layered on top of the legacy provider stream.

Source

fn start_copilot_prompt_session<'a>( &'a self, _request: LLMRequest, _tools: &'a [ToolDefinition], ) -> Option<CopilotPromptSessionFuture<'a>>

Provider-specific streaming path that can service interactive runtime requests while the stream is active. Copilot uses this to bridge ACP tool calls and permission prompts back into VT Code’s turn runtime.

Source

fn get_balance<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = Result<Option<BalanceInfo>, LLMError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Fetch account balance for this provider, if supported.

Dyn Compatibility§

This trait is dyn compatible.

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

Implementors§