feat(agent): support dedicated model for query understanding step
Quick-answer (RAG) agents can now configure a separate chat model for the query-understanding stage (rewrite + intent classification), decoupling it from the main conversation model so users can route the lightweight rewrite call to a cheaper / faster model. - Add CustomAgentConfig.QueryUnderstandModelID and plumb it through PipelineRequest and ChatManage.Clone. - query_understand plugin prefers QueryUnderstandModelID on the text-only path; falls back to ChatModelID if the configured model cannot be resolved (with a warn log). Multimodal path is unchanged to keep vision-capable model selection intact. - AgentEditorModal exposes a ModelSelector under the existing Query Rewrite block; empty means reuse the main chat model. - Add i18n strings (queryUnderstandModel / placeholder / desc) for zh-CN, en-US, ko-KR, ru-RU. - Extend Go SDK AgentConfig with the new field.
This commit is contained in:
@@ -293,11 +293,27 @@ func (p *PluginQueryUnderstand) selectModel(ctx context.Context, chatManage *typ
|
||||
})
|
||||
}
|
||||
|
||||
m, err := p.modelService.GetChatModel(ctx, chatManage.ChatModelID)
|
||||
textModelID := chatManage.ChatModelID
|
||||
if chatManage.QueryUnderstandModelID != "" {
|
||||
textModelID = chatManage.QueryUnderstandModelID
|
||||
}
|
||||
m, err := p.modelService.GetChatModel(ctx, textModelID)
|
||||
if err != nil {
|
||||
// Fall back to ChatModelID when a dedicated query-understand model was
|
||||
// configured but cannot be resolved (e.g. deleted / disabled).
|
||||
if chatManage.QueryUnderstandModelID != "" && textModelID != chatManage.ChatModelID {
|
||||
pipelineWarn(ctx, "QueryUnderstand", "query_understand_model_fallback", map[string]interface{}{
|
||||
"session_id": chatManage.SessionID,
|
||||
"query_understand_model_id": chatManage.QueryUnderstandModelID,
|
||||
"error": err.Error(),
|
||||
})
|
||||
if fallback, fbErr := p.modelService.GetChatModel(ctx, chatManage.ChatModelID); fbErr == nil {
|
||||
return fallback, false
|
||||
}
|
||||
}
|
||||
pipelineError(ctx, "QueryUnderstand", "get_model", map[string]interface{}{
|
||||
"session_id": chatManage.SessionID,
|
||||
"chat_model_id": chatManage.ChatModelID,
|
||||
"chat_model_id": textModelID,
|
||||
"error": err.Error(),
|
||||
})
|
||||
return nil, false
|
||||
|
||||
@@ -164,6 +164,11 @@ func (s *sessionService) applyAgentOverridesToChatManage(
|
||||
if customAgent.Config.RewritePromptUser != "" {
|
||||
cm.RewritePromptUser = customAgent.Config.RewritePromptUser
|
||||
}
|
||||
if customAgent.Config.QueryUnderstandModelID != "" {
|
||||
cm.QueryUnderstandModelID = customAgent.Config.QueryUnderstandModelID
|
||||
logger.Infof(ctx, "Using custom agent's query_understand_model_id: %s",
|
||||
customAgent.Config.QueryUnderstandModelID)
|
||||
}
|
||||
|
||||
// Override fallback settings
|
||||
if customAgent.Config.FallbackStrategy != "" {
|
||||
|
||||
@@ -36,6 +36,10 @@ type PipelineRequest struct {
|
||||
EnableQueryExpansion bool `json:"enable_query_expansion"`
|
||||
RewritePromptSystem string `json:"rewrite_prompt_system"`
|
||||
RewritePromptUser string `json:"rewrite_prompt_user"`
|
||||
// QueryUnderstandModelID, when set, overrides the chat model used for
|
||||
// the query-understanding (rewrite + intent classification) stage only.
|
||||
// Empty means fall back to ChatModelID.
|
||||
QueryUnderstandModelID string `json:"query_understand_model_id,omitempty"`
|
||||
|
||||
// FAQ strategy
|
||||
FAQPriorityEnabled bool `json:"-"`
|
||||
@@ -201,6 +205,7 @@ func (c *ChatManage) Clone() *ChatManage {
|
||||
EnableQueryExpansion: c.EnableQueryExpansion,
|
||||
RewritePromptSystem: c.RewritePromptSystem,
|
||||
RewritePromptUser: c.RewritePromptUser,
|
||||
QueryUnderstandModelID: c.QueryUnderstandModelID,
|
||||
FAQPriorityEnabled: c.FAQPriorityEnabled,
|
||||
FAQDirectAnswerThreshold: c.FAQDirectAnswerThreshold,
|
||||
FAQScoreBoost: c.FAQScoreBoost,
|
||||
|
||||
@@ -223,6 +223,9 @@ type CustomAgentConfig struct {
|
||||
RewritePromptSystem string `yaml:"rewrite_prompt_system" json:"rewrite_prompt_system"`
|
||||
// Rewrite prompt user message template
|
||||
RewritePromptUser string `yaml:"rewrite_prompt_user" json:"rewrite_prompt_user"`
|
||||
// Dedicated chat model ID for the query-understanding (rewrite + intent) step.
|
||||
// When empty, the main conversation ModelID is used as a fallback.
|
||||
QueryUnderstandModelID string `yaml:"query_understand_model_id" json:"query_understand_model_id,omitempty"`
|
||||
// Fallback strategy: "fixed" for fixed response, "model" for model generation
|
||||
FallbackStrategy string `yaml:"fallback_strategy" json:"fallback_strategy"`
|
||||
// Fixed fallback response (when FallbackStrategy is "fixed")
|
||||
|
||||
Reference in New Issue
Block a user