feat(agent): add per-agent citation output toggle
Move citation protocol injection to the system layer so custom prompts no longer own citation syntax. Agents can disable inline citations while source aliases still encode and decode tool arguments correctly.
This commit is contained in:
@@ -38,6 +38,8 @@ type AgentConfig struct {
|
||||
MCPAuthWaitTimeout int `json:"mcp_auth_wait_timeout,omitempty"`
|
||||
// Whether to enable thinking mode (for models that support extended thinking)
|
||||
Thinking *bool `json:"thinking"`
|
||||
// Whether final answers include knowledge/web source citations. Nil defaults to true.
|
||||
CitationEnabled *bool `json:"citation_enabled"`
|
||||
// Whether to retrieve knowledge base only when explicitly mentioned with @ (default: false)
|
||||
RetrieveKBOnlyWhenMentioned bool `json:"retrieve_kb_only_when_mentioned"`
|
||||
|
||||
@@ -71,6 +73,12 @@ type AgentConfig struct {
|
||||
ParallelToolCalls bool `json:"parallel_tool_calls,omitempty"`
|
||||
}
|
||||
|
||||
// CitationsEnabled preserves citation output for legacy runtime configs that
|
||||
// predate the setting and therefore have a nil CitationEnabled value.
|
||||
func (c *AgentConfig) CitationsEnabled() bool {
|
||||
return c == nil || c.CitationEnabled == nil || *c.CitationEnabled
|
||||
}
|
||||
|
||||
// SessionAgentConfig represents session-level agent configuration
|
||||
// Sessions only store Enabled and KnowledgeBases; other configs are read from Tenant at runtime
|
||||
type SessionAgentConfig struct {
|
||||
|
||||
@@ -30,6 +30,9 @@ type PipelineRequest struct {
|
||||
FallbackStrategy FallbackStrategy `json:"fallback_strategy"`
|
||||
FallbackResponse string `json:"fallback_response"`
|
||||
FallbackPrompt string `json:"fallback_prompt"`
|
||||
// CitationEnabled controls only final knowledge/web source citations. Nil
|
||||
// defaults to true for requests and agents created before this option existed.
|
||||
CitationEnabled *bool `json:"citation_enabled,omitempty"`
|
||||
|
||||
// Rewrite parameters
|
||||
EnableRewrite bool `json:"enable_rewrite"`
|
||||
@@ -73,6 +76,11 @@ type PipelineRequest struct {
|
||||
Language string `json:"-"`
|
||||
}
|
||||
|
||||
// CitationsEnabled returns the effective citation setting for this request.
|
||||
func (c *PipelineRequest) CitationsEnabled() bool {
|
||||
return c == nil || c.CitationEnabled == nil || *c.CitationEnabled
|
||||
}
|
||||
|
||||
// QueryIntent represents the classified intent of a user query.
|
||||
type QueryIntent string
|
||||
|
||||
@@ -210,6 +218,7 @@ func (c *ChatManage) Clone() *ChatManage {
|
||||
FallbackStrategy: c.FallbackStrategy,
|
||||
FallbackResponse: c.FallbackResponse,
|
||||
FallbackPrompt: c.FallbackPrompt,
|
||||
CitationEnabled: c.CitationEnabled,
|
||||
EnableRewrite: c.EnableRewrite,
|
||||
EnableQueryExpansion: c.EnableQueryExpansion,
|
||||
RewritePromptSystem: c.RewritePromptSystem,
|
||||
|
||||
@@ -125,6 +125,9 @@ type CustomAgentConfig struct {
|
||||
MaxCompletionTokens int `yaml:"max_completion_tokens" json:"max_completion_tokens"`
|
||||
// Whether to enable thinking mode (for models that support extended thinking)
|
||||
Thinking *bool `yaml:"thinking" json:"thinking"`
|
||||
// Whether final answers include knowledge/web source citations. Nil defaults to true
|
||||
// so agents saved before this option was introduced keep their existing behavior.
|
||||
CitationEnabled *bool `yaml:"citation_enabled" json:"citation_enabled"`
|
||||
|
||||
// ===== Agent Mode Settings =====
|
||||
// Maximum iterations for ReAct loop (only for agent type)
|
||||
@@ -517,6 +520,12 @@ func (a *CustomAgent) EnsureDefaults() {
|
||||
disabled := false
|
||||
a.Config.Thinking = &disabled
|
||||
}
|
||||
// Keep citations enabled for existing agents whose persisted config predates
|
||||
// this field. An explicit false is always preserved.
|
||||
if a.Config.CitationEnabled == nil {
|
||||
enabled := true
|
||||
a.Config.CitationEnabled = &enabled
|
||||
}
|
||||
}
|
||||
|
||||
// IsAgentMode returns true if this agent uses ReAct agent mode
|
||||
|
||||
@@ -39,3 +39,18 @@ func TestEnsureDefaults_ThinkingPreservesTrue(t *testing.T) {
|
||||
t.Fatal("EnsureDefaults must not overwrite an explicit Thinking=true")
|
||||
}
|
||||
}
|
||||
|
||||
func TestEnsureDefaults_CitationsDefaultEnabledAndPreserveFalse(t *testing.T) {
|
||||
legacy := &CustomAgent{Config: CustomAgentConfig{}}
|
||||
legacy.EnsureDefaults()
|
||||
if legacy.Config.CitationEnabled == nil || !*legacy.Config.CitationEnabled {
|
||||
t.Fatal("legacy agents must default citation output to enabled")
|
||||
}
|
||||
|
||||
disabled := false
|
||||
explicit := &CustomAgent{Config: CustomAgentConfig{CitationEnabled: &disabled}}
|
||||
explicit.EnsureDefaults()
|
||||
if explicit.Config.CitationEnabled == nil || *explicit.Config.CitationEnabled {
|
||||
t.Fatal("EnsureDefaults must preserve explicit citation_enabled=false")
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user