feat: Introduce agent type presets for smart-reasoning mode
- Added a new configuration file `agent_type_presets.yaml` to define various agent type presets, including RAG Q&A, Wiki Q&A, Hybrid (Wiki + RAG), and Data Analysis. - Updated the `builtin_agents.yaml` to associate built-in agents with the new agent type presets, enhancing their configuration options. - Enhanced the agent system prompt templates to reflect the new agent types and their functionalities. - Implemented API endpoints to retrieve agent type presets, allowing for dynamic loading in the frontend. - Updated the frontend to support agent type selection in the agent editor modal, improving user experience by auto-filling relevant configurations based on selected presets. These changes significantly enhance the flexibility and usability of the agent system, allowing users to easily configure agents based on predefined types.
This commit is contained in:
@@ -341,18 +341,16 @@ func (s *agentService) registerTools(
|
||||
sessionID string,
|
||||
) error {
|
||||
// Source of truth policy:
|
||||
// - `config.AllowedTools` is the explicit, user-editable whitelist.
|
||||
// - We no longer silently *inject* tools the user didn't pick (esp. wiki tools).
|
||||
// - `config.AllowedTools` is the explicit, user-editable whitelist —
|
||||
// populated by the agent-type preset on create and freely editable
|
||||
// afterwards.
|
||||
// - We never silently *inject* tools the user didn't pick.
|
||||
// - We still *filter out* tools whose capability prerequisites are missing
|
||||
// (no KB in scope, no Wiki-capable KB, etc.) so the LLM can't call tools
|
||||
// that would error at runtime.
|
||||
// - Legacy agents without AllowedTools fall back to DefaultAllowedTools(),
|
||||
// and for them we preserve the historical "auto-append wiki tools when
|
||||
// a wiki KB is in scope" behavior for backward compatibility.
|
||||
hasExplicitAllowedTools := len(config.AllowedTools) > 0
|
||||
|
||||
// - Legacy agents without AllowedTools fall back to DefaultAllowedTools().
|
||||
var allowedTools []string
|
||||
if hasExplicitAllowedTools {
|
||||
if len(config.AllowedTools) > 0 {
|
||||
allowedTools = make([]string, len(config.AllowedTools))
|
||||
copy(allowedTools, config.AllowedTools)
|
||||
logger.Infof(ctx, "Using custom allowed tools from config: %v", allowedTools)
|
||||
@@ -433,31 +431,12 @@ func (s *agentService) registerTools(
|
||||
allowedTools = append(allowedTools, tools.ToolWebFetch)
|
||||
}
|
||||
|
||||
retrievalPref := config.RetrievalPreference
|
||||
if retrievalPref == "" {
|
||||
retrievalPref = "auto"
|
||||
}
|
||||
|
||||
// Default wiki read-only set used for backward-compat auto-injection below.
|
||||
// Edit/issue wiki tools are intentionally excluded — they must be explicitly
|
||||
// opted in via AllowedTools because they can mutate data.
|
||||
defaultWikiReadTools := []string{
|
||||
tools.ToolWikiReadPage,
|
||||
tools.ToolWikiSearch,
|
||||
tools.ToolWikiReadSourceDoc,
|
||||
tools.ToolWikiFlagIssue,
|
||||
}
|
||||
|
||||
// ---- Apply retrieval preference ----
|
||||
// Preference is now a *filter*, never an injector (for explicit lists).
|
||||
// For legacy agents without explicit AllowedTools, we still auto-append
|
||||
// wiki read tools so existing integrations keep working.
|
||||
// Tool capability sets — used by the hard safety nets below to drop tools
|
||||
// whose runtime prerequisite (a matching KB surface) is missing.
|
||||
//
|
||||
// NOTE: ragToolSet must stay in sync with frontend `knowledgeBaseTools`
|
||||
// in AgentEditorModal.vue. These are *all* tools that retrieve/inspect
|
||||
// content from RAG-style knowledge bases; wiki_only must strip the whole
|
||||
// set, otherwise the agent can still reach RAG data via graph/db/doc
|
||||
// info tools despite the user asking for Wiki only.
|
||||
// content from RAG-style knowledge bases.
|
||||
ragToolSet := map[string]bool{
|
||||
tools.ToolKnowledgeSearch: true,
|
||||
tools.ToolGrepChunks: true,
|
||||
@@ -479,47 +458,6 @@ func (s *agentService) registerTools(
|
||||
tools.ToolWikiUpdateIssue: true,
|
||||
}
|
||||
|
||||
switch retrievalPref {
|
||||
case "vector_only":
|
||||
filtered := make([]string, 0, len(allowedTools))
|
||||
dropped := make([]string, 0)
|
||||
for _, t := range allowedTools {
|
||||
if allWikiToolSet[t] {
|
||||
dropped = append(dropped, t)
|
||||
continue
|
||||
}
|
||||
filtered = append(filtered, t)
|
||||
}
|
||||
allowedTools = filtered
|
||||
logger.Infof(ctx, "Retrieval preference: vector_only, wiki tools filtered out: %v", dropped)
|
||||
case "wiki_only":
|
||||
filtered := make([]string, 0, len(allowedTools))
|
||||
dropped := make([]string, 0)
|
||||
for _, t := range allowedTools {
|
||||
if ragToolSet[t] {
|
||||
dropped = append(dropped, t)
|
||||
continue
|
||||
}
|
||||
filtered = append(filtered, t)
|
||||
}
|
||||
allowedTools = filtered
|
||||
// Only legacy agents get auto-append here; explicit lists are authoritative.
|
||||
if !hasExplicitAllowedTools && hasWikiKB {
|
||||
allowedTools = append(allowedTools, defaultWikiReadTools...)
|
||||
}
|
||||
logger.Infof(ctx, "Retrieval preference: wiki_only, RAG tools filtered out: %v", dropped)
|
||||
case "hybrid":
|
||||
if !hasExplicitAllowedTools && hasWikiKB {
|
||||
allowedTools = append(allowedTools, defaultWikiReadTools...)
|
||||
logger.Infof(ctx, "Retrieval preference: hybrid (legacy), wiki read tools auto-added")
|
||||
}
|
||||
default: // "auto"
|
||||
if !hasExplicitAllowedTools && hasWikiKB {
|
||||
allowedTools = append(allowedTools, defaultWikiReadTools...)
|
||||
logger.Infof(ctx, "Retrieval preference: auto (legacy), wiki read tools auto-added")
|
||||
}
|
||||
}
|
||||
|
||||
// Hard safety nets: drop tools whose runtime prerequisite is missing.
|
||||
// This guards against stale configs where e.g. the user ticked wiki tools
|
||||
// earlier but later swapped in a non-wiki KB (or vice versa for RAG).
|
||||
|
||||
@@ -226,7 +226,6 @@ func (s *sessionService) buildAgentConfig(
|
||||
MCPServices: customAgent.Config.MCPServices,
|
||||
Thinking: customAgent.Config.Thinking,
|
||||
RetrieveKBOnlyWhenMentioned: customAgent.Config.RetrieveKBOnlyWhenMentioned,
|
||||
RetrievalPreference: customAgent.Config.RetrievalPreference,
|
||||
LLMCallTimeout: customAgent.Config.LLMCallTimeout,
|
||||
RetainRetrievalHistory: customAgent.Config.RetainRetrievalHistory,
|
||||
}
|
||||
|
||||
@@ -408,10 +408,22 @@ func LoadConfig() (*Config, error) {
|
||||
fmt.Printf("Warning: failed to load builtin agents config: %v\n", err)
|
||||
}
|
||||
|
||||
// Load smart-reasoning agent type presets (rag-qa / wiki-qa / hybrid / custom).
|
||||
if err := types.LoadAgentTypePresetsConfig(configDir); err != nil {
|
||||
fmt.Printf("Warning: failed to load agent type presets: %v\n", err)
|
||||
}
|
||||
|
||||
// Resolve prompt template ID references in builtin agent configs
|
||||
// (e.g. system_prompt_id -> actual content from agent_system_prompt.yaml)
|
||||
if cfg.PromptTemplates != nil {
|
||||
resolveBuiltinAgentPromptIDs(cfg.PromptTemplates)
|
||||
// Validate that every preset references an existing prompt template.
|
||||
types.ResolveAgentTypePresetPromptRefs(func(id string) string {
|
||||
if t := FindTemplateByID(cfg.PromptTemplates, id); t != nil {
|
||||
return t.Content
|
||||
}
|
||||
return ""
|
||||
})
|
||||
}
|
||||
|
||||
// Validate configuration values
|
||||
|
||||
@@ -379,6 +379,25 @@ func (h *CustomAgentHandler) GetPlaceholders(c *gin.Context) {
|
||||
})
|
||||
}
|
||||
|
||||
// GetAgentTypePresets godoc
|
||||
// @Summary 获取智能体类型预设列表
|
||||
// @Description 返回所有 smart-reasoning 下可用的智能体类型预设(RAG/Wiki/Hybrid/Custom),用于编辑器自动填充系统提示词、工具和 KB 兼容性
|
||||
// @Tags 智能体
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Success 200 {object} map[string]interface{} "预设列表"
|
||||
// @Security Bearer
|
||||
// @Security ApiKeyAuth
|
||||
// @Router /agents/type-presets [get]
|
||||
func (h *CustomAgentHandler) GetAgentTypePresets(c *gin.Context) {
|
||||
ctx := c.Request.Context()
|
||||
presets := types.ListAgentTypePresetsWithContext(ctx)
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"success": true,
|
||||
"data": presets,
|
||||
})
|
||||
}
|
||||
|
||||
// GetSuggestedQuestions godoc
|
||||
// @Summary 获取推荐问题
|
||||
// @Description 基于智能体关联的知识库,返回推荐问题供用户快捷提问
|
||||
|
||||
@@ -532,6 +532,8 @@ func RegisterCustomAgentRoutes(r *gin.RouterGroup, agentHandler *handler.CustomA
|
||||
{
|
||||
// Get placeholder definitions (must be before /:id to avoid conflict)
|
||||
agents.GET("/placeholders", agentHandler.GetPlaceholders)
|
||||
// List smart-reasoning agent type presets (rag-qa / wiki-qa / hybrid / custom)
|
||||
agents.GET("/type-presets", agentHandler.GetAgentTypePresets)
|
||||
// Create custom agent
|
||||
agents.POST("", agentHandler.CreateAgent)
|
||||
// List all agents (including built-in)
|
||||
|
||||
@@ -37,10 +37,6 @@ type AgentConfig struct {
|
||||
// Whether to retrieve knowledge base only when explicitly mentioned with @ (default: false)
|
||||
RetrieveKBOnlyWhenMentioned bool `json:"retrieve_kb_only_when_mentioned"`
|
||||
|
||||
// RetrievalPreference controls which retrieval tools the agent uses:
|
||||
// "auto" (default), "vector_only", "wiki_only", "hybrid"
|
||||
RetrievalPreference string `json:"retrieval_preference"`
|
||||
|
||||
// Whether to retain retrieval history (like wiki_read_page results) across turns (default: false)
|
||||
RetainRetrievalHistory bool `json:"retain_retrieval_history"`
|
||||
|
||||
|
||||
@@ -0,0 +1,213 @@
|
||||
package types
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"sync"
|
||||
|
||||
"gopkg.in/yaml.v3"
|
||||
)
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// YAML data structures for config/agent_type_presets.yaml
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
// AgentTypePresetI18n holds localised label and description for a single locale.
|
||||
type AgentTypePresetI18n struct {
|
||||
Label string `yaml:"label" json:"label"`
|
||||
Description string `yaml:"description" json:"description"`
|
||||
}
|
||||
|
||||
// AgentTypeKBFilter describes how the agent editor should filter selectable KBs
|
||||
// when this preset is active. Predicates are evaluated against the KB's
|
||||
// capabilities (see KBCapabilities).
|
||||
//
|
||||
// If all three slices are empty, the preset imposes no KB restriction.
|
||||
type AgentTypeKBFilter struct {
|
||||
// AnyOf: KB must expose at least ONE of these capability flags.
|
||||
AnyOf []string `yaml:"any_of" json:"any_of,omitempty"`
|
||||
// AllOf: KB must expose ALL of these capability flags.
|
||||
AllOf []string `yaml:"all_of" json:"all_of,omitempty"`
|
||||
// NoneOf: KB must expose NONE of these capability flags.
|
||||
NoneOf []string `yaml:"none_of" json:"none_of,omitempty"`
|
||||
}
|
||||
|
||||
// AgentTypePresetEntry is one entry in the agent_type_presets list in YAML.
|
||||
//
|
||||
// Only fields relevant for auto-filling the editor form are included under
|
||||
// `config`. Everything else (retrieval thresholds, etc.) falls back to the
|
||||
// user-edited defaults / CustomAgent.EnsureDefaults.
|
||||
type AgentTypePresetEntry struct {
|
||||
ID string `yaml:"id" json:"id"`
|
||||
I18n map[string]AgentTypePresetI18n `yaml:"i18n" json:"i18n"`
|
||||
Config *AgentTypePresetConfig `yaml:"config" json:"config,omitempty"`
|
||||
KBFilter *AgentTypeKBFilter `yaml:"kb_filter" json:"kb_filter,omitempty"`
|
||||
}
|
||||
|
||||
// AgentTypePresetConfig is a restricted view of CustomAgentConfig used purely
|
||||
// as the preset payload. Any field left at its zero value is NOT applied by
|
||||
// the preset so the user's existing value stays untouched.
|
||||
//
|
||||
// We mirror json tags (not yaml tags) directly from CustomAgentConfig so the
|
||||
// frontend can apply them via simple Object.assign.
|
||||
type AgentTypePresetConfig struct {
|
||||
SystemPromptID string `yaml:"system_prompt_id" json:"system_prompt_id,omitempty"`
|
||||
Temperature float64 `yaml:"temperature" json:"temperature,omitempty"`
|
||||
MaxIterations int `yaml:"max_iterations" json:"max_iterations,omitempty"`
|
||||
AllowedTools []string `yaml:"allowed_tools" json:"allowed_tools,omitempty"`
|
||||
RetainRetrievalHistory bool `yaml:"retain_retrieval_history" json:"retain_retrieval_history,omitempty"`
|
||||
FAQPriorityEnabled bool `yaml:"faq_priority_enabled" json:"faq_priority_enabled,omitempty"`
|
||||
WebSearchEnabled bool `yaml:"web_search_enabled" json:"web_search_enabled,omitempty"`
|
||||
SupportedFileTypes []string `yaml:"supported_file_types" json:"supported_file_types,omitempty"`
|
||||
// KBSelectionMode presets the KB picker mode: "all" | "selected" | "none".
|
||||
// When empty, the user's current value stays untouched.
|
||||
KBSelectionMode string `yaml:"kb_selection_mode" json:"kb_selection_mode,omitempty"`
|
||||
}
|
||||
|
||||
// agentTypePresetsFile is the top-level YAML structure.
|
||||
type agentTypePresetsFile struct {
|
||||
Presets []AgentTypePresetEntry `yaml:"agent_type_presets"`
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Global registry (populated from YAML at startup)
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
var (
|
||||
agentTypePresets map[string]*AgentTypePresetEntry // keyed by preset ID
|
||||
agentTypePresetsMu sync.RWMutex
|
||||
agentTypePresetsOnce sync.Once
|
||||
agentTypePresetIDs []string // insertion order, for stable UI listing
|
||||
)
|
||||
|
||||
// LoadAgentTypePresetsConfig loads agent-type preset definitions from the given
|
||||
// config directory (e.g. "./config"). The file must be named
|
||||
// "agent_type_presets.yaml". Called once at startup (after LoadConfig determines
|
||||
// the config directory).
|
||||
//
|
||||
// If the file does not exist, this is a no-op and the registry stays empty —
|
||||
// in that case the frontend will simply not offer the agent-type dropdown.
|
||||
func LoadAgentTypePresetsConfig(configDir string) error {
|
||||
var loadErr error
|
||||
agentTypePresetsOnce.Do(func() {
|
||||
filePath := filepath.Join(configDir, "agent_type_presets.yaml")
|
||||
data, err := os.ReadFile(filePath)
|
||||
if err != nil {
|
||||
if os.IsNotExist(err) {
|
||||
return
|
||||
}
|
||||
loadErr = fmt.Errorf("read agent_type_presets.yaml: %w", err)
|
||||
return
|
||||
}
|
||||
|
||||
var file agentTypePresetsFile
|
||||
if err := yaml.Unmarshal(data, &file); err != nil {
|
||||
loadErr = fmt.Errorf("parse agent_type_presets.yaml: %w", err)
|
||||
return
|
||||
}
|
||||
|
||||
agentTypePresetsMu.Lock()
|
||||
defer agentTypePresetsMu.Unlock()
|
||||
|
||||
agentTypePresets = make(map[string]*AgentTypePresetEntry, len(file.Presets))
|
||||
agentTypePresetIDs = make([]string, 0, len(file.Presets))
|
||||
for i := range file.Presets {
|
||||
entry := &file.Presets[i]
|
||||
if entry.ID == "" {
|
||||
continue
|
||||
}
|
||||
agentTypePresets[entry.ID] = entry
|
||||
agentTypePresetIDs = append(agentTypePresetIDs, entry.ID)
|
||||
}
|
||||
})
|
||||
return loadErr
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Public API
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
// ListAgentTypePresetsWithContext returns all registered agent-type presets in
|
||||
// their YAML-declared order, with i18n resolved against the request locale.
|
||||
//
|
||||
// The returned slice is a fresh copy safe to mutate by the caller (e.g. to
|
||||
// tweak the i18n label before encoding).
|
||||
func ListAgentTypePresetsWithContext(ctx context.Context) []AgentTypePresetEntry {
|
||||
locale := localeFromCtx(ctx)
|
||||
|
||||
agentTypePresetsMu.RLock()
|
||||
defer agentTypePresetsMu.RUnlock()
|
||||
|
||||
out := make([]AgentTypePresetEntry, 0, len(agentTypePresetIDs))
|
||||
for _, id := range agentTypePresetIDs {
|
||||
entry := agentTypePresets[id]
|
||||
if entry == nil {
|
||||
continue
|
||||
}
|
||||
// Shallow copy and narrow i18n down to the caller's locale so the
|
||||
// API response is compact. We keep both "default" and the resolved
|
||||
// locale entry in case the frontend wants to fall back.
|
||||
cp := *entry
|
||||
if len(entry.I18n) > 0 {
|
||||
cp.I18n = resolveAgentTypeI18n(entry.I18n, locale)
|
||||
}
|
||||
out = append(out, cp)
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
// GetAgentTypePreset returns the raw entry for the given preset ID, or nil.
|
||||
// Used by prompt-resolution at startup.
|
||||
func GetAgentTypePreset(id string) *AgentTypePresetEntry {
|
||||
agentTypePresetsMu.RLock()
|
||||
defer agentTypePresetsMu.RUnlock()
|
||||
return agentTypePresets[id]
|
||||
}
|
||||
|
||||
// ResolveAgentTypePresetPromptRefs iterates over all presets and resolves
|
||||
// system_prompt_id references into the actual prompt template content via the
|
||||
// provided resolver. This lets downstream services treat the `system_prompt_id`
|
||||
// field as a concrete prompt string if they need to.
|
||||
//
|
||||
// We keep system_prompt_id as-is in the preset (it's also what the editor
|
||||
// writes back to CustomAgentConfig), so this hook is only used to validate
|
||||
// that every referenced template actually exists at startup.
|
||||
func ResolveAgentTypePresetPromptRefs(resolver func(id string) string) {
|
||||
agentTypePresetsMu.Lock()
|
||||
defer agentTypePresetsMu.Unlock()
|
||||
for _, entry := range agentTypePresets {
|
||||
if entry == nil || entry.Config == nil || entry.Config.SystemPromptID == "" {
|
||||
continue
|
||||
}
|
||||
if content := resolver(entry.Config.SystemPromptID); content == "" {
|
||||
fmt.Printf(
|
||||
"Warning: agent type preset %q references system_prompt_id %q but template not found\n",
|
||||
entry.ID, entry.Config.SystemPromptID,
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// resolveAgentTypeI18n picks a reasonable subset of i18n entries for the given
|
||||
// locale: the exact-match entry (if any) plus the "default" fallback. Callers
|
||||
// that want full i18n can pass an empty locale to get everything.
|
||||
func resolveAgentTypeI18n(m map[string]AgentTypePresetI18n, locale string) map[string]AgentTypePresetI18n {
|
||||
out := make(map[string]AgentTypePresetI18n, 2)
|
||||
if v, ok := m["default"]; ok {
|
||||
out["default"] = v
|
||||
}
|
||||
if locale != "" {
|
||||
if v, ok := m[locale]; ok {
|
||||
out[locale] = v
|
||||
}
|
||||
}
|
||||
// If neither matched, surface the whole map so the frontend can decide.
|
||||
if len(out) == 0 {
|
||||
for k, v := range m {
|
||||
out[k] = v
|
||||
}
|
||||
}
|
||||
return out
|
||||
}
|
||||
@@ -36,6 +36,27 @@ const (
|
||||
AgentModeSmartReasoning = "smart-reasoning"
|
||||
)
|
||||
|
||||
// AgentType constants for Smart-Reasoning agent presets.
|
||||
// These presets bundle a recommended system prompt template,
|
||||
// tool allowlist, KB compatibility hint, and other defaults so users
|
||||
// don't have to configure everything from scratch.
|
||||
// AgentTypeCustom means the user wants full control and we won't
|
||||
// auto-fill anything based on the preset.
|
||||
const (
|
||||
// AgentTypeRAGQA prefers vector/keyword chunk retrieval on document KBs.
|
||||
AgentTypeRAGQA = "rag-qa"
|
||||
// AgentTypeWikiQA prefers wiki-page navigation on wiki-enabled KBs.
|
||||
AgentTypeWikiQA = "wiki-qa"
|
||||
// AgentTypeHybridRAGWiki orchestrates Wiki + RAG on KBs where both are enabled.
|
||||
AgentTypeHybridRAGWiki = "hybrid-rag-wiki"
|
||||
// AgentTypeDataAnalysis runs SQL / statistics over tabular files (CSV, Excel)
|
||||
// uploaded into the KB. Retrieval semantics (vector/wiki/…) are largely
|
||||
// irrelevant — this type is about data_schema + data_analysis tools.
|
||||
AgentTypeDataAnalysis = "data-analysis"
|
||||
// AgentTypeCustom is the "no preset" option; user-configured end to end.
|
||||
AgentTypeCustom = "custom"
|
||||
)
|
||||
|
||||
// CustomAgent represents a configurable AI agent (similar to GPTs)
|
||||
type CustomAgent struct {
|
||||
// Unique identifier of the agent (composite primary key with TenantID)
|
||||
@@ -69,6 +90,12 @@ type CustomAgentConfig struct {
|
||||
// ===== Basic Settings =====
|
||||
// Agent mode: "quick-answer" for RAG mode, "smart-reasoning" for ReAct agent mode
|
||||
AgentMode string `yaml:"agent_mode" json:"agent_mode"`
|
||||
// AgentType is a preset category under smart-reasoning mode that pre-fills
|
||||
// system prompt, allowed tools and recommended KB compatibility.
|
||||
// Valid values: "rag-qa", "wiki-qa", "hybrid-rag-wiki", "custom".
|
||||
// Empty / unknown values are treated as "custom" (no preset applied).
|
||||
// Ignored for quick-answer mode.
|
||||
AgentType string `yaml:"agent_type" json:"agent_type,omitempty"`
|
||||
// System prompt for the agent (unified prompt, uses web_search_status placeholder for dynamic behavior)
|
||||
SystemPrompt string `yaml:"system_prompt" json:"system_prompt"`
|
||||
// SystemPromptID references a template ID in prompt_templates/ YAML files.
|
||||
@@ -119,13 +146,6 @@ type CustomAgentConfig struct {
|
||||
// When false, knowledge base retrieval happens according to KBSelectionMode
|
||||
RetrieveKBOnlyWhenMentioned bool `yaml:"retrieve_kb_only_when_mentioned" json:"retrieve_kb_only_when_mentioned"`
|
||||
|
||||
// RetrievalPreference controls which retrieval tools the agent uses:
|
||||
// "auto" - auto-detect from KB capabilities (default, preserves existing behavior)
|
||||
// "vector_only" - only use vector/keyword search tools, no wiki tools
|
||||
// "wiki_only" - only use wiki tools, no vector/keyword search tools
|
||||
// "hybrid" - use both vector/keyword search AND wiki tools
|
||||
RetrievalPreference string `yaml:"retrieval_preference" json:"retrieval_preference"`
|
||||
|
||||
// Whether to retain retrieval history across turns
|
||||
RetainRetrievalHistory bool `yaml:"retain_retrieval_history" json:"retain_retrieval_history"`
|
||||
|
||||
@@ -269,9 +289,6 @@ func (a *CustomAgent) EnsureDefaults() {
|
||||
if a.Config.FallbackStrategy == "" {
|
||||
a.Config.FallbackStrategy = "model"
|
||||
}
|
||||
if a.Config.RetrievalPreference == "" {
|
||||
a.Config.RetrievalPreference = "auto"
|
||||
}
|
||||
if a.Config.MaxCompletionTokens == 0 {
|
||||
a.Config.MaxCompletionTokens = 2048
|
||||
}
|
||||
|
||||
@@ -532,6 +532,53 @@ func (kb *KnowledgeBase) EnsureDefaults() {
|
||||
}
|
||||
}
|
||||
|
||||
// KBCapabilities describes the functional features a knowledge base exposes.
|
||||
// It is computed from the KB's configuration (IndexingStrategy, Type, WikiConfig, …)
|
||||
// and surfaced in the JSON representation of a KnowledgeBase so that the frontend
|
||||
// can filter / enable / disable KB options based on what the selected agent type needs.
|
||||
type KBCapabilities struct {
|
||||
// Vector means semantic (embedding) search is indexed.
|
||||
Vector bool `json:"vector"`
|
||||
// Keyword means BM25 / sparse keyword search is indexed.
|
||||
Keyword bool `json:"keyword"`
|
||||
// Wiki means the wiki feature is enabled and authored pages exist / will be generated.
|
||||
Wiki bool `json:"wiki"`
|
||||
// Graph means knowledge-graph extraction is enabled.
|
||||
Graph bool `json:"graph"`
|
||||
// FAQ means the KB is a FAQ-type KB (Q/A pairs).
|
||||
FAQ bool `json:"faq"`
|
||||
}
|
||||
|
||||
// Capabilities returns the computed capability flags for this KB.
|
||||
// Safe to call on a nil KB (returns zero value).
|
||||
func (kb *KnowledgeBase) Capabilities() KBCapabilities {
|
||||
if kb == nil {
|
||||
return KBCapabilities{}
|
||||
}
|
||||
return KBCapabilities{
|
||||
Vector: kb.IsVectorEnabled(),
|
||||
Keyword: kb.IsKeywordEnabled(),
|
||||
Wiki: kb.IsWikiEnabled(),
|
||||
Graph: kb.IsGraphEnabled(),
|
||||
FAQ: kb.Type == KnowledgeBaseTypeFAQ,
|
||||
}
|
||||
}
|
||||
|
||||
// MarshalJSON augments the default JSON encoding of KnowledgeBase with a computed
|
||||
// `capabilities` field so clients (agent editor) can filter KBs by feature.
|
||||
// It preserves all existing fields verbatim.
|
||||
func (kb *KnowledgeBase) MarshalJSON() ([]byte, error) {
|
||||
type alias KnowledgeBase
|
||||
aux := struct {
|
||||
*alias
|
||||
Capabilities KBCapabilities `json:"capabilities"`
|
||||
}{
|
||||
alias: (*alias)(kb),
|
||||
Capabilities: kb.Capabilities(),
|
||||
}
|
||||
return json.Marshal(aux)
|
||||
}
|
||||
|
||||
// IsWikiEnabled checks if the wiki feature is enabled for this knowledge base.
|
||||
// Wiki requires both IndexingStrategy.WikiEnabled and WikiConfig with Enabled=true.
|
||||
func (kb *KnowledgeBase) IsWikiEnabled() bool {
|
||||
|
||||
Reference in New Issue
Block a user