pub struct ProviderRegistry { /* private fields */ }Expand description
Registry for managing multiple named LLM providers
The ProviderRegistry holds references to provider configurations and allows creating LLM clients for specific models or providers by name.
Implementations§
Source§impl ProviderRegistry
impl ProviderRegistry
Sourcepub fn new() -> ProviderRegistry
pub fn new() -> ProviderRegistry
Create a new empty provider registry
Sourcepub fn from_config(
providers: HashMap<String, ProviderConfig>,
models: HashMap<String, ModelConfig>,
nvidia: Option<&NvidiaConfig>,
) -> ProviderRegistry
pub fn from_config( providers: HashMap<String, ProviderConfig>, models: HashMap<String, ModelConfig>, nvidia: Option<&NvidiaConfig>, ) -> ProviderRegistry
Create a provider registry from TOML configuration
Sourcepub fn reload_runtime_providers(
&self,
providers: Vec<RuntimeProviderEntry>,
names: Vec<String>,
)
pub fn reload_runtime_providers( &self, providers: Vec<RuntimeProviderEntry>, names: Vec<String>, )
Hot-swap the runtime provider map. Called by admin endpoints after mutating the DB so the new providers are visible immediately.
Sourcepub fn with_catalog(self, catalog: Arc<NvidiaCatalogCache>) -> ProviderRegistry
pub fn with_catalog(self, catalog: Arc<NvidiaCatalogCache>) -> ProviderRegistry
Attach a live catalog cache (used after construction for background refresh).
Sourcepub fn set_default_model(&mut self, model_name: &str)
pub fn set_default_model(&mut self, model_name: &str)
Set the default model name
Sourcepub fn register_provider(&mut self, name: &str, config: ProviderConfig)
pub fn register_provider(&mut self, name: &str, config: ProviderConfig)
Register a provider configuration (legacy no-op if providers are already managed).
Sourcepub fn register_model(&mut self, name: &str, config: ModelConfig)
pub fn register_model(&mut self, name: &str, config: ModelConfig)
Register a model configuration (legacy backward-compat).
Sourcepub fn unregister_provider(&mut self, name: &str) -> Option<ProviderConfig>
pub fn unregister_provider(&mut self, name: &str) -> Option<ProviderConfig>
Remove a provider by name.
Sourcepub fn unregister_model(&mut self, name: &str) -> Option<ModelConfig>
pub fn unregister_model(&mut self, name: &str) -> Option<ModelConfig>
Remove a model by name.
Sourcepub fn get_provider(&self, name: &str) -> Option<ProviderConfig>
pub fn get_provider(&self, name: &str) -> Option<ProviderConfig>
Get a provider configuration by name.
Runtime providers are checked first and synthesized into a ProviderConfig
on the fly; legacy static configs are checked second. The return value is
cloned so that the caller owns it — this is required because runtime
providers are materialised from the arc-swapped map rather than stored as
ProviderConfig internally.
Sourcepub fn get_provider_for_ctx(
&self,
ctx: &Arc<Context>,
name: &str,
) -> Option<ProviderConfig>
pub fn get_provider_for_ctx( &self, ctx: &Arc<Context>, name: &str, ) -> Option<ProviderConfig>
Resolve a provider visible to the tenant derived from the context’s isolate
namespace. Reads ctx.isolate_label(TypeId::of::<Llm>()) and
strips a leading tenant:/user: prefix (mirroring
ares_agent::resolver::user_id_from_ctx), delegating to
crate-private tenant lookup with the derived tenant (None when unlabeled).
Sourcepub fn get_model(&self, name: &str) -> Option<ModelConfig>
pub fn get_model(&self, name: &str) -> Option<ModelConfig>
Get a model configuration by name. Checks explicit legacy models first, then falls back to the live catalog.
Sourcepub fn provider_names(&self) -> Vec<String>
pub fn provider_names(&self) -> Vec<String>
Get all provider names (legacy + runtime).
Sourcepub fn model_names(&self) -> Vec<String>
pub fn model_names(&self) -> Vec<String>
Get all model names (legacy + catalog ids)
Sourcepub async fn create_client_for_model(
&self,
model_name: &str,
) -> Result<Box<dyn LLMClient>, AppError>
pub async fn create_client_for_model( &self, model_name: &str, ) -> Result<Box<dyn LLMClient>, AppError>
Create an LLM client for a specific model by name.
Fleet-wide tenant resolution (tenant None).
Sourcepub async fn create_client_for_model_ctx(
&self,
ctx: &Arc<Context>,
model_name: &str,
) -> Result<Box<dyn LLMClient>, AppError>
pub async fn create_client_for_model_ctx( &self, ctx: &Arc<Context>, model_name: &str, ) -> Result<Box<dyn LLMClient>, AppError>
Create an LLM client for a specific model by name, deriving the tenant from the context’s isolate namespace so tenant-scoped runtime providers are used when the caller holds a tenant-isolated context.
Sourcepub async fn create_client_for_provider(
&self,
provider_name: &str,
) -> Result<Box<dyn LLMClient>, AppError>
pub async fn create_client_for_provider( &self, provider_name: &str, ) -> Result<Box<dyn LLMClient>, AppError>
Create an LLM client for a specific provider by name
Sourcepub async fn create_client_for_resolved_provider(
&self,
resolved: &ResolvedProviderConfig,
) -> Result<Box<dyn LLMClient>, AppError>
pub async fn create_client_for_resolved_provider( &self, resolved: &ResolvedProviderConfig, ) -> Result<Box<dyn LLMClient>, AppError>
Create an LLM client for an already-resolved provider/model pair.
Sourcepub async fn create_default_client(
&self,
) -> Result<Box<dyn LLMClient>, AppError>
pub async fn create_default_client( &self, ) -> Result<Box<dyn LLMClient>, AppError>
Create an LLM client using the default model
Sourcepub fn has_provider(&self, name: &str) -> bool
pub fn has_provider(&self, name: &str) -> bool
Check if a provider exists in the registry (legacy or runtime).
pub fn has_provider_for_tenant( &self, name: &str, tenant_id: Option<&str>, ) -> bool
Sourcepub fn get_model_capabilities(
&self,
model_name: &str,
) -> Option<ModelCapabilities>
pub fn get_model_capabilities( &self, model_name: &str, ) -> Option<ModelCapabilities>
Get capabilities for a registered model.
Sourcepub fn models_with_capabilities(&self) -> Vec<ModelWithCapabilities>
pub fn models_with_capabilities(&self) -> Vec<ModelWithCapabilities>
Get all models with their capabilities.
Sourcepub fn find_models(
&self,
requirements: &CapabilityRequirements,
) -> Vec<ModelWithCapabilities>
pub fn find_models( &self, requirements: &CapabilityRequirements, ) -> Vec<ModelWithCapabilities>
Find models that satisfy the given capability requirements.
Sourcepub fn find_best_model(
&self,
requirements: &CapabilityRequirements,
) -> Option<ModelWithCapabilities>
pub fn find_best_model( &self, requirements: &CapabilityRequirements, ) -> Option<ModelWithCapabilities>
Find the best model for the given requirements.
Sourcepub async fn create_client_for_requirements(
&self,
requirements: &CapabilityRequirements,
) -> Result<Box<dyn LLMClient>, AppError>
pub async fn create_client_for_requirements( &self, requirements: &CapabilityRequirements, ) -> Result<Box<dyn LLMClient>, AppError>
Create an LLM client for the best model matching requirements.
Sourcepub fn find_agent_models(&self) -> Vec<ModelWithCapabilities>
pub fn find_agent_models(&self) -> Vec<ModelWithCapabilities>
Find models suitable for agent tasks (tool calling required).
Sourcepub fn find_vision_models(&self) -> Vec<ModelWithCapabilities>
pub fn find_vision_models(&self) -> Vec<ModelWithCapabilities>
Find models suitable for vision tasks.
Sourcepub fn find_coding_models(&self) -> Vec<ModelWithCapabilities>
pub fn find_coding_models(&self) -> Vec<ModelWithCapabilities>
Find models suitable for coding tasks.
Sourcepub fn find_local_models(&self) -> Vec<ModelWithCapabilities>
pub fn find_local_models(&self) -> Vec<ModelWithCapabilities>
Find local-only models.
Sourcepub fn list_models(&self) -> Vec<ModelInfo>
pub fn list_models(&self) -> Vec<ModelInfo>
List all registered models with their provider info.
Sourcepub async fn resolve_with_capability_fallback(
&self,
requirements: Option<CapabilityRequirements>,
) -> Result<Box<dyn LLMClient>, AppError>
pub async fn resolve_with_capability_fallback( &self, requirements: Option<CapabilityRequirements>, ) -> Result<Box<dyn LLMClient>, AppError>
Capability-aware fallback chain for Llm.
Tries create_client_for_requirements for the given requirements if
Some, then falls back to create_default_client. This reuses the
existing find_best_model → create_client_for_model chain and the
coordinator’s fallback semantics without requiring a database.
Sourcepub async fn resolve_with_fallback(
&self,
tier_or_model: &str,
tenant_id: &str,
pool: &Pool<Postgres>,
fleet_secrets: &FleetSecrets,
) -> Result<Vec<ResolvedProviderConfig>, AppError>
pub async fn resolve_with_fallback( &self, tier_or_model: &str, tenant_id: &str, pool: &Pool<Postgres>, fleet_secrets: &FleetSecrets, ) -> Result<Vec<ResolvedProviderConfig>, AppError>
Resolve a model tier or model name to concrete provider/model entries,
following the fallback chain stored in fleet_secrets for the primary provider.
- Looks up
tenant_model_tiersfor the tenant + tier. - Falls back to the registry’s configured models.
- Falls back to treating
tier_or_modelas a provider name. - Loads the primary provider’s
fallback_providersfrom fleet secrets and appends each resolved provider with its own concrete default model.
Trait Implementations§
Source§impl Default for ProviderRegistry
impl Default for ProviderRegistry
Source§fn default() -> ProviderRegistry
fn default() -> ProviderRegistry
Source§impl Service for ProviderRegistry
impl Service for ProviderRegistry
Auto Trait Implementations§
impl !RefUnwindSafe for ProviderRegistry
impl !UnwindSafe for ProviderRegistry
impl Freeze for ProviderRegistry
impl Send for ProviderRegistry
impl Sync for ProviderRegistry
impl Unpin for ProviderRegistry
impl UnsafeUnpin for ProviderRegistry
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
impl<T> ErasedDestructor for Twhere
T: 'static,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreimpl<T> MaybeSendSync for T
Source§impl<T> Pipe for Twhere
T: ?Sized,
impl<T> Pipe for Twhere
T: ?Sized,
Source§fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
Source§fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
self and passes that borrow into the pipe function. Read moreSource§fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
self and passes that borrow into the pipe function. Read moreSource§fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
Source§fn pipe_borrow_mut<'a, B, R>(
&'a mut self,
func: impl FnOnce(&'a mut B) -> R,
) -> R
fn pipe_borrow_mut<'a, B, R>( &'a mut self, func: impl FnOnce(&'a mut B) -> R, ) -> R
Source§fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
self, then passes self.as_ref() into the pipe function.Source§fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
self, then passes self.as_mut() into the pipe
function.Source§fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
self, then passes self.deref() into the pipe function.Source§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> Read<Exclusive, BecauseExclusive> for Twhere
T: ?Sized,
Source§impl<T> Tap for T
impl<T> Tap for T
Source§fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
Borrow<B> of a value. Read moreSource§fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
BorrowMut<B> of a value. Read moreSource§fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
AsRef<R> view of a value. Read moreSource§fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
AsMut<R> view of a value. Read moreSource§fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
Deref::Target of a value. Read moreSource§fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
Deref::Target of a value. Read moreSource§fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
.tap() only in debug builds, and is erased in release builds.Source§fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
.tap_mut() only in debug builds, and is erased in release
builds.Source§fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
.tap_borrow() only in debug builds, and is erased in release
builds.Source§fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
.tap_borrow_mut() only in debug builds, and is erased in release
builds.Source§fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
.tap_ref() only in debug builds, and is erased in release
builds.Source§fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
.tap_ref_mut() only in debug builds, and is erased in release
builds.Source§fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
.tap_deref() only in debug builds, and is erased in release
builds.