🤯 LobeHub - Super-Agents on Your Team. Add super-agents to the chats your team already uses.They take on work by themselves and get better every week.
TypeScript agentagent-collaborationagent-harnessloop-engineeringmcppersonal-assistantproactive-agentskillssuper-agenttask-management
🐛 fix(builtin-tools): stop Agent Documents from shadowing Knowledge Base for file lookups (#19085)
LiJian5449f616d735
diff --git a/locales/en-US/setting.json b/locales/en-US/setting.jsonindex 6ab037f8fcd..a9ca8476540 100644--- a/locales/en-US/setting.json+++ b/locales/en-US/setting.json@@ -1454,7 +1454,7 @@"tools.builtins.lobe-agent-browser.title": "Agent Browser","tools.builtins.lobe-agent-builder.description": "Configure agent metadata, model settings, plugins, and the system prompt","tools.builtins.lobe-agent-builder.title": "Agent Builder",- "tools.builtins.lobe-agent-documents.description": "Manage agent-scoped documents (list, create, read, edit, remove, rename) and load rules",+ "tools.builtins.lobe-agent-documents.description": "Manage agent-scoped documents (list, create, read, edit, remove, rename) and load rules. Not for your uploaded files — see Knowledge Base for those.","tools.builtins.lobe-agent-documents.title": "Documents","tools.builtins.lobe-agent-management.description": "Create, manage, and orchestrate AI agents","tools.builtins.lobe-agent-management.title": "Agent Management",@@ -1480,7 +1480,7 @@"tools.builtins.lobe-image-generation.description": "Generate images through LobeHub providers when the current chat model has no native image output.","tools.builtins.lobe-image-generation.readme": "Opt-in image generation for models without native image output. Pin this tool to enable it in chat or agent mode; leave unpinned to avoid the tool schema cost.","tools.builtins.lobe-image-generation.title": "Image Generation",- "tools.builtins.lobe-knowledge-base.description": "Search uploaded documents and domain knowledge via semantic vector search — for persistent, reusable reference",+ "tools.builtins.lobe-knowledge-base.description": "Find, browse, and read your uploaded files, and search organized knowledge bases via semantic vector search","tools.builtins.lobe-knowledge-base.title": "Knowledge Base","tools.builtins.lobe-local-system.description": "Access and manage local files, run shell commands on your desktop","tools.builtins.lobe-local-system.readme": "Access your local filesystem on desktop. Read, write, search, and organize files. Execute shell commands with background task support and grep content with regex patterns.",diff --git a/locales/zh-CN/setting.json b/locales/zh-CN/setting.jsonindex 2cd1d085170..a19770b9b2d 100644--- a/locales/zh-CN/setting.json+++ b/locales/zh-CN/setting.json@@ -1454,7 +1454,7 @@"tools.builtins.lobe-agent-browser.title": "助手浏览器","tools.builtins.lobe-agent-builder.description": "配置助手元信息、模型设置、插件以及系统提示词","tools.builtins.lobe-agent-builder.title": "助手构建器",- "tools.builtins.lobe-agent-documents.description": "管理助手范围内的文档(列出、创建、读取、编辑、删除、重命名)并加载规则",+ "tools.builtins.lobe-agent-documents.description": "管理助手范围内的文档(列出、创建、读取、编辑、删除、重命名)并加载规则。不适用于您上传的文件——请使用「知识库」工具。","tools.builtins.lobe-agent-documents.title": "文档","tools.builtins.lobe-agent-management.description": "创建、管理并编排 AI 助手","tools.builtins.lobe-agent-management.title": "助手管理",@@ -1480,7 +1480,7 @@"tools.builtins.lobe-image-generation.description": "在当前对话模型没有原生出图能力时,通过 LobeHub 的图片生成通道生成图片。","tools.builtins.lobe-image-generation.readme": "可选的图片生成能力,适用于没有原生出图的模型。固定(Pin)后可在对话/Agent 模式使用;不固定则不注入工具 schema,避免额外 token 消耗。","tools.builtins.lobe-image-generation.title": "图片生成",- "tools.builtins.lobe-knowledge-base.description": "通过语义向量检索搜索已上传的文档与领域知识 — 适用于持久、可复用的参考资料",+ "tools.builtins.lobe-knowledge-base.description": "查找、浏览并读取您上传的文件,并通过语义向量检索搜索已整理的知识库","tools.builtins.lobe-knowledge-base.title": "知识库","tools.builtins.lobe-local-system.description": "访问和管理本地文件,在桌面端运行 Shell 命令","tools.builtins.lobe-local-system.readme": "访问桌面端的本地文件系统。读取、写入、搜索和组织文件。执行 Shell 命令,支持后台任务和正则内容搜索。",diff --git a/packages/builtin-tool-agent-documents/src/manifest.ts b/packages/builtin-tool-agent-documents/src/manifest.tsindex a6bae7598b0..03f46924e05 100644--- a/packages/builtin-tool-agent-documents/src/manifest.ts+++ b/packages/builtin-tool-agent-documents/src/manifest.ts@@ -226,7 +226,7 @@ export const AgentDocumentsManifest: BuiltinToolManifest = {},{description:- 'List agent documents. Use this to discover documents that are not auto-injected (e.g. web-crawled pages), to expand a folder collapsed in the agent_documents_index, or to resolve a title to a document ID.',+ "List agent documents (this agent's own notes/skills/structured docs). Use this to discover documents that are not auto-injected (e.g. web-crawled pages), to expand a folder collapsed in the agent_documents_index, or to resolve a title to a document ID. Do NOT use this to find the user's uploaded files (PDFs, images, general uploads) — those live in the resource library and are covered by the Knowledge Base tool's listFiles, not here.",name: AgentDocumentsApiName.listDocuments,parameters: {properties: {@@ -244,8 +244,7 @@ export const AgentDocumentsManifest: BuiltinToolManifest = {},sourceType: {default: 'all',- description:- 'Filter by document source. "file" = user-created or uploaded; "web" = crawled from external URLs; "all" returns both. Web-crawled documents are hidden from the default agent_documents_index — pass sourceType="web" here to see them.',+ description: `Filter by document source within this agent-document system (unrelated to the user's resource library uploads). "file" = documents authored/edited directly as agent documents; "web" = crawled from external URLs; "all" returns both. Web-crawled documents are hidden from the default agent_documents_index — pass sourceType="web" here to see them.`,enum: ['all', 'file', 'web'],type: 'string',},@@ -290,7 +289,7 @@ export const AgentDocumentsManifest: BuiltinToolManifest = {meta: {avatar: '🗂️',description:- 'Manage agent-scoped documents (list/create/read/edit/remove/rename/copy/upsert) and load rules',+ "Manage agent-scoped documents (list/create/read/edit/remove/rename/copy/upsert) and load rules. Not for the user's uploaded files — use the Knowledge Base tool for those.",title: 'Documents',},systemRole: systemPrompt,diff --git a/packages/builtin-tool-agent-documents/src/systemRole.test.ts b/packages/builtin-tool-agent-documents/src/systemRole.test.tsindex 34427373e33..415eee6d065 100644--- a/packages/builtin-tool-agent-documents/src/systemRole.test.ts+++ b/packages/builtin-tool-agent-documents/src/systemRole.test.ts@@ -9,4 +9,17 @@ describe('systemPrompt', () => {"For folder navigation, pass the folder's `documentId` (or the ID shown in a collapsed folder row) as `listDocuments.parentId`.",);});++ it("should route the user's uploaded files to the Knowledge Base tool when it is available", () => {+ expect(systemPrompt).toContain(+ 'If the Knowledge Base tool is available in this conversation, use its listFiles/readKnowledge instead — do not treat listDocuments results as a match for an uploaded file.',+ );+ });++ it('should not dead-end when the Knowledge Base tool is unavailable', () => {+ expect(systemPrompt).toContain(+ "If the Knowledge Base tool is not available, listDocuments still cannot see the user's uploaded files",+ );+ expect(systemPrompt).toContain('do not simply refuse');+ });});diff --git a/packages/builtin-tool-agent-documents/src/systemRole.ts b/packages/builtin-tool-agent-documents/src/systemRole.tsindex d64697c3c22..c795e640680 100644--- a/packages/builtin-tool-agent-documents/src/systemRole.ts+++ b/packages/builtin-tool-agent-documents/src/systemRole.ts@@ -1,5 +1,11 @@export const systemPrompt = `You have access to an Agent Documents tool for creating and managing agent-scoped documents.+<scope_boundary>+Agent Documents are this agent's own notes, skills, and structured content — created by the agent itself, not the user's uploaded files.+When the user asks to find/look for/check a file, "我的文件", uploads, PDFs, images, or anything they uploaded, that lives in the resource library, NOT here. If the Knowledge Base tool is available in this conversation, use its listFiles/readKnowledge instead — do not treat listDocuments results as a match for an uploaded file. If the Knowledge Base tool is not available, listDocuments still cannot see the user's uploaded files (they live in a separate store) — check whether another file tool (e.g. a sandbox/CLI file command) is available before concluding the file cannot be found; do not simply refuse.+Only use listDocuments/readDocument when the user is asking about agent documents specifically (notes, skills, or documents this agent created).+</scope_boundary>+<core_capabilities>1. Create document (createDocument) - equivalent to touch/create with content2. Read document (readDocument) - equivalent to cat/read; only one read entry, by document IDdiff --git a/packages/builtin-tool-knowledge-base/src/manifest.ts b/packages/builtin-tool-knowledge-base/src/manifest.tsindex 1d32a54ef31..ff2cd9fcd9c 100644--- a/packages/builtin-tool-knowledge-base/src/manifest.ts+++ b/packages/builtin-tool-knowledge-base/src/manifest.ts@@ -245,7 +245,7 @@ export const KnowledgeBaseManifest: BuiltinToolManifest = {meta: {avatar: '📚',description:- 'Search uploaded documents and domain knowledge via semantic vector search — for persistent, reusable reference',+ "Find, browse, and read the user's uploaded files (resource library), and search organized knowledge bases via semantic vector search — the tool for any request about the user's own files or uploads",title: 'Knowledge Base',},systemRole: systemPrompt,diff --git a/packages/builtin-tool-knowledge-base/src/systemRole.test.ts b/packages/builtin-tool-knowledge-base/src/systemRole.test.tsnew file mode 100644index 00000000000..344e910328b--- /dev/null+++ b/packages/builtin-tool-knowledge-base/src/systemRole.test.ts@@ -0,0 +1,30 @@+import { describe, expect, it } from 'vitest';++import { systemPrompt } from './systemRole';++describe('systemPrompt', () => {+ it("should route the user's uploaded files here instead of Agent Documents", () => {+ expect(systemPrompt).toContain(+ 'this Knowledge Base tool is the correct tool, not Agent Documents',+ );+ });++ it('should mandate listFiles before readKnowledge as the primary path for file requests', () => {+ expect(systemPrompt).toContain('Always use listFiles first');+ expect(systemPrompt).toContain(+ 'it works regardless of whether the file has been organized into a knowledge base, and does not require the file to be pre-indexed',+ );+ });++ it('should scope searchKnowledgeBase to organized knowledge bases only, excluding the resource library', () => {+ expect(systemPrompt).toContain(+ 'searchKnowledgeBase only covers files already organized into a knowledge base, not the general resource library',+ );+ });++ it('should order sandbox/CLI file listing as a last resort after listFiles and searchKnowledgeBase', () => {+ expect(systemPrompt).toContain(+ 'Treat any sandbox/CLI file-listing command as a last-resort fallback only, after both listFiles and searchKnowledgeBase have been tried.',+ );+ });+});diff --git a/packages/builtin-tool-knowledge-base/src/systemRole.ts b/packages/builtin-tool-knowledge-base/src/systemRole.tsindex 70274b74bc4..a8749a37df3 100644--- a/packages/builtin-tool-knowledge-base/src/systemRole.ts+++ b/packages/builtin-tool-knowledge-base/src/systemRole.ts@@ -3,9 +3,11 @@ export const systemPrompt = `You have access to a Knowledge Base tool with compr<important_file_behavior>**Most user files live in the resource library, NOT in knowledge bases.**When a user uploads files (images, PDFs, documents, etc.), they go into the resource library by default. Most users never manually organize files into knowledge bases. Therefore:-- When the user says "find my file", "look for that PDF", "check my uploads", "我的文件", or references ANY file — **always use listFiles first**.-- Only use listKnowledgeBases / searchKnowledgeBase when the user explicitly mentions "knowledge base", "知识库", or wants semantic search over organized collections.-- If listFiles doesn't find the file, then fall back to searching knowledge bases.+- When the user says "find my file", "look for that PDF", "check my uploads", "我的文件", or references ANY file they own — **this Knowledge Base tool is the correct tool, not Agent Documents.** Agent Documents only manages the agent's own notes/skills, not the user's uploads.+- **Always use listFiles first**, then readKnowledge to get its content if needed. This alone covers most "find/read my file" requests — it works regardless of whether the file has been organized into a knowledge base, and does not require the file to be pre-indexed.+- Only use listKnowledgeBases / searchKnowledgeBase when the user explicitly mentions "knowledge base", "知识库", wants semantic search over organized collections, or when the user doesn't know the filename and wants a topic/content search — note searchKnowledgeBase only covers files already organized into a knowledge base, not the general resource library.+- If listFiles doesn't find the file by name, then fall back to searching knowledge bases via searchKnowledgeBase.+- Treat any sandbox/CLI file-listing command as a last-resort fallback only, after both listFiles and searchKnowledgeBase have been tried.</important_file_behavior><core_capabilities>diff --git a/packages/builtin-tool-knowledge-base/vitest.config.mts b/packages/builtin-tool-knowledge-base/vitest.config.mtsnew file mode 100644index 00000000000..52f86e133c7--- /dev/null+++ b/packages/builtin-tool-knowledge-base/vitest.config.mts@@ -0,0 +1,11 @@+import { defineConfig } from 'vitest/config';++export default defineConfig({+ test: {+ coverage: {+ provider: 'v8',+ reporter: ['text', 'json', 'lcov', 'text-summary'],+ },+ environment: 'node',+ },+});diff --git a/packages/locales/src/default/setting.ts b/packages/locales/src/default/setting.tsindex 0ec1836116a..83907115b8a 100644--- a/packages/locales/src/default/setting.ts+++ b/packages/locales/src/default/setting.ts@@ -3383,7 +3383,7 @@ When I am ___, I need ___'Configure agent metadata, model settings, plugins, and the system prompt','tools.builtins.lobe-agent-builder.title': 'Agent Builder','tools.builtins.lobe-agent-documents.description':- 'Manage agent-scoped documents (list, create, read, edit, remove, rename) and load rules',+ 'Manage agent-scoped documents (list, create, read, edit, remove, rename) and load rules. Not for your uploaded files — see Knowledge Base for those.','tools.builtins.lobe-agent-documents.title': 'Documents','tools.builtins.lobe-agent-management.description': 'Create, manage, and orchestrate AI agents','tools.builtins.lobe-agent-management.title': 'Agent Management',@@ -3403,7 +3403,7 @@ When I am ___, I need ___'Orchestrate and manage multi-agent group conversations','tools.builtins.lobe-group-management.title': 'Group Management','tools.builtins.lobe-knowledge-base.description':- 'Search uploaded documents and domain knowledge via semantic vector search — for persistent, reusable reference',+ 'Find, browse, and read your uploaded files, and search organized knowledge bases via semantic vector search','tools.builtins.lobe-knowledge-base.title': 'Knowledge Base','tools.builtins.lobe-message.description':'Send, read, edit, and manage messages across multiple messaging platforms with a unified interface',