feat(models): add configurable default fallback chain (#3200)

* feat(models): add configurable default fallback chain

* fix(lint): resolve linter issues

* fix(models): keep default fallback chain valid

* fix(models): normalize default chain on model writes

* fix(models): harden fallback chain consistency

* fix(models): preserve raw model provider injection

* fix(agent): preserve provider-prefixed model configs

* fix(agent): preserve injected provider contracts

* fix(agent): preserve fallback providers after model switch

* fix(build): update Go to 1.25.13
This commit is contained in:
LC authored and GitHub committed 2026-08-19 17:17:32 +08:00
1 parent 49183d7e8d
commit bbf6893ca7
39 files changed
+5376 -436

No files matched your search

+25 -1
View File
@@ -20,11 +20,19 @@ type FallbackCandidate struct {
DisplayName string // optional configured alias/raw model label for persistence/UI
RPM int // requests per minute; 0 means unrestricted
IdentityKey string // optional stable config identity for cooldown/rate limiting
ConfigIndex int // optional 1-based model_list index selected during resolution
ConfigKey string // optional hashed model_list identity, stable across reordering
}
// StableKey returns the candidate's config-level identity when available,
// otherwise it falls back to the runtime provider/model key.
func (c FallbackCandidate) StableKey() string {
if configKey := strings.TrimSpace(c.ConfigKey); configKey != "" {
if identityKey := strings.TrimSpace(c.IdentityKey); identityKey != "" {
return identityKey + "|" + configKey
}
return configKey
}
if key := strings.TrimSpace(c.IdentityKey); key != "" {
return key
}
@@ -275,6 +283,22 @@ func (fc *FallbackChain) ExecuteImage(
ctx context.Context,
candidates []FallbackCandidate,
run func(ctx context.Context, provider, model string) (*LLMResponse, error),
) (*FallbackResult, error) {
return fc.ExecuteImageCandidate(
ctx,
candidates,
func(ctx context.Context, candidate FallbackCandidate) (*LLMResponse, error) {
return run(ctx, candidate.Provider, candidate.Model)
},
)
}
// ExecuteImageCandidate preserves model-list identity metadata for each image
// fallback attempt.
func (fc *FallbackChain) ExecuteImageCandidate(
ctx context.Context,
candidates []FallbackCandidate,
run func(ctx context.Context, candidate FallbackCandidate) (*LLMResponse, error),
) (*FallbackResult, error) {
if len(candidates) == 0 {
return nil, fmt.Errorf("image fallback: no candidates configured")
@@ -318,7 +342,7 @@ func (fc *FallbackChain) ExecuteImage(
}
start := time.Now()
resp, err := run(ctx, candidate.Provider, candidate.Model)
resp, err := run(ctx, candidate)
elapsed := time.Since(start)
if err == nil {