diff --git a/internal/application/service/agent_service.go b/internal/application/service/agent_service.go index 1f79516e..d2c2d6e4 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 template systemPromptTemplate := "" - 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.go new file mode 100644 index 00000000..383e9511 --- /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) + } +}