fix(agent): exclude wiki-only KBs from quick-answer (RAG) mode
Quick-answer agent mode retrieves purely through vector/keyword chunk search and ships with no `allowed_tools`, so the existing capability filter (which only reads from `allowed_tools`) let wiki-only KBs through in every entry point. End result: users could @-mention, select, and receive suggested questions from wiki-only KBs in quick-answer mode, but the underlying retrieval always returned empty. Treat "RAG-only" as an implicit property of `agent_mode = quick-answer` and union it with the tool-derived filter. The same predicate is now used everywhere the user can pick or be steered toward a KB: Backend - `tools.DeriveKBFilterForAgent` / `KBSatisfiesAgentRequirements` layer the implicit quick-answer requirement on top of tool derivation. - `ListKnowledgeBases`, `SearchKnowledge` (shared-agent `@file`), `resolveKnowledgeBasesFromAgent` (chat runtime), `/search` IM command, and `GetSuggestedQuestions` now all use the agent-mode-aware variant. - `GetSuggestedQuestions` also skips the wiki-page fallback for quick-answer agents to cover the `selected` / explicit-kb-ids paths where a wiki-only KB could still slip through. Frontend - `deriveKbFilterForAgent` / `kbSatisfiesAgentRequirements` mirror the Go helpers. - `@` mention dropdown (`Input-field.vue`) uses the new helper. - Agent editor's "specified KB" picker (`AgentEditorModal.vue`) grays out wiki-only KBs for quick-answer agents with a tooltip, and the pre-save warning fires for quick-answer mode too. - i18n: add `agentEditor.agentType.kbMismatch.quickAnswer` across all four locales.
This commit is contained in:
@@ -357,21 +357,24 @@ func (h *KnowledgeBaseHandler) ListKnowledgeBases(c *gin.Context) {
|
||||
|
||||
// `all` mode: authoritative server-side capability filter so a client
|
||||
// that bypassed the frontend (old tab, curl, rogue plugin) can't @ a
|
||||
// KB whose capabilities don't match any allowed tool of this agent.
|
||||
// KB whose capabilities don't match this agent. The filter combines
|
||||
// tool-derived requirements (smart-reasoning) with the implicit
|
||||
// RAG-only requirement of quick-answer mode (which has no
|
||||
// `allowed_tools` but still needs vector/keyword chunks to work).
|
||||
// Non-`all` modes already constrain the scope explicitly.
|
||||
if mode == "all" && len(agent.Config.AllowedTools) > 0 {
|
||||
filter := tools.DeriveKBFilterFromTools(agent.Config.AllowedTools)
|
||||
if mode == "all" {
|
||||
filter := tools.DeriveKBFilterForAgent(agent.Config.AgentMode, agent.Config.AllowedTools)
|
||||
if !filter.IsEmpty() {
|
||||
before := len(kbs)
|
||||
kept := make([]*types.KnowledgeBase, 0, before)
|
||||
for _, kb := range kbs {
|
||||
if tools.KBSatisfiesToolRequirements(kb.Capabilities(), agent.Config.AllowedTools) {
|
||||
if tools.KBSatisfiesAgentRequirements(kb.Capabilities(), agent.Config.AgentMode, agent.Config.AllowedTools) {
|
||||
kept = append(kept, kb)
|
||||
}
|
||||
}
|
||||
if removed := before - len(kept); removed > 0 {
|
||||
logger.Infof(ctx,
|
||||
"ListKnowledgeBases(agent=%s, mode=all): tool-capability filter removed %d of %d KBs",
|
||||
"ListKnowledgeBases(agent=%s, mode=all): capability filter removed %d of %d KBs",
|
||||
agentID, removed, before)
|
||||
}
|
||||
kbs = kept
|
||||
|
||||
Reference in New Issue
Block a user