fix: support cross-backend cheap provider for smart routing#2298
Open
swagasaurus wants to merge 2 commits intonearai:stagingfrom
Open
fix: support cross-backend cheap provider for smart routing#2298swagasaurus wants to merge 2 commits intonearai:stagingfrom
swagasaurus wants to merge 2 commits intonearai:stagingfrom
Conversation
When LLM_CHEAP_BACKEND differs from LLM_BACKEND, resolve the cheap provider independently through the provider registry instead of cloning the primary backend's RegistryProviderConfig. Previously, create_cheap_provider_for_backend() always used the primary backend's config and only swapped the model name. This meant setting LLM_CHEAP_BACKEND=ollama with LLM_BACKEND=anthropic would route hermes3 through Anthropic's API instead of Ollama. Changes: - Add cheap_backend and cheap_provider fields to LlmConfig - Add llm_cheap_backend to Settings (DB/serde) - Wire LLM_CHEAP_BACKEND env var and llm_cheap_backend DB setting into config resolution, including custom provider lookup - In create_cheap_provider_for_backend(), check cheap_backend first and use the independently resolved cheap_provider when available Backward compatible: when cheap_backend is unset or matches the primary backend, existing behavior is preserved. Fixes: #1
Contributor
|
The new code path ( I'd like to see more testing. Unit tests:
For manual verification without cloud keys: Nits:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Support cross-backend cheap provider resolution for smart routing. When
LLM_CHEAP_BACKENDdiffers fromLLM_BACKEND, the cheap provider is now resolved independently through the provider registry instead of cloning the primary backend's config.Fixes a bug where
create_cheap_provider_for_backend()always used the primary backend'sRegistryProviderConfigand only swapped the model name — meaningLLM_CHEAP_BACKEND=ollamawithLLM_BACKEND=anthropicwould route hermes3 through Anthropic's API.Root Cause
LLM_CHEAP_BACKEND/llm_cheap_backendDB setting had zero references in Rust source. The setting was stored but never consumed byLlmConfig, socreate_cheap_provider_for_backend()had no way to resolve a different provider.Changes
src/llm/config.rscheap_backend: Option<String>andcheap_provider: Option<RegistryProviderConfig>fields toLlmConfigsrc/settings.rsllm_cheap_backend: Option<String>toSettings(DB/serde deserialization)src/config/llm.rsLLM_CHEAP_BACKENDenv var andllm_cheap_backendDB setting into config resolutionllm_custom_providers) and built-in registrysrc/llm/mod.rscreate_cheap_provider_for_backend(), checkcheap_backendfirstcheap_providercheap_backendis unset or matches primarysrc/llm/models.rsBackward Compatible
When
cheap_backendis unset or matches the primary backend, existing behavior is preserved exactly. The new code path only activates when cross-backend routing is explicitly configured.Testing
Tested with:
anthropic/claude-opus-4-6home(Ollama adapter athttp://127.0.0.1:11434) /hermes3