feat: add model routing table with three-layer priority

This commit is contained in:
Mathias Bergqvist
2026-04-17 07:37:43 +02:00
parent 8b8ada2676
commit 4c00b55ca5
3 changed files with 97 additions and 0 deletions

43
internal/config/models.go Normal file
View File

@@ -0,0 +1,43 @@
package config
import (
"fmt"
"os"
"gopkg.in/yaml.v3"
)
type modelsFile struct {
Default string `yaml:"default"`
Skills map[string]string `yaml:"skills"`
}
type Models struct {
data modelsFile
}
func LoadModels(path string) (Models, error) {
raw, err := os.ReadFile(path)
if err != nil {
return Models{}, fmt.Errorf("load models: %w", err)
}
var f modelsFile
if err := yaml.Unmarshal(raw, &f); err != nil {
return Models{}, fmt.Errorf("parse models: %w", err)
}
return Models{data: f}, nil
}
// Resolve returns the model for a skill, respecting three-layer priority:
// 1. override (from MCP call) — highest
// 2. per-skill default from models.yaml
// 3. global default
func (m Models) Resolve(skill, override string) string {
if override != "" {
return override
}
if model, ok := m.data.Skills[skill]; ok {
return model
}
return m.data.Default
}

View File

@@ -0,0 +1,44 @@
package config_test
import (
"os"
"path/filepath"
"testing"
"github.com/mathiasbq/supervisor/internal/config"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestModelsResolve(t *testing.T) {
yaml := `
default: ollama/default-model
skills:
tdd: ollama/qwen3-coder-30b-tuned
review: ollama/devstral-tuned
`
f := filepath.Join(t.TempDir(), "models.yaml")
require.NoError(t, os.WriteFile(f, []byte(yaml), 0644))
m, err := config.LoadModels(f)
require.NoError(t, err)
assert.Equal(t, "ollama/qwen3-coder-30b-tuned", m.Resolve("tdd", ""))
assert.Equal(t, "ollama/devstral-tuned", m.Resolve("review", ""))
assert.Equal(t, "ollama/default-model", m.Resolve("unknown", ""))
}
func TestModelsOverride(t *testing.T) {
yaml := `
default: ollama/default-model
skills:
tdd: ollama/qwen3-coder-30b-tuned
`
f := filepath.Join(t.TempDir(), "models.yaml")
require.NoError(t, os.WriteFile(f, []byte(yaml), 0644))
m, err := config.LoadModels(f)
require.NoError(t, err)
assert.Equal(t, "anthropic/claude-sonnet-4-6", m.Resolve("tdd", "anthropic/claude-sonnet-4-6"))
}