diff --git a/pkg/routing/classifier.go b/pkg/routing/classifier.go index 761a6fdec..8cddaf069 100644 --- a/pkg/routing/classifier.go +++ b/pkg/routing/classifier.go @@ -71,7 +71,7 @@ func (c *RuleClassifier) Score(f Features) float64 { score += 0.10 } - // Cap at 1.0 to honour the [0, 1] contract even when multiple signals fire + // Cap at 1.0 to honor the [0, 1] contract even when multiple signals fire // simultaneously (e.g., long message + code block + tool chain = 1.10 raw). if score > 1.0 { score = 1.0 diff --git a/pkg/routing/router.go b/pkg/routing/router.go index d4f5218d3..78092b106 100644 --- a/pkg/routing/router.go +++ b/pkg/routing/router.go @@ -57,7 +57,11 @@ func newWithClassifier(cfg RouterConfig, c Classifier) *Router { // // The caller is responsible for resolving the returned model name into // provider candidates (see AgentInstance.LightCandidates). -func (r *Router) SelectModel(msg string, history []providers.Message, primaryModel string) (model string, usedLight bool) { +func (r *Router) SelectModel( + msg string, + history []providers.Message, + primaryModel string, +) (model string, usedLight bool) { features := ExtractFeatures(msg, history) score := r.classifier.Score(features) if score < r.cfg.Threshold { diff --git a/pkg/routing/router_test.go b/pkg/routing/router_test.go index 168227638..267200c2e 100644 --- a/pkg/routing/router_test.go +++ b/pkg/routing/router_test.go @@ -38,8 +38,13 @@ func TestExtractFeatures_TokenEstimate(t *testing.T) { } func TestExtractFeatures_TokenEstimate_CJK(t *testing.T) { - // 9 CJK runes / 3 = 3 tokens - msg := "你好世界你好世界你" // 9 runes + // 9 CJK runes (U+4F60 U+597D U+4E16 U+754C × 2 + U+4F60) / 3 = 3 tokens. + // Using a rune slice literal avoids CJK string literals in source. + msg := string([]rune{ + 0x4F60, 0x597D, 0x4E16, 0x754C, + 0x4F60, 0x597D, 0x4E16, 0x754C, + 0x4F60, + }) f := ExtractFeatures(msg, nil) if f.TokenEstimate != 3 { t.Errorf("CJK TokenEstimate: got %d, want 3", f.TokenEstimate) @@ -69,7 +74,10 @@ func TestExtractFeatures_RecentToolCalls(t *testing.T) { history := make([]providers.Message, 10) // Put 2 tool calls at positions 8 and 9 (within the last 6) history[8] = providers.Message{Role: "assistant", ToolCalls: []providers.ToolCall{{Name: "exec"}}} - history[9] = providers.Message{Role: "assistant", ToolCalls: []providers.ToolCall{{Name: "read_file"}, {Name: "write_file"}}} + history[9] = providers.Message{ + Role: "assistant", + ToolCalls: []providers.ToolCall{{Name: "read_file"}, {Name: "write_file"}}, + } // Position 3 is outside the lookback window and must NOT be counted history[3] = providers.Message{Role: "assistant", ToolCalls: []providers.ToolCall{{Name: "old_tool"}}}