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:
@@ -165,6 +165,57 @@ export function deriveKbFilterFromTools(
|
||||
return { any_of: Array.from(caps) };
|
||||
}
|
||||
|
||||
/**
|
||||
* Implicit KB capability requirement for the "quick-answer" (RAG) agent
|
||||
* mode. Quick-answer drives retrieval purely through vector/keyword chunk
|
||||
* search and ships with NO `allowed_tools`, so the tool-derived filter
|
||||
* alone would let wiki-only KBs through even though they can't contribute
|
||||
* anything to a RAG answer. Treat this as a property of the agent MODE.
|
||||
*/
|
||||
const QUICK_ANSWER_KB_FILTER: { any_of: KBCapability[] } = {
|
||||
any_of: ['vector', 'keyword'],
|
||||
};
|
||||
|
||||
/**
|
||||
* Agent-mode aware version of `deriveKbFilterFromTools`: unions the
|
||||
* tool-derived `any_of` with the implicit requirement of `agentMode`
|
||||
* (currently: quick-answer → vector|keyword).
|
||||
*
|
||||
* Returns `null` when neither the agent mode nor the tools impose any
|
||||
* capability constraint (i.e. any KB is acceptable).
|
||||
*/
|
||||
export function deriveKbFilterForAgent(
|
||||
agentMode: string | undefined | null,
|
||||
allowedTools: string[] | undefined | null,
|
||||
): { any_of: KBCapability[] } | null {
|
||||
const caps = new Set<KBCapability>();
|
||||
if (agentMode === 'quick-answer') {
|
||||
QUICK_ANSWER_KB_FILTER.any_of.forEach(c => caps.add(c));
|
||||
}
|
||||
const fromTools = deriveKbFilterFromTools(allowedTools || []);
|
||||
fromTools?.any_of.forEach(c => caps.add(c));
|
||||
if (caps.size === 0) return null;
|
||||
return { any_of: Array.from(caps) };
|
||||
}
|
||||
|
||||
/**
|
||||
* Agent-mode aware version of `kbSatisfiesToolRequirements`: ALSO honours
|
||||
* the implicit capability requirement of `agentMode` (quick-answer needs
|
||||
* vector or keyword indexing). Use this anywhere the user is choosing a
|
||||
* KB for an agent — agent editor "specified KB" dropdown, chat `@`
|
||||
* mention list, etc.
|
||||
*/
|
||||
export function kbSatisfiesAgentRequirements(
|
||||
kbCaps: Partial<ScopeCapabilities> | undefined | null,
|
||||
agentMode: string | undefined | null,
|
||||
allowedTools: string[] | undefined | null,
|
||||
): boolean {
|
||||
const filter = deriveKbFilterForAgent(agentMode, allowedTools);
|
||||
if (!filter) return true;
|
||||
if (!kbCaps) return false;
|
||||
return filter.any_of.some(c => !!kbCaps[c]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Decide whether a single KB is compatible with an agent's tool set.
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user