feat(agent): add intent prompt customization in agent editor
Allow per-intent system prompt overrides for non-retrieval intents in normal mode. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -187,8 +187,16 @@ func (p *PluginQueryUnderstand) OnEvent(ctx context.Context,
|
||||
|
||||
// --- Apply intent-specific system prompt override ---
|
||||
if !chatManage.NeedsRetrieval() {
|
||||
if prompt, ok := p.config.Conversation.IntentSystemPrompts[string(chatManage.Intent)]; ok {
|
||||
chatManage.SystemPromptOverride = prompt
|
||||
intentKey := string(chatManage.Intent)
|
||||
if chatManage.IntentPromptOverrides != nil {
|
||||
chatManage.SystemPromptOverride = strings.TrimSpace(chatManage.IntentPromptOverrides[intentKey])
|
||||
}
|
||||
if chatManage.SystemPromptOverride == "" {
|
||||
if prompt, ok := p.config.Conversation.IntentSystemPrompts[intentKey]; ok {
|
||||
chatManage.SystemPromptOverride = prompt
|
||||
}
|
||||
}
|
||||
if chatManage.SystemPromptOverride != "" {
|
||||
pipelineInfo(ctx, "QueryUnderstand", "prompt_override", map[string]interface{}{
|
||||
"session_id": chatManage.SessionID,
|
||||
"intent": chatManage.Intent,
|
||||
|
||||
@@ -210,6 +210,11 @@ func (s *sessionService) applyAgentOverridesToChatManage(
|
||||
if cm.DataAnalysisEnabled {
|
||||
logger.Infof(ctx, "Data analysis pipeline stage enabled by custom agent")
|
||||
}
|
||||
|
||||
if len(customAgent.Config.IntentPrompts) > 0 {
|
||||
cm.IntentPromptOverrides = customAgent.Config.IntentPrompts
|
||||
logger.Infof(ctx, "Using custom agent's intent_prompts (%d overrides)", len(cm.IntentPromptOverrides))
|
||||
}
|
||||
}
|
||||
|
||||
// restrictMentionsToAgentScope filters user-provided @mention targets (KB IDs
|
||||
|
||||
@@ -951,6 +951,7 @@ func (h *TenantHandler) GetPromptTemplates(c *gin.Context) {
|
||||
GenerateSummary: templates.GenerateSummary,
|
||||
KeywordsExtraction: templates.KeywordsExtraction,
|
||||
AgentSystemPrompt: config.LocalizeTemplates(templates.AgentSystemPrompt, lang),
|
||||
IntentPrompts: config.LocalizeTemplates(templates.IntentPrompts, lang),
|
||||
}
|
||||
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
|
||||
@@ -59,6 +59,10 @@ type PipelineRequest struct {
|
||||
// File attachments support
|
||||
Attachments MessageAttachments `json:"-"`
|
||||
|
||||
// IntentPromptOverrides holds agent-level intent prompt overrides for the
|
||||
// query-understanding stage. Empty values fall back to tenant/global defaults.
|
||||
IntentPromptOverrides map[string]string `json:"-"`
|
||||
|
||||
// Misc request-scoped config
|
||||
TenantID uint64 `json:"-"`
|
||||
WebSearchEnabled bool `json:"-"`
|
||||
@@ -221,6 +225,7 @@ func (c *ChatManage) Clone() *ChatManage {
|
||||
WebFetchEnabled: c.WebFetchEnabled,
|
||||
WebFetchTopN: c.WebFetchTopN,
|
||||
Language: c.Language,
|
||||
IntentPromptOverrides: maps.Clone(c.IntentPromptOverrides),
|
||||
},
|
||||
PipelineState: PipelineState{
|
||||
RewriteQuery: c.RewriteQuery,
|
||||
|
||||
@@ -256,6 +256,10 @@ type CustomAgentConfig struct {
|
||||
FallbackResponse string `yaml:"fallback_response" json:"fallback_response"`
|
||||
// Fallback prompt (when FallbackStrategy is "model")
|
||||
FallbackPrompt string `yaml:"fallback_prompt" json:"fallback_prompt"`
|
||||
// IntentPrompts holds per-intent system prompt overrides for non-retrieval
|
||||
// intents (greeting, chitchat, etc.). Empty values fall back to templates
|
||||
// under config/prompt_templates/intent_prompts.yaml.
|
||||
IntentPrompts map[string]string `yaml:"intent_prompts" json:"intent_prompts,omitempty"`
|
||||
|
||||
// ===== Suggested Prompts =====
|
||||
// 推荐问题列表,用于在前端对话面板展示快捷提问
|
||||
|
||||
Reference in New Issue
Block a user