@@ -461,8 +461,9 @@ func (s *sessionService) KnowledgeQA(
461461 // Ensure defaults are set
462462 customAgent .EnsureDefaults ()
463463
464- // Override model ID
465- if customAgent .Config .ModelID != "" {
464+ // Override model ID only if request didn't specify summaryModelID
465+ // Request's summaryModelID has highest priority
466+ if summaryModelID == "" && customAgent .Config .ModelID != "" {
466467 chatModelID = customAgent .Config .ModelID
467468 logger .Infof (ctx , "Using custom agent's model_id: %s" , chatModelID )
468469 }
@@ -1055,11 +1056,13 @@ func (s *sessionService) SearchKnowledge(ctx context.Context,
10551056
10561057// AgentQA performs agent-based question answering with conversation history and streaming support
10571058// customAgent is optional - if provided, uses custom agent configuration instead of tenant defaults
1059+ // summaryModelID is optional - if provided, overrides the model from customAgent config
10581060func (s * sessionService ) AgentQA (
10591061 ctx context.Context ,
10601062 session * types.Session ,
10611063 query string ,
10621064 assistantMessageID string ,
1065+ summaryModelID string ,
10631066 eventBus * event.EventBus ,
10641067 customAgent * types.CustomAgent ,
10651068 knowledgeBaseIDs []string ,
@@ -1163,15 +1166,23 @@ func (s *sessionService) AgentQA(
11631166 agentConfig .SearchTargets = searchTargets
11641167 logger .Infof (ctx , "Agent search targets built: %d targets" , len (searchTargets ))
11651168
1166- // Get summary model from custom agent config
1169+ // Get summary model: prioritize request's summaryModelID, then custom agent config
11671170 // Note: tenantInfo.ConversationConfig is deprecated, all config comes from customAgent now
1168- summaryModelID := customAgent .Config .ModelID
1169- if summaryModelID == "" {
1171+ effectiveModelID := summaryModelID
1172+ if effectiveModelID == "" {
1173+ effectiveModelID = customAgent .Config .ModelID
1174+ }
1175+ if effectiveModelID == "" {
11701176 logger .Warnf (ctx , "No summary model configured for custom agent %s" , customAgent .ID )
11711177 return errors .New ("summary model (model_id) is not configured in custom agent settings" )
11721178 }
1179+ if summaryModelID != "" {
1180+ logger .Infof (ctx , "Using request's summary model override: %s" , effectiveModelID )
1181+ } else {
1182+ logger .Infof (ctx , "Using custom agent's model_id: %s" , effectiveModelID )
1183+ }
11731184
1174- summaryModel , err := s .modelService .GetChatModel (ctx , summaryModelID )
1185+ summaryModel , err := s .modelService .GetChatModel (ctx , effectiveModelID )
11751186 if err != nil {
11761187 logger .Warnf (ctx , "Failed to get chat model: %v" , err )
11771188 return fmt .Errorf ("failed to get chat model: %w" , err )
0 commit comments