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:
@@ -20,8 +20,8 @@ import { getConversationConfig, updateConversationConfig, type ConversationConfi
|
||||
import { useI18n } from 'vue-i18n';
|
||||
import AttachmentUpload, { type AttachmentFile } from './AttachmentUpload.vue';
|
||||
import {
|
||||
kbSatisfiesToolRequirements,
|
||||
deriveKbFilterFromTools,
|
||||
kbSatisfiesAgentRequirements,
|
||||
deriveKbFilterForAgent,
|
||||
toolsConsumeFiles,
|
||||
type ScopeCapabilities,
|
||||
} from '@/utils/tool-capabilities';
|
||||
@@ -303,12 +303,19 @@ const kbToScopeCaps = (kb: any): Partial<ScopeCapabilities> => {
|
||||
};
|
||||
};
|
||||
|
||||
// 当前智能体的 agent_mode(quick-answer / smart-reasoning),用于把
|
||||
// "RAG-only 模式不能 @ wiki-only 知识库"这种隐式约束带进 KB 过滤。
|
||||
const agentMode = computed(() => {
|
||||
if (!hasAgentConfig.value) return '';
|
||||
return currentAgentConfig.value?.agent_mode || '';
|
||||
});
|
||||
|
||||
// "all" 模式 + 智能体工具有 KB 依赖时的兼容性过滤;'selected'/'none' 不在这里二次过滤
|
||||
// (selected 由编辑器负责,none 已经空表)。
|
||||
const isKbCompatibleWithAgent = (kb: any): boolean => {
|
||||
if (!hasAgentConfig.value) return true;
|
||||
if (agentKBSelectionMode.value !== 'all') return true;
|
||||
return kbSatisfiesToolRequirements(kbToScopeCaps(kb), agentAllowedTools.value);
|
||||
return kbSatisfiesAgentRequirements(kbToScopeCaps(kb), agentMode.value, agentAllowedTools.value);
|
||||
};
|
||||
|
||||
// 仅在用户没输入搜索词、且是因智能体工具兼容性把列表清空的场景展示专用空态文案
|
||||
@@ -318,7 +325,7 @@ const mentionEmptyHint = computed(() => {
|
||||
if (agentKBSelectionMode.value !== 'all') return '';
|
||||
// 列表为空 && 兼容性过滤器其实是有效的(否则"全部"不会被剔空)
|
||||
if (mentionItems.value.length !== 0) return '';
|
||||
const filter = deriveKbFilterFromTools(agentAllowedTools.value);
|
||||
const filter = deriveKbFilterForAgent(agentMode.value, agentAllowedTools.value);
|
||||
if (!filter) return '';
|
||||
return t('mentionDetail.noCompatibleKbForAgent');
|
||||
});
|
||||
|
||||
@@ -3933,6 +3933,7 @@ export default {
|
||||
wikiQa: 'Wiki not enabled',
|
||||
hybridRagWiki: 'No retrieval surface enabled',
|
||||
dataAnalysis: 'Requires RAG (FAQ not supported)',
|
||||
quickAnswer: 'Quick Answer mode requires RAG retrieval',
|
||||
generic: 'Not compatible with current type',
|
||||
},
|
||||
kbIncompatibleWarn: '{count} selected KB(s) are not compatible with this type, please adjust manually.',
|
||||
|
||||
@@ -4000,6 +4000,7 @@ export default {
|
||||
wikiQa: 'Wiki 비활성화',
|
||||
hybridRagWiki: '활성화된 검색 수단 없음',
|
||||
dataAnalysis: 'RAG 필요 (FAQ 미지원)',
|
||||
quickAnswer: '빠른 답변 모드는 RAG 검색이 필요합니다',
|
||||
generic: '현재 유형과 호환 안 됨',
|
||||
},
|
||||
kbIncompatibleWarn: '선택된 {count}개의 지식 베이스가 현재 유형과 호환되지 않습니다. 수동으로 조정해 주세요.',
|
||||
|
||||
@@ -3609,6 +3609,7 @@ export default {
|
||||
wikiQa: 'Wiki отключён',
|
||||
hybridRagWiki: 'Поиск не включён',
|
||||
dataAnalysis: 'Требуется RAG (не FAQ)',
|
||||
quickAnswer: 'Быстрый ответ требует RAG-поиск',
|
||||
generic: 'Несовместимо с типом',
|
||||
},
|
||||
kbIncompatibleWarn: 'Выбранные базы знаний ({count}) несовместимы с текущим типом. Настройте вручную.'
|
||||
|
||||
@@ -3929,6 +3929,7 @@ export default {
|
||||
wikiQa: "未启用 Wiki",
|
||||
hybridRagWiki: "未启用任何检索能力",
|
||||
dataAnalysis: "需启用 RAG(不支持 FAQ)",
|
||||
quickAnswer: "快速问答模式需启用 RAG 检索",
|
||||
generic: "不适用于当前类型",
|
||||
},
|
||||
kbIncompatibleWarn: "已选的 {count} 个知识库不适用于当前类型,请手动调整",
|
||||
|
||||
@@ -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.
|
||||
*
|
||||
|
||||
@@ -2019,21 +2019,38 @@ const kbSatisfiesPresetFilter = (kb: { capabilities?: KBCapabilities; ragEnabled
|
||||
return { ok: true, reason: '' };
|
||||
};
|
||||
|
||||
// "快速问答 / RAG 模式"对 KB 的隐式要求:必须有 vector 或 keyword 索引。
|
||||
// 这里跟 `activeAgentTypePreset` 解耦——quick-answer 没有 agent_type,
|
||||
// 所以预设链路恒为 null,但 wiki-only KB 在 RAG 模式下检索结果永远为空,
|
||||
// 必须在 UI 上 disable + 提示,避免用户白选。
|
||||
const kbSatisfiesQuickAnswerMode = (kb: { capabilities?: KBCapabilities; ragEnabled?: boolean }): { ok: boolean; reason: string } => {
|
||||
if (agentMode.value !== 'quick-answer') return { ok: true, reason: '' };
|
||||
const hasRag = kb.capabilities
|
||||
? (!!kb.capabilities.vector || !!kb.capabilities.keyword)
|
||||
: !!kb.ragEnabled;
|
||||
if (hasRag) return { ok: true, reason: '' };
|
||||
return { ok: false, reason: t('agentEditor.agentType.kbMismatch.quickAnswer') };
|
||||
};
|
||||
|
||||
// KB 过滤后的选项(用于"指定知识库"下拉)— 不满足的仍保留但标记 disabled + tooltip
|
||||
const filteredKbOptionsForPreset = computed(() => {
|
||||
const preset = activeAgentTypePreset.value;
|
||||
return kbOptions.value.map(kb => {
|
||||
const { ok, reason } = kbSatisfiesPresetFilter(kb, preset);
|
||||
const presetResult = kbSatisfiesPresetFilter(kb, preset);
|
||||
const modeResult = kbSatisfiesQuickAnswerMode(kb);
|
||||
const ok = presetResult.ok && modeResult.ok;
|
||||
const reason = !presetResult.ok ? presetResult.reason : (!modeResult.ok ? modeResult.reason : '');
|
||||
return { ...kb, disabled: !ok, disabledReason: reason };
|
||||
});
|
||||
});
|
||||
const filteredMyKbOptions = computed(() => filteredKbOptionsForPreset.value.filter(kb => !kb.shared));
|
||||
const filteredSharedKbOptions = computed(() => filteredKbOptionsForPreset.value.filter(kb => kb.shared));
|
||||
|
||||
// 当前选中的 KB 中,有多少个在新预设下会被禁用(用于保存前提示)
|
||||
// 当前选中的 KB 中,有多少个在新预设 / 模式下会被禁用(用于保存前提示)。
|
||||
// quick-answer 模式下 preset 恒为 null,但 wiki-only KB 仍属"被禁用",
|
||||
// 所以这里不再依赖 preset 是否存在,直接看是否有被 disable 的选中项。
|
||||
const incompatibleSelectedKbCount = computed(() => {
|
||||
const preset = activeAgentTypePreset.value;
|
||||
if (!preset || kbSelectionMode.value !== 'selected') return 0;
|
||||
if (kbSelectionMode.value !== 'selected') return 0;
|
||||
const selected = new Set(formData.value.config.knowledge_bases || []);
|
||||
return filteredKbOptionsForPreset.value.filter(kb => selected.has(kb.value) && kb.disabled).length;
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user