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:
wizardchen
2026-05-12 15:41:47 +08:00
committed by lyingbug
parent a082c04d28
commit d199628701
13 changed files with 185 additions and 23 deletions
+7 -4
View File
@@ -52,14 +52,17 @@ func (c *SearchCommand) Execute(ctx context.Context, cmdCtx *CommandContext, arg
case "all":
allKBs, err := c.kbService.ListKnowledgeBases(ctx)
if err == nil {
// Same tool-capability filter as the QA pipeline's
// Same capability filter as the QA pipeline's
// resolveKnowledgeBasesFromAgent (`all` branch) so `/search`
// agrees with what the agent's tools can actually reach.
filter := tools.DeriveKBFilterFromTools(cmdCtx.CustomAgent.Config.AllowedTools)
// Agent-mode aware: quick-answer enforces RAG-only KBs.
agentMode := cmdCtx.CustomAgent.Config.AgentMode
allowed := cmdCtx.CustomAgent.Config.AllowedTools
filter := tools.DeriveKBFilterForAgent(agentMode, allowed)
skipped := 0
for _, kb := range allKBs {
if !filter.IsEmpty() &&
!tools.KBSatisfiesToolRequirements(kb.Capabilities(), cmdCtx.CustomAgent.Config.AllowedTools) {
!tools.KBSatisfiesAgentRequirements(kb.Capabilities(), agentMode, allowed) {
skipped++
continue
}
@@ -67,7 +70,7 @@ func (c *SearchCommand) Execute(ctx context.Context, cmdCtx *CommandContext, arg
}
if skipped > 0 {
logger.Infof(ctx,
"/search(agent=%s, mode=all): tool-capability filter removed %d of %d KBs",
"/search(agent=%s, mode=all): capability filter removed %d of %d KBs",
cmdCtx.CustomAgent.ID, skipped, len(allKBs))
}
}