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:
@@ -152,6 +152,63 @@ func KBSatisfiesToolRequirements(caps types.KBCapabilities, allowedTools []strin
|
||||
return false
|
||||
}
|
||||
|
||||
// quickAnswerKBFilter is the implicit capability requirement for the
|
||||
// "quick-answer" (RAG) agent mode. Quick-answer drives retrieval purely
|
||||
// through vector/keyword chunk search, so a KB with neither chunk index
|
||||
// (e.g. wiki-only) cannot contribute any context and should be filtered
|
||||
// out everywhere the user can pick a KB (agent KB scope, `@` mention list,
|
||||
// chat KB selector).
|
||||
//
|
||||
// We treat this as a property of the agent MODE rather than of any
|
||||
// specific tool, because quick-answer mode doesn't ship with an
|
||||
// `allowed_tools` list — its retrieval is implicit.
|
||||
var quickAnswerKBFilter = KBFilter{AnyOf: []KBCapability{CapVector, CapKeyword}}
|
||||
|
||||
// DeriveKBFilterForAgent derives the effective KB capability filter for a
|
||||
// given agent configuration. It combines the implicit constraint from
|
||||
// `agentMode` (quick-answer forces vector|keyword) with the tool-derived
|
||||
// filter (any_of capabilities required by some allowed tool).
|
||||
//
|
||||
// The returned filter is the UNION of both contributions, which matches
|
||||
// the existing any_of semantics: a KB passes iff it exposes at least one
|
||||
// of the listed capabilities.
|
||||
func DeriveKBFilterForAgent(agentMode string, allowedTools []string) KBFilter {
|
||||
seen := make(map[KBCapability]struct{})
|
||||
if agentMode == "quick-answer" {
|
||||
for _, c := range quickAnswerKBFilter.AnyOf {
|
||||
seen[c] = struct{}{}
|
||||
}
|
||||
}
|
||||
for _, c := range DeriveKBFilterFromTools(allowedTools).AnyOf {
|
||||
seen[c] = struct{}{}
|
||||
}
|
||||
if len(seen) == 0 {
|
||||
return KBFilter{}
|
||||
}
|
||||
out := make([]KBCapability, 0, len(seen))
|
||||
for c := range seen {
|
||||
out = append(out, c)
|
||||
}
|
||||
return KBFilter{AnyOf: out}
|
||||
}
|
||||
|
||||
// KBSatisfiesAgentRequirements is the agent-aware variant of
|
||||
// KBSatisfiesToolRequirements: it also enforces the implicit capability
|
||||
// constraints of `agentMode` (currently: quick-answer requires vector or
|
||||
// keyword indexing on the KB).
|
||||
func KBSatisfiesAgentRequirements(caps types.KBCapabilities, agentMode string, allowedTools []string) bool {
|
||||
f := DeriveKBFilterForAgent(agentMode, allowedTools)
|
||||
if f.IsEmpty() {
|
||||
return true
|
||||
}
|
||||
for _, c := range f.AnyOf {
|
||||
if hasCap(caps, c) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// ToolsConsumeFiles reports whether any tool in the allowed-tools list can
|
||||
// use user-provided file references. Used to gate the `@file` listing in
|
||||
// the chat input (and potentially SearchKnowledge defensively on the
|
||||
|
||||
Reference in New Issue
Block a user