fix: preserve agent system prompt for greetings

This commit is contained in:
wolfkill
2026-05-28 20:04:20 +08:00
committed by lyingbug
parent 10383c6ddd
commit b22303cec8
5 changed files with 54 additions and 3 deletions
@@ -470,14 +470,18 @@ func mergeImageDescAndOCR(desc, ocr string) (string, bool) {
// applyIntentPromptOverride resolves the system-prompt override for the current
// non-retrieval intent. Agent-level overrides take precedence; otherwise the
// tenant/global IntentSystemPrompts map is consulted. Whitespace-only agent
// overrides are treated as unset and fall through to the global default. Returns
// true when a non-empty override was applied.
// tenant/global IntentSystemPrompts map is consulted. When a custom agent
// system prompt is already applied, global intent prompts must not replace it.
// Whitespace-only agent overrides are treated as unset. Returns true when a
// non-empty override was applied.
func applyIntentPromptOverride(chatManage *types.ChatManage, globalPrompts map[string]string) bool {
intentKey := string(chatManage.Intent)
if raw, ok := chatManage.IntentPromptOverrides[intentKey]; ok && strings.TrimSpace(raw) != "" {
chatManage.SystemPromptOverride = raw
}
if chatManage.AgentSystemPromptApplied {
return chatManage.SystemPromptOverride != ""
}
if chatManage.SystemPromptOverride == "" {
if prompt, ok := globalPrompts[intentKey]; ok {
chatManage.SystemPromptOverride = prompt
@@ -59,6 +59,23 @@ func TestApplyIntentPromptOverride_BlankAgentFallsBackToGlobal(t *testing.T) {
}
}
func TestApplyIntentPromptOverride_CustomAgentSystemPromptSkipsGlobalFallback(t *testing.T) {
cm := &types.ChatManage{
PipelineRequest: types.PipelineRequest{
AgentSystemPromptApplied: true,
},
PipelineState: types.PipelineState{Intent: types.IntentGreeting},
}
global := map[string]string{"greeting": "global prompt"}
if applyIntentPromptOverride(cm, global) {
t.Fatal("expected applied=false")
}
if cm.SystemPromptOverride != "" {
t.Errorf("override should remain empty, got %q", cm.SystemPromptOverride)
}
}
func TestApplyIntentPromptOverride_NoOverrideAndNoGlobal(t *testing.T) {
cm := &types.ChatManage{
PipelineState: types.PipelineState{Intent: types.IntentChitchat},