ekg m2+: add error-signature-aware provider ranking for fallback selection

This commit is contained in:
DBT
2026-03-01 04:32:34 +00:00
parent 1d5454066a
commit ed9e4203d3
2 changed files with 25 additions and 5 deletions

View File

@@ -350,7 +350,11 @@ func (al *AgentLoop) tryFallbackProviders(ctx context.Context, msg bus.InboundMe
lastErr := primaryErr
candidates := append([]string(nil), al.providerNames[1:]...)
if al.ekg != nil {
candidates = al.ekg.RankProviders(candidates)
errSig := ""
if primaryErr != nil {
errSig = primaryErr.Error()
}
candidates = al.ekg.RankProvidersForError(candidates, errSig)
}
for _, name := range candidates {
p, ok := al.providerPool[name]
@@ -361,11 +365,13 @@ func (al *AgentLoop) tryFallbackProviders(ctx context.Context, msg bus.InboundMe
if al.ekg != nil {
st := "success"
lg := "fallback provider success"
errSig := ""
if err != nil {
st = "error"
lg = err.Error()
errSig = err.Error()
}
al.ekg.Record(ekg.Event{Session: msg.SessionKey, Channel: msg.Channel, Source: "provider_fallback", Status: st, Provider: name, Model: al.model, Log: lg})
al.ekg.Record(ekg.Event{Session: msg.SessionKey, Channel: msg.Channel, Source: "provider_fallback", Status: st, Provider: name, Model: al.model, ErrSig: errSig, Log: lg})
}
if err == nil {
logger.WarnCF("agent", "LLM fallback provider switched", map[string]interface{}{"provider": name})