diff --git a/pkg/agent/loop.go b/pkg/agent/loop.go index f20a56b9c..cc0dfbda0 100644 --- a/pkg/agent/loop.go +++ b/pkg/agent/loop.go @@ -1431,12 +1431,13 @@ func (al *AgentLoop) selectCandidates( logger.InfoCF("agent", "Model routing: light model selected", map[string]any{ - "agent_id": agent.ID, - "light_model": agent.Router.LightModel(), - "score": score, - "threshold": agent.Router.Threshold(), + "agent_id": agent.ID, + "light_model": agent.Router.LightModel(), + "resolved_light_model": agent.LightCandidates[0].Model, + "score": score, + "threshold": agent.Router.Threshold(), }) - return agent.LightCandidates, agent.Router.LightModel() + return agent.LightCandidates, agent.LightCandidates[0].Model } // maybeSummarize triggers summarization if the session history exceeds thresholds. diff --git a/pkg/agent/loop_test.go b/pkg/agent/loop_test.go index a6604e87f..5c1f46991 100644 --- a/pkg/agent/loop_test.go +++ b/pkg/agent/loop_test.go @@ -575,6 +575,35 @@ func TestProcessMessage_SwitchModelShowModelConsistency(t *testing.T) { } } +func TestSelectCandidates_UsesResolvedLightModelID(t *testing.T) { + al := &AgentLoop{} + agent := &AgentInstance{ + ID: "main", + Model: "heavy-alias", + Router: routing.New(routing.RouterConfig{ + LightModel: "light-alias", + Threshold: 1.0, + }), + Candidates: []providers.FallbackCandidate{ + {Provider: "openai", Model: "gpt-4o"}, + }, + LightCandidates: []providers.FallbackCandidate{ + {Provider: "openai", Model: "qwen2.5:3b"}, + }, + } + + candidates, model := al.selectCandidates(agent, "hi", nil) + if len(candidates) != 1 { + t.Fatalf("len(candidates) = %d, want 1", len(candidates)) + } + if candidates[0].Model != "qwen2.5:3b" { + t.Fatalf("candidate model = %q, want %q", candidates[0].Model, "qwen2.5:3b") + } + if model != "qwen2.5:3b" { + t.Fatalf("model = %q, want %q", model, "qwen2.5:3b") + } +} + // TestToolResult_SilentToolDoesNotSendUserMessage verifies silent tools don't trigger outbound func TestToolResult_SilentToolDoesNotSendUserMessage(t *testing.T) { tmpDir, err := os.MkdirTemp("", "agent-test-*")