Skip to content

fix: preserve configured KB scope for accurate search notices - #3904

Open
cj2026-bit wants to merge 9 commits into
developfrom
fix-kb-search-scope-notice
Open

fix: preserve configured KB scope for accurate search notices#3904
cj2026-bit wants to merge 9 commits into
developfrom
fix-kb-search-scope-notice

Conversation

@cj2026-bit

@cj2026-bit cj2026-bit commented Sep 9, 2026

Copy link
Copy Markdown
Collaborator

本次 PR 解决了什么 Bug

当一次知识库检索同时请求多个知识库时,后端会在生成运行时工具配置前,把无权限知识库从完整配置范围中删除。SDK 最终只能收到剩余的可访问知识库,因此无法区分:

  • 已配置但当前用户无权限
  • 未配置、不存在或不可用

这会导致原本属于“无权限”的知识库被错误提示为 not configured or unavailable,误导用户和模型判断失败原因。

解决方案

  • 后端保留 Agent 本次完整配置的知识库 ID 范围,并继续通过 allowed_kds_set 传递真实有权限范围。
  • SDK 使用“完整配置范围 - 有权限范围”识别无权限知识库,再生成准确 notice。
  • 名称映射覆盖完整配置范围内已有的非空 kds_name,确保按知识库名称调用时也能正确分类。
  • 权限快照查询失败时继续 fail-closed,不扩大检索范围。
  • AIDP 实际检索请求仍只包含有权限知识库,不会越权访问。

验证测试

自动化测试

  • test_create_agent_info.py:229 passed
  • AIDP search tool:68 passed
  • AIDP access/permission:80 passed
  • Ruff 检查通过
  • CI:GitHub Actions、CodeQL、SonarCloud、Codecov patch、Docker 构建全部通过

HTTP 接口验证

使用 DEV 账号通过真实 /api/agent/run 调用 AIDP Agent,请求 test666test123AIDP API Guidetest888,返回 notice:

NOTICE: Requested knowledge bases were filtered (no read permission: ["test123"]; not configured or unavailable: ["AIDP API Guide", "test888"]). Search was executed in the remaining available knowledge bases ["test666"]. Do not retry the filtered knowledge bases. No relevant information was found.

验证截图

修正后的权限过滤提示:

修正后的权限过滤提示

全部无效知识库回退到已配置可用范围:

全部无效知识库回退

kds_list 回退到 Agent 已配置范围:

空 kds_list 回退

@codecov

codecov Bot commented Sep 9, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 98.78049% with 2 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
sdk/nexent/core/tools/ind_aidp_search_tool.py 92.30% 1 Missing and 1 partial ⚠️

📢 Thoughts on this report? Let us know!

cj2026-bit and others added 8 commits September 10, 2026 15:30
Keep internal index names and KDS IDs for retrieval while exposing configured knowledge-base display names in scope notices and metadata. Leave independent AIDP search unchanged and add regression coverage for both updated tools.

Co-authored-by: Codex <noreply@openai.com>

Generated-by: gpt-5-codex
Use the effective configured scope when every requested knowledge base is invalid, matching omitted-scope behavior. Reuse mapping normalization helpers and update the affected tests.

Co-authored-by: Codex <noreply@openai.com>

Generated-by: gpt-5-codex
Rely on the existing early return for empty search scopes before entering the ES search flow.

Co-authored-by: Codex <noreply@openai.com>

Generated-by: gpt-5-codex
Treat explicit empty scopes as no-search requests, preserve fallback for invalid non-empty scopes, and report unavailable scopes without claiming a search ran.

Co-authored-by: Codex <noreply@openai.com>

Generated-by: gpt-5-codex
Co-authored-by: GPT-5 <noreply@openai.com>
…e-notice

# Conflicts:
#	backend/agents/create_agent_info.py
@cj2026-bit cj2026-bit changed the title fix: report corrected knowledge search scope fix: preserve configured KB scope for accurate search notices Sep 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant