Open-source LLM knowledge platform: turn raw documents into a queryable RAG, an autonomous reasoning agent, and a self-maintaining Wiki.
Go agentagenticaichatbotdsh-pluginembeddingsevaluationgenerative-aigolangknowledge-basellmmulti-tenantollamaopenaiquestion-answeringragrerankingsemantic-searchvector-searchwiki
Fix system prompt not being used when flag is false
ugurtafrali38077d6ccdc0
diff --git a/internal/application/service/agent_service.go b/internal/application/service/agent_service.goindex 1f79516e4..d2c2d6e4f 100644--- a/internal/application/service/agent_service.go+++ b/internal/application/service/agent_service.go@@ -110,7 +110,7 @@ func (s *agentService) CreateAgentEngine(// 4. Resolve system prompt templatesystemPromptTemplate := ""- if config.UseCustomSystemPrompt {+ if config.UseCustomSystemPrompt || config.SystemPrompt != "" {systemPromptTemplate = config.ResolveSystemPrompt(config.WebSearchEnabled)}diff --git a/internal/types/agent_test.go b/internal/types/agent_test.gonew file mode 100644index 000000000..383e9511b--- /dev/null+++ b/internal/types/agent_test.go@@ -0,0 +1,77 @@+package types++import (+ "testing"+)++func TestResolveSystemPrompt(t *testing.T) {+ tests := []struct {+ name string+ config *AgentConfig+ webSearchEnabled bool+ want string+ }{+ {+ name: "nil config returns empty",+ config: nil,+ webSearchEnabled: false,+ want: "",+ },+ {+ name: "unified SystemPrompt returned",+ config: &AgentConfig{SystemPrompt: "my prompt"},+ webSearchEnabled: false,+ want: "my prompt",+ },+ {+ name: "deprecated web-disabled fallback",+ config: &AgentConfig{+ SystemPromptWebDisabled: "no-web",+ SystemPromptWebEnabled: "with-web",+ },+ webSearchEnabled: false,+ want: "no-web",+ },+ {+ name: "deprecated web-enabled fallback",+ config: &AgentConfig{+ SystemPromptWebDisabled: "no-web",+ SystemPromptWebEnabled: "with-web",+ },+ webSearchEnabled: true,+ want: "with-web",+ },+ {+ name: "empty config returns empty",+ config: &AgentConfig{},+ webSearchEnabled: false,+ want: "",+ },+ }++ for _, tt := range tests {+ t.Run(tt.name, func(t *testing.T) {+ got := tt.config.ResolveSystemPrompt(tt.webSearchEnabled)+ if got != tt.want {+ t.Errorf("ResolveSystemPrompt() = %q, want %q", got, tt.want)+ }+ })+ }+}++// TestUseCustomSystemPromptFlag verifies that UseCustomSystemPrompt=false+// does not block a non-empty SystemPrompt from being resolved by agent_service.+// The fix in agent_service.go checks config.SystemPrompt != "" as a fallback,+// so ResolveSystemPrompt must return the prompt even when the flag is false.+func TestUseCustomSystemPromptFlag(t *testing.T) {+ cfg := &AgentConfig{+ SystemPrompt: "custom prompt",+ UseCustomSystemPrompt: false, // flag NOT set+ }++ // ResolveSystemPrompt should still return the prompt+ got := cfg.ResolveSystemPrompt(false)+ if got != "custom prompt" {+ t.Errorf("expected 'custom prompt', got %q", got)+ }+}