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(agent-share): don't require rerank model for wiki-only agents
wizardchenb8c45b173e41
diff --git a/internal/application/service/agent_share.go b/internal/application/service/agent_share.goindex 1a7650580..40216b1d6 100644--- a/internal/application/service/agent_share.go+++ b/internal/application/service/agent_share.go@@ -6,6 +6,7 @@ import ("fmt""time"+ "github.com/Tencent/WeKnora/internal/agent/tools""github.com/Tencent/WeKnora/internal/application/repository""github.com/Tencent/WeKnora/internal/logger""github.com/Tencent/WeKnora/internal/types"@@ -19,9 +20,35 @@ var (ErrAgentNotFoundForShare = errors.New("agent not found")ErrNotAgentOwner = errors.New("only agent owner can share")ErrOrgRoleCannotShareAgent = errors.New("only editors and admins can share agents to this organization")- ErrAgentNotConfigured = errors.New("agent is not fully configured (missing required chat model or rerank model when using knowledge bases)")+ ErrAgentNotConfigured = errors.New("agent is not fully configured (missing required chat model, or rerank model when the knowledge_search tool is enabled)"))+// agentRequiresRerankModel returns true when the agent's configured tools+// will actually invoke the reranker at runtime. This mirrors the runtime+// check in session_agent_qa.go: only `knowledge_search` uses the reranker.+// Wiki-first agents (wiki_search / wiki_read_page / …) never call it and+// therefore don't need a rerank model configured, even when knowledge bases+// are attached.+//+// When AllowedTools is empty the runtime falls back to+// tools.DefaultAllowedTools(), which includes knowledge_search, so we treat+// that case as requiring the reranker.+func agentRequiresRerankModel(agent *types.CustomAgent) bool {+ if agent == nil {+ return false+ }+ allowed := agent.Config.AllowedTools+ if len(allowed) == 0 {+ allowed = tools.DefaultAllowedTools()+ }+ for _, t := range allowed {+ if t == tools.ToolKnowledgeSearch {+ return true+ }+ }+ return false+}+// agentShareService implements AgentShareService interfacetype agentShareService struct {shareRepo interfaces.AgentShareRepository@@ -60,12 +87,14 @@ func (s *agentShareService) ShareAgent(ctx context.Context, agentID string, orgIreturn nil, ErrNotAgentOwner}- // Require agent to be fully configured before sharing (same rules as for conversation)+ // Require agent to be fully configured before sharing (same rules as for+ // conversation — see session_agent_qa.go). Rerank model is only required+ // when the `knowledge_search` tool is enabled; Wiki-only agents+ // (wiki_search / wiki_read_page) don't call the reranker at runtime.if agent.Config.ModelID == "" {return nil, ErrAgentNotConfigured}- usesKB := agent.Config.KBSelectionMode != "none" || len(agent.Config.KnowledgeBases) > 0- if usesKB && agent.Config.RerankModelID == "" {+ if agentRequiresRerankModel(agent) && agent.Config.RerankModelID == "" {return nil, ErrAgentNotConfigured}diff --git a/internal/handler/organization.go b/internal/handler/organization.goindex a42868199..38d430431 100644--- a/internal/handler/organization.go+++ b/internal/handler/organization.go@@ -1262,7 +1262,7 @@ func (h *OrganizationHandler) ShareAgent(c *gin.Context) {return}if errors.Is(err, service.ErrAgentNotConfigured) {- c.Error(apperrors.NewValidationError("Agent is not fully configured. Please set the chat model and, if using knowledge bases, the rerank model in agent settings."))+ c.Error(apperrors.NewValidationError("Agent is not fully configured. Please set the chat model, and set the rerank model if the knowledge_search tool is enabled in agent settings."))return}c.Error(apperrors.NewForbiddenError("Permission denied or invalid operation"))