From 32c7637a5eb5556132219143edf3adcb87c510ce Mon Sep 17 00:00:00 2001 From: AmChocolate Date: Sun, 15 Mar 2026 21:57:25 +0800 Subject: [PATCH] feat: wire image_model config to agent loop for vision-capable models - Add ImageModel and ImageModelCandidates fields to AgentInstance - Resolve image_model candidates at agent creation time - Route to image_model when media attachments are detected in selectCandidates Fixes issue #1578 --- pkg/agent/instance.go | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/pkg/agent/instance.go b/pkg/agent/instance.go index 0c7baa1ee..086f2b9e6 100644 --- a/pkg/agent/instance.go +++ b/pkg/agent/instance.go @@ -47,6 +47,11 @@ type AgentInstance struct { // LightCandidates holds the resolved provider candidates for the light model. // Pre-computed at agent creation to avoid repeated model_list lookups at runtime. LightCandidates []providers.FallbackCandidate + // ImageModel holds the configured image model name from config. + ImageModel string + // ImageModelCandidates holds the resolved provider candidates for the image model. + // Pre-computed at agent creation to avoid repeated model_list lookups at runtime. + ImageModelCandidates []providers.FallbackCandidate } // NewAgentInstance creates an agent instance from config. @@ -214,6 +219,21 @@ func NewAgentInstance( } } + // Image model setup: pre-resolve image model candidates at creation time + // to avoid repeated model_list lookups when processing image attachments. + var imageModelCandidates []providers.FallbackCandidate + imageModel := defaults.ImageModel + if imageModel != "" { + imageModelCfg := providers.ModelConfig{Primary: imageModel, Fallbacks: defaults.ImageModelFallbacks} + resolved := providers.ResolveCandidatesWithLookup(imageModelCfg, defaults.Provider, resolveFromModelList) + if len(resolved) > 0 { + imageModelCandidates = resolved + } else { + log.Printf("image_model %q not found in model_list — image attachments will use primary model", + imageModel) + } + } + return &AgentInstance{ ID: agentID, Name: agentName, @@ -236,6 +256,8 @@ func NewAgentInstance( Candidates: candidates, Router: router, LightCandidates: lightCandidates, + ImageModel: imageModel, + ImageModelCandidates: imageModelCandidates, } }