58beb7ce3c
Phase 4 routing decisions depend on knowing whether the SLM classifier is actually firing or whether the heuristic is silently doing all the work. Adds the instrumentation to make that observable. router.ClassifierSource enum (heuristic / slm / slm_fallback) is set on Task by every classifier: - HeuristicClassifier → ClassifierHeuristic - slm.Classifier → ClassifierSLM on success, ClassifierSLMFallback when the SLM call fails or returns unparseable output The source is plumbed through router.Outcome to QualityTracker, which now maintains per-source counters alongside the existing per-arm × task EMA scores. QualitySnapshot serializes both (classifier_counts is omitempty for back-compat with pre-feature quality.json files). lazyClassifier logs at INFO the first time it falls back to heuristic because the SLM hasn't booted yet — distinguishes operational fallback from an unconfigured-SLM run. slm.Manager.Start() now records elapsed-to-healthy and the main.go goroutine logs it as part of the "SLM ready" event. Confirms whether short-lived runs are racing the boot cycle. New `gnoma router stats` subcommand prints both tables (arm × task quality, classifier source breakdown) from quality.json with a Phase 4 trust hint when the data is too sparse or the SLM share is low. 6 new tests cover ClassifierSource string/enum, heuristic + SLM source propagation, QualityTracker counter round-trip, and back-compat restore from a legacy quality.json without classifier_counts.
25 lines
811 B
Go
25 lines
811 B
Go
package router
|
|
|
|
import (
|
|
"context"
|
|
|
|
"somegit.dev/Owlibou/gnoma/internal/message"
|
|
)
|
|
|
|
// TaskClassifier classifies a user prompt into a Task for routing decisions.
|
|
// The history slice provides prior conversation context; implementations may
|
|
// ignore it (HeuristicClassifier) or use it for richer inference (SLMClassifier).
|
|
type TaskClassifier interface {
|
|
Classify(ctx context.Context, prompt string, history []message.Message) (Task, error)
|
|
}
|
|
|
|
// HeuristicClassifier is the default classifier. It wraps the keyword-based
|
|
// ClassifyTask function and ignores conversation history.
|
|
type HeuristicClassifier struct{}
|
|
|
|
func (HeuristicClassifier) Classify(_ context.Context, prompt string, _ []message.Message) (Task, error) {
|
|
t := ClassifyTask(prompt)
|
|
t.ClassifierSource = ClassifierHeuristic
|
|
return t, nil
|
|
}
|