dont load embedded provider if its not in use

This commit is contained in:
Dhanji Prasanna
2025-09-20 20:32:47 +10:00
parent 9a5486f2a8
commit cae16a7daf

View File

@@ -259,8 +259,13 @@ impl Agent {
pub async fn new(config: Config) -> Result<Self> { pub async fn new(config: Config) -> Result<Self> {
let mut providers = ProviderRegistry::new(); let mut providers = ProviderRegistry::new();
// Register providers based on configuration // Only register providers that are configured AND selected as the default provider
// This prevents unnecessary initialization of heavy providers like embedded models
// Register embedded provider if configured AND it's the default provider
if let Some(embedded_config) = &config.providers.embedded { if let Some(embedded_config) = &config.providers.embedded {
if config.providers.default_provider == "embedded" {
info!("Initializing embedded provider (selected as default)");
let embedded_provider = crate::providers::embedded::EmbeddedProvider::new( let embedded_provider = crate::providers::embedded::EmbeddedProvider::new(
embedded_config.model_path.clone(), embedded_config.model_path.clone(),
embedded_config.model_type.clone(), embedded_config.model_type.clone(),
@@ -271,10 +276,15 @@ impl Agent {
embedded_config.threads, embedded_config.threads,
)?; )?;
providers.register(embedded_provider); providers.register(embedded_provider);
} else {
info!("Embedded provider configured but not selected as default, skipping initialization");
}
} }
// Register Anthropic provider if configured // Register Anthropic provider if configured AND it's the default provider
if let Some(anthropic_config) = &config.providers.anthropic { if let Some(anthropic_config) = &config.providers.anthropic {
if config.providers.default_provider == "anthropic" {
info!("Initializing Anthropic provider (selected as default)");
let anthropic_provider = g3_providers::AnthropicProvider::new( let anthropic_provider = g3_providers::AnthropicProvider::new(
anthropic_config.api_key.clone(), anthropic_config.api_key.clone(),
Some(anthropic_config.model.clone()), Some(anthropic_config.model.clone()),
@@ -282,6 +292,9 @@ impl Agent {
anthropic_config.temperature, anthropic_config.temperature,
)?; )?;
providers.register(anthropic_provider); providers.register(anthropic_provider);
} else {
info!("Anthropic provider configured but not selected as default, skipping initialization");
}
} }
// Set default provider // Set default provider