feat(config): add model presets for quick model switching#3696
Closed
chengyongru wants to merge 4 commits into
Closed
feat(config): add model presets for quick model switching#3696chengyongru wants to merge 4 commits into
chengyongru wants to merge 4 commits into
Conversation
Add ModelPresetConfig schema and model_presets dictionary to config, enabling named bundles of model parameters (model, temperature, max_tokens, reasoning_effort, context_window_tokens) that can be switched atomically at runtime via the self tool.
When the primary model fails (finish_reason="error" after exhausting provider-level retries), automatically try each model in the configured fallback_models list. Supports cross-provider fallback via a cached provider_factory that resolves the correct provider for each model string. Config: agents.defaults.fallback_models: ["model-b", "provider/model-c"] Changes: - AgentDefaults: add fallback_models field - AgentRunSpec: add fallback_models field - AgentRunner: add provider_factory, _call_provider, _resolve_fallback_provider - AgentLoop: accept and forward fallback_models + provider_factory - nanobot.py: extract _make_provider_for_model, add _make_provider_factory - cli/commands.py: add _make_cli_provider_factory, wire all AgentLoop sites - tests/agent/test_runner_fallback.py: 8 test cases covering primary success, single/multi fallback, cross-provider, no-factory reuse, caching Made-with: Cursor
…er factory - Restrict fallback_models to only reference preset names in model_presets. - Add schema validation to reject unknown preset names in fallback_models. - Remove build_provider_for_model() since bare model fallback is no longer supported. - Simplify make_provider_factory() to only look up presets by name. - Update onboard UI to remove "Add custom model" option from fallback chain. - Update tests to use preset names instead of bare model strings in fallback chains. - Fix test imports referencing deleted _make_provider function.
This was referenced May 9, 2026
Collaborator
Author
|
This PR is too large and needs to be reasonably split. |
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
Add named model presets with automatic failover and runtime switching support.
ModelPresetConfigbundles model + provider + generation parameters. Defined inmodel_presetsdict, activated viamodel_presetonAgentDefaults.ModelRouter): Whenfallback_presetsis configured, the primary provider is wrapped with a router that retries provider-internal errors against fallback presets in order.AgentLoop.model_presetsetter resolves preset by name, creates provider via factory, wraps with failover, and atomically updates all subsystems.make_provider_factory(config)builds a cached factory that creates providers from preset names only.AgentLoop.from_config(): New classmethod that encapsulates bus/provider/loop assembly, used by both CLI (serve,chat) andNanobotfacade.[M] Model Presetssection with add / edit / delete support.@xzq-xu thanks for your contribution
@boogieLing thanks for your contribution
(cherry-picked from #3358)