@@ -81,29 +81,63 @@ func ensureModelsExist(cfg *v2.Config) error {
8181 cfg .Models = map [string ]v2.ModelConfig {}
8282 }
8383
84+ // Ensure models referenced by agents exist
8485 for agentName := range cfg .Agents {
8586 agentConfig := cfg .Agents [agentName ]
8687
8788 modelNames := strings .SplitSeq (agentConfig .Model , "," )
8889 for modelName := range modelNames {
89- if modelName == "auto" {
90- continue
90+ if err := ensureSingleModelExists ( cfg , modelName , fmt . Sprintf ( "agent '%s'" , agentName )); err != nil {
91+ return err
9192 }
92- if _ , exists := cfg .Models [modelName ]; exists {
93+ }
94+ }
95+
96+ // Ensure models referenced by RAG strategies exist
97+ for ragName , ragCfg := range cfg .RAG {
98+ for _ , stratCfg := range ragCfg .Strategies {
99+ rawModel , ok := stratCfg .Params ["model" ]
100+ if ! ok {
93101 continue
94102 }
95103
96- providerName , model , ok := strings . Cut ( modelName , "/" )
104+ modelName , ok := rawModel .( string )
97105 if ! ok {
98- return fmt .Errorf ("agent '%s' references non-existent model '%s'" , agentName , modelName )
106+ return fmt .Errorf ("RAG strategy '%s' in RAG '%s' has non-string model value " , stratCfg . Type , ragName )
99107 }
100108
101- cfg .Models [modelName ] = v2.ModelConfig {
102- Provider : providerName ,
103- Model : model ,
109+ if err := ensureSingleModelExists (cfg , modelName , fmt .Sprintf ("RAG strategy '%s' in RAG '%s'" , stratCfg .Type , ragName )); err != nil {
110+ return err
104111 }
105112 }
106113 }
107114
108115 return nil
109116}
117+
118+ // ensureSingleModelExists normalizes shorthand model IDs like "openai/gpt-5-mini"
119+ // into full entries in cfg.Models so they can be reused by agents, RAG, and other
120+ // subsystems without duplicating parsing logic.
121+ func ensureSingleModelExists (cfg * v2.Config , modelName , context string ) error {
122+ modelName = strings .TrimSpace (modelName )
123+ if modelName == "" || modelName == "auto" {
124+ // "auto" is handled dynamically at runtime and does not need a config entry.
125+ return nil
126+ }
127+
128+ if _ , exists := cfg .Models [modelName ]; exists {
129+ return nil
130+ }
131+
132+ providerName , model , ok := strings .Cut (modelName , "/" )
133+ if ! ok || providerName == "" || model == "" {
134+ return fmt .Errorf ("%s references non-existent model '%s'" , context , modelName )
135+ }
136+
137+ cfg .Models [modelName ] = v2.ModelConfig {
138+ Provider : providerName ,
139+ Model : model ,
140+ }
141+
142+ return nil
143+ }
0 commit comments