π€― 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
β¨ feat: agent-documents index β hide web crawls + new table format (#14292)
Arvin Xu73fa3b16892d
diff --git a/packages/builtin-tool-agent-documents/src/ExecutionRuntime/index.ts b/packages/builtin-tool-agent-documents/src/ExecutionRuntime/index.tsindex b975be59b90..75ca81e26cf 100644--- a/packages/builtin-tool-agent-documents/src/ExecutionRuntime/index.ts+++ b/packages/builtin-tool-agent-documents/src/ExecutionRuntime/index.ts@@ -221,9 +221,10 @@ export class AgentDocumentsExecutionRuntime {};}- const target = args.target ?? 'agent';+ const scope = args.scope ?? 'agent';+ const sourceType = args.sourceType ?? 'all';const topicId = this.resolveTopicId(context);- if (target === 'currentTopic' && !topicId) {+ if (scope === 'currentTopic' && !topicId) {return {content: 'Cannot list current topic documents without topicId context.',success: false,@@ -231,9 +232,9 @@ export class AgentDocumentsExecutionRuntime {}const docs =- target === 'currentTopic'- ? await this.service.listTopicDocuments({ agentId, target, topicId: topicId! })- : await this.service.listDocuments({ agentId, target });+ scope === 'currentTopic'+ ? await this.service.listTopicDocuments({ agentId, scope, sourceType, topicId: topicId! })+ : await this.service.listDocuments({ agentId, scope, sourceType });const list = docs.map((d) => ({...(d.documentId ? { documentId: d.documentId } : {}),filename: d.filename ?? d.title ?? '',@@ -260,9 +261,9 @@ export class AgentDocumentsExecutionRuntime {};}- const target = args.target ?? 'agent';+ const scope = args.scope ?? 'agent';const topicId = this.resolveTopicId(context);- if (target === 'currentTopic' && !topicId) {+ if (scope === 'currentTopic' && !topicId) {return {content: 'Cannot create current topic document without topicId context.',success: false,@@ -271,7 +272,7 @@ export class AgentDocumentsExecutionRuntime {const toolTriggerInput = this.buildToolTriggerInput(context);const created =- target === 'currentTopic'+ scope === 'currentTopic'? await this.service.createTopicDocument({...args,...toolTriggerInput,diff --git a/packages/builtin-tool-agent-documents/src/client/Inspector/CreateDocument/index.tsx b/packages/builtin-tool-agent-documents/src/client/Inspector/CreateDocument/index.tsxindex c019b0c8a28..2130881b443 100644--- a/packages/builtin-tool-agent-documents/src/client/Inspector/CreateDocument/index.tsx+++ b/packages/builtin-tool-agent-documents/src/client/Inspector/CreateDocument/index.tsx@@ -16,7 +16,7 @@ export const CreateDocumentInspector = memo<const { t } = useTranslation('plugin');const title = args?.title || partialArgs?.title;- const target = args?.target || partialArgs?.target;+ const scope = args?.scope || partialArgs?.scope;const styles = inspectorChipStyles;if (isArgumentsStreaming && !title) {@@ -37,11 +37,11 @@ export const CreateDocumentInspector = memo<><span>{t('builtins.lobe-agent-documents.apiName.createDocument')}</span>{title && <span className={styles.chip}>{title}</span>}- {target && (+ {scope && (<><span className={styles.separator}>Β·</span><span className={styles.subdued}>- {t(`builtins.lobe-agent-documents.inspector.target.${target}` as const)}+ {t(`builtins.lobe-agent-documents.inspector.scope.${scope}` as const)}</span></>)}diff --git a/packages/builtin-tool-agent-documents/src/client/Inspector/ListDocuments/index.tsx b/packages/builtin-tool-agent-documents/src/client/Inspector/ListDocuments/index.tsxindex a968e665105..b4aeecb7aea 100644--- a/packages/builtin-tool-agent-documents/src/client/Inspector/ListDocuments/index.tsx+++ b/packages/builtin-tool-agent-documents/src/client/Inspector/ListDocuments/index.tsx@@ -15,7 +15,7 @@ export const ListDocumentsInspector = memo<>(({ args, partialArgs, pluginState, isArgumentsStreaming, isLoading }) => {const { t } = useTranslation('plugin');- const target = args?.target || partialArgs?.target;+ const scope = args?.scope || partialArgs?.scope;const count = pluginState?.documents?.length;const styles = inspectorChipStyles;@@ -28,11 +28,11 @@ export const ListDocumentsInspector = memo<)}><span>{t('builtins.lobe-agent-documents.apiName.listDocuments')}</span>- {target && (+ {scope && (<><span className={styles.separator}>Β·</span><span className={styles.subdued}>- {t(`builtins.lobe-agent-documents.inspector.target.${target}` as const)}+ {t(`builtins.lobe-agent-documents.inspector.scope.${scope}` as const)}</span></>)}diff --git a/packages/builtin-tool-agent-documents/src/manifest.ts b/packages/builtin-tool-agent-documents/src/manifest.tsindex 0238a1453f5..f8c6688996d 100644--- a/packages/builtin-tool-agent-documents/src/manifest.ts+++ b/packages/builtin-tool-agent-documents/src/manifest.ts@@ -21,7 +21,7 @@ export const AgentDocumentsManifest: BuiltinToolManifest = {'Set true only when the document captures reusable procedural knowledge or durable agent behavior.',type: 'boolean',},- target: {+ scope: {default: 'agent',description:'Where to create the document. Use currentTopic to associate it with the current topic; defaults to agent-scoped documents.',@@ -194,17 +194,24 @@ export const AgentDocumentsManifest: BuiltinToolManifest = {},{description:- 'List agent documents. Defaults to all agent documents; use target=currentTopic to list documents associated with the current topic.',+ 'List agent documents. Use this to discover documents that are not auto-injected (e.g. web-crawled pages) or to resolve a title to a document ID.',name: AgentDocumentsApiName.listDocuments,parameters: {properties: {- target: {+ scope: {default: 'agent',description:- 'Which document set to list. currentTopic filters to documents associated with the current topic.',+ 'Which document set to list. Defaults to "agent" (all agent-scoped documents). Use "currentTopic" to filter to documents associated with the current topic.',enum: ['agent', 'currentTopic'],type: 'string',},+ 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.',+ enum: ['all', 'file', 'web'],+ type: 'string',+ },},required: [],type: 'object',diff --git a/packages/builtin-tool-agent-documents/src/systemRole.ts b/packages/builtin-tool-agent-documents/src/systemRole.tsindex f14a64477a3..c6660a67525 100644--- a/packages/builtin-tool-agent-documents/src/systemRole.ts+++ b/packages/builtin-tool-agent-documents/src/systemRole.ts@@ -21,10 +21,10 @@ export const systemPrompt = `You have access to an Agent Documents tool for crea<tool_selection_guidelines>- By default, if the user does not explicitly specify otherwise, and the relevant Agent Documents tool is available for the task, prefer Agent Documents over Cloud Sandbox because it is easier for collaboration and multi-agent coordination.-- **createDocument**: create a new document with title + content. Use target="currentTopic" only when the user asks to create a document in the current topic; otherwise omit target for an agent-scoped document.+- **createDocument**: create a new document with title + content. Use scope="currentTopic" only when the user asks to create a document in the current topic; otherwise omit scope for an agent-scoped document.- Set hintIsSkill=true only when creating a document that contains reusable procedural knowledge, workflow instructions, tool usage guidance, or durable agent behavior. Leave ordinary notes unhinted.- Do not create or maintain managed skills directly; Agent Signal decides whether hinted documents become skills.-- **listDocuments**: list agent documents. Use target="currentTopic" when the user asks about documents in the current topic. Use this to resolve a filename to a document ID before reading.+- **listDocuments**: list agent documents. Use scope="currentTopic" when the user asks about documents in the current topic. The default agent_documents_index hides web-crawled documents; pass sourceType="web" here to enumerate them, or sourceType="all" to see everything. Use this to resolve a title to a document ID before reading.- **readDocument**: retrieve current content by document ID. This is the only way to read an agent document β there is no read-by-filename variant. Prefer format="xml" when you may edit content, because XML includes stable node IDs. If the response contains empty content, the document is genuinely empty; do not retry with a different format or filename.- **modifyNodes**: preferred content-edit API. Use LiteXML insert/modify/remove operations after reading XML. For modify operations, include the existing node ID in the LiteXML.- **replaceDocumentContent**: overwrite the full content of an existing document only when replacing most or all content.diff --git a/packages/builtin-tool-agent-documents/src/types.ts b/packages/builtin-tool-agent-documents/src/types.tsindex c6c46143d91..b1fba0ee1f7 100644--- a/packages/builtin-tool-agent-documents/src/types.ts+++ b/packages/builtin-tool-agent-documents/src/types.ts@@ -15,7 +15,7 @@ export const AgentDocumentsApiName = {export interface CreateDocumentArgs {content: string;hintIsSkill?: boolean;- target?: 'agent' | 'currentTopic';+ scope?: 'agent' | 'currentTopic';title: string;}@@ -154,7 +154,8 @@ export interface AgentDocumentReference {}export interface ListDocumentsArgs {- target?: 'agent' | 'currentTopic';+ scope?: 'agent' | 'currentTopic';+ sourceType?: 'all' | 'file' | 'web';}export interface ListDocumentsState {diff --git a/packages/builtin-tool-local-system/src/systemRole.desktop.ts b/packages/builtin-tool-local-system/src/systemRole.desktop.tsindex dd4f2ecc6ba..9e4d3bb3f09 100644--- a/packages/builtin-tool-local-system/src/systemRole.desktop.ts+++ b/packages/builtin-tool-local-system/src/systemRole.desktop.ts@@ -86,7 +86,7 @@ You have access to a set of tools to interact with the user's local file system:- 'command': The shell command to execute.- 'description' (Optional but recommended): A clear, concise description of what the command does (5-10 words, in active voice). **IMPORTANT: Always use the same language as the user's input.** If the user speaks Chinese, write the description in Chinese; if English, use English, etc.- 'run_in_background' (Optional): Set to true to run in background and get a shell_id for later checking output.- - 'timeout' (Optional): Timeout in milliseconds (default: 120000ms, max: 600000ms).+ - 'timeout' (Optional): Timeout in milliseconds (default: 120000ms, max: 800000ms).The command runs in cmd.exe on Windows or /bin/sh on macOS/Linux.- For retrieving output from background commands: Use 'getCommandOutput'. Provide:- 'shell_id': The ID returned from runCommand when run_in_background was true.diff --git a/packages/builtin-tool-local-system/src/systemRole.ts b/packages/builtin-tool-local-system/src/systemRole.tsindex 5cb83819dad..79e1ef3cee7 100644--- a/packages/builtin-tool-local-system/src/systemRole.ts+++ b/packages/builtin-tool-local-system/src/systemRole.ts@@ -75,7 +75,7 @@ You have access to a set of tools to interact with the user's local file system:- 'command': The shell command to execute.- 'description' (Optional but recommended): A clear, concise description of what the command does (5-10 words, in active voice). **IMPORTANT: Always use the same language as the user's input.** If the user speaks Chinese, write the description in Chinese; if English, use English, etc.- 'run_in_background' (Optional): Set to true to run in background and get a shell_id for later checking output.- - 'timeout' (Optional): Timeout in milliseconds (default: 120000ms, max: 600000ms).+ - 'timeout' (Optional): Timeout in milliseconds (default: 120000ms, max: 800000ms).The command runs in cmd.exe on Windows or /bin/sh on macOS/Linux.- For retrieving output from background commands: Use 'getCommandOutput'. Provide:- 'shell_id': The ID returned from runCommand when run_in_background was true.diff --git a/packages/context-engine/src/engine/messages/__tests__/MessagesEngine.test.ts b/packages/context-engine/src/engine/messages/__tests__/MessagesEngine.test.tsindex 1f19d7ae642..71e68018355 100644--- a/packages/context-engine/src/engine/messages/__tests__/MessagesEngine.test.ts+++ b/packages/context-engine/src/engine/messages/__tests__/MessagesEngine.test.ts@@ -591,7 +591,7 @@ Document content here.expect(userMessage?.content).toContain('<active_topic_document>');expect(userMessage?.content).toContain('document_id="docs_123"');expect(userMessage?.content).toContain('agent_document_id="agd_123"');- expect(userMessage?.content).toContain('target="currentTopic"');+ expect(userMessage?.content).toContain('scope="currentTopic"');expect(userMessage?.content).toContain('Do not use PageAgent editor tools');expect(result.metadata.activeTopicDocumentContextInjected).toBe(true);});diff --git a/packages/context-engine/src/providers/ActiveTopicDocumentContextInjector.ts b/packages/context-engine/src/providers/ActiveTopicDocumentContextInjector.tsindex 072d1157fb7..a4e90b8c487 100644--- a/packages/context-engine/src/providers/ActiveTopicDocumentContextInjector.ts+++ b/packages/context-engine/src/providers/ActiveTopicDocumentContextInjector.ts@@ -34,7 +34,7 @@ const formatActiveTopicDocumentContext = (document: RuntimeActiveTopicDocumentCoThe current conversation is not inside the page editor. Do not use PageAgent editor tools.When the user asks to continue editing this topic document, use lobe-agent-documents tools instead.Prefer readDocument with format="xml" and modifyNodes with agent_document_id when it is present.-If agent_document_id is missing, call listDocuments with target="currentTopic" and match document_id.+If agent_document_id is missing, call listDocuments with scope="currentTopic" and match document_id.</guidance>`;};diff --git a/packages/context-engine/src/providers/AgentDocumentInjector/shared.ts b/packages/context-engine/src/providers/AgentDocumentInjector/shared.tsindex 51a3b95f23f..8c979ef3fc6 100644--- a/packages/context-engine/src/providers/AgentDocumentInjector/shared.ts+++ b/packages/context-engine/src/providers/AgentDocumentInjector/shared.ts@@ -21,6 +21,8 @@ export type AgentDocumentInjectionPosition = (typeof AGENT_DOCUMENT_INJECTION_POexport type AgentDocumentLoadFormat = 'file' | 'raw';+export type AgentDocumentSourceType = 'agent' | 'agent-signal' | 'api' | 'file' | 'topic' | 'web';+export interface AgentContextDocument {content?: string;description?: string;@@ -31,7 +33,9 @@ export interface AgentContextDocument {policyId?: string | null;policyLoad?: 'always' | 'progressive';policyLoadFormat?: AgentDocumentLoadFormat;+ sourceType?: AgentDocumentSourceType;title?: string;+ updatedAt?: Date | string;}export interface AgentDocumentFilterContext {@@ -106,20 +110,112 @@ export function formatDocument(}/**- * Format a single progressive document as an index entry+ * Format the size of a document content as a short human-readable token string.+ * Empty content is rendered as "empty" so the LLM does not retry reading it.*/-function formatProgressiveEntry(doc: AgentContextDocument): string {- const parts: string[] = [];- if (doc.id) parts.push(`[${doc.id}]`);- parts.push(doc.filename);- if (doc.title && doc.title !== doc.filename) parts.push(`β "${doc.title}"`);- if (doc.description) parts.push(`: ${doc.description}`);- return `- ${parts.join(' ')}`;+function formatSize(content: string | undefined): string {+ const len = content?.length ?? 0;+ if (len === 0) return 'empty';+ if (len < 1000) return String(len);+ if (len < 10_000) return `${(len / 1000).toFixed(1)}k`;+ if (len < 1_000_000) return `${Math.round(len / 1000)}k`;+ return `${(len / 1_000_000).toFixed(1)}M`;+}++/**+ * Render a Date / ISO string as a short relative-time token like "2d ago".+ */+function formatRelative(at: Date | string | undefined, now: Date): string {+ if (!at) return 'β';+ const date = typeof at === 'string' ? new Date(at) : at;+ if (Number.isNaN(date.getTime())) return 'β';++ const sec = Math.max(0, Math.floor((now.getTime() - date.getTime()) / 1000));+ if (sec < 60) return 'now';+ const min = Math.floor(sec / 60);+ if (min < 60) return `${min}m ago`;+ const hr = Math.floor(min / 60);+ if (hr < 24) return `${hr}h ago`;+ const day = Math.floor(hr / 24);+ if (day < 30) return `${day}d ago`;+ const month = Math.floor(day / 30);+ if (month < 12) return `${month}mo ago`;+ const year = Math.floor(day / 365);+ return `${year}y ago`;+}++const TITLE_MAX_WIDTH = 60;++function pickRowTitle(doc: AgentContextDocument): string {+ return doc.title || doc.filename || '(untitled)';+}++function truncate(s: string, max: number): string {+ return s.length > max ? `${s.slice(0, max - 1)}β¦` : s;+}++/**+ * Render a list of progressive docs as a fixed-width table:+ *+ * TITLE ID SIZE UPDATED+ * daily-brief.txt 2af6eb88-8bdb-468f-887f-620baa394efa 1.4k 2d ago+ */+function buildIndexTable(+ docs: AgentContextDocument[],+ context: AgentDocumentFilterContext,+): string {+ const now = context.currentTime ?? new Date();+ const rows = docs.map((d) => ({+ id: d.id ?? '',+ size: formatSize(d.content),+ title: truncate(pickRowTitle(d), TITLE_MAX_WIDTH),+ updated: formatRelative(d.updatedAt, now),+ }));++ const titleWidth = Math.max('TITLE'.length, ...rows.map((r) => r.title.length));+ const idWidth = Math.max('ID'.length, ...rows.map((r) => r.id.length));+ const sizeWidth = Math.max('SIZE'.length, ...rows.map((r) => r.size.length));++ const sep = ' ';+ const headerLine = [+ 'TITLE'.padEnd(titleWidth),+ 'ID'.padEnd(idWidth),+ 'SIZE'.padEnd(sizeWidth),+ 'UPDATED',+ ].join(sep);++ const dataLines = rows.map((row) =>+ [+ row.title.padEnd(titleWidth),+ row.id.padEnd(idWidth),+ row.size.padEnd(sizeWidth),+ row.updated,+ ].join(sep),+ );++ return [headerLine, ...dataLines].join('\n');+}++/**+ * Sort documents by recency (most-recently-updated first); rows missing+ * `updatedAt` sink to the end and keep stable input order between themselves.+ */+function sortByRecency(docs: AgentContextDocument[]): AgentContextDocument[] {+ return [...docs]+ .map((doc, index) => ({ doc, index }))+ .sort((a, b) => {+ const ta = a.doc.updatedAt ? new Date(a.doc.updatedAt).getTime() : 0;+ const tb = b.doc.updatedAt ? new Date(b.doc.updatedAt).getTime() : 0;+ if (tb !== ta) return tb - ta;+ return a.index - b.index;+ })+ .map(({ doc }) => doc);}/*** Combine multiple documents into a single string.- * Progressive documents are grouped into a lightweight index block;+ * Progressive documents are grouped into an `<agent_documents_index>` block+ * (web-crawled docs are hidden behind a count and surfaced via listDocuments);* full-content documents are formatted individually.*/export function combineDocuments(@@ -136,9 +232,22 @@ export function combineDocuments(}if (progressiveDocs.length > 0) {- const entries = progressiveDocs.map(formatProgressiveEntry).join('\n');+ const userDocs = sortByRecency(progressiveDocs.filter((d) => d.sourceType !== 'web'));+ const hiddenWebCount = progressiveDocs.length - userDocs.length;++ const headerLines: string[] = [+ `${userDocs.length} user-created doc${userDocs.length === 1 ? '' : 's'}. Use readDocument(id) for full content.`,+ ];+ if (hiddenWebCount > 0) {+ headerLines.push(+ `${hiddenWebCount} web-crawled doc${hiddenWebCount === 1 ? '' : 's'} hidden β call listDocuments(sourceType='web') to see them.`,+ );+ }++ const tableBlock = userDocs.length > 0 ? `\n\n${buildIndexTable(userDocs, context)}` : '';+parts.push(- `<agent_documents_index>\nThe following documents are available. Use readDocument tool to access full content.\n${entries}\n</agent_documents_index>`,+ `<agent_documents_index>\n${headerLines.join('\n')}${tableBlock}\n</agent_documents_index>`,);}diff --git a/packages/context-engine/src/providers/__tests__/AgentDocumentInjector.test.ts b/packages/context-engine/src/providers/__tests__/AgentDocumentInjector.test.tsindex 3f76b8cf25f..5cd8fbc8aba 100644--- a/packages/context-engine/src/providers/__tests__/AgentDocumentInjector.test.ts+++ b/packages/context-engine/src/providers/__tests__/AgentDocumentInjector.test.ts@@ -176,25 +176,29 @@ describe('AgentDocumentInjector', () => {it('should inject progressive documents as index instead of full content', async () => {const provider = new AgentDocumentContextInjector({+ currentTime: new Date('2026-04-29T00:00:00.000Z'),documents: [{content: 'Full content that should NOT appear',- description: 'Core safety rules',- filename: 'guardrails.md',- id: 'doc-1',+ filename: 'daily-brief.txt',+ id: '2af6eb88-8bdb-468f-887f-620baa394efa',loadPosition: 'before-first-user',loadRules: { rule: 'always' },policyLoad: 'progressive',- title: 'Guardrails',+ sourceType: 'file',+ title: 'Daily Brief ζεζ‘ζΆ',+ updatedAt: new Date('2026-04-27T00:00:00.000Z'),},{- content: 'Another full content that should NOT appear',- filename: 'notes.txt',- id: 'doc-2',+ content: 'a'.repeat(6000),+ filename: 'cfg.txt',+ id: '32e12975-7db2-4818-8415-9b5c3d383f05',loadPosition: 'before-first-user',loadRules: { rule: 'always' },policyLoad: 'progressive',- title: 'Notes',+ sourceType: 'file',+ title: 'cfg-constrained-decoding',+ updatedAt: new Date('2026-04-10T00:00:00.000Z'),},],});@@ -202,21 +206,106 @@ describe('AgentDocumentInjector', () => {const context = createContext([{ content: 'Hello', id: 'user-1', role: 'user' }]);const result = await provider.process(context);- const injected = result.messages[0].content;- expect(injected).toContain('<agent_documents_index>');- expect(injected).toContain('[doc-1]');- expect(injected).toContain('guardrails.md');- expect(injected).toContain('"Guardrails"');- expect(injected).toContain('Core safety rules');- expect(injected).toContain('[doc-2]');- expect(injected).toContain('notes.txt');- expect(injected).not.toContain('Full content that should NOT appear');- expect(injected).not.toContain('Another full content that should NOT appear');- expect(injected).toContain('</agent_documents_index>');+ expect(result.messages[0].content).toMatchInlineSnapshot(`+ "<agent_documents_index>+ 2 user-created docs. Use readDocument(id) for full content.++ TITLE ID SIZE UPDATED+ Daily Brief ζεζ‘ζΆ 2af6eb88-8bdb-468f-887f-620baa394efa 35 2d ago+ cfg-constrained-decoding 32e12975-7db2-4818-8415-9b5c3d383f05 6.0k 19d ago+ </agent_documents_index>"+ `);+ expect(result.messages[0].content).not.toContain('Full content that should NOT appear');+ });++ it('should hide web-crawled docs from the index and surface the count', async () => {+ const provider = new AgentDocumentContextInjector({+ currentTime: new Date('2026-04-29T00:00:00.000Z'),+ documents: [+ {+ content: 'user note',+ filename: 'daily-brief.txt',+ id: '2af6eb88-8bdb-468f-887f-620baa394efa',+ loadPosition: 'before-first-user',+ loadRules: { rule: 'always' },+ policyLoad: 'progressive',+ sourceType: 'file',+ title: 'Daily Brief',+ updatedAt: new Date('2026-04-27T00:00:00.000Z'),+ },+ {+ content: 'gold price page',+ filename: 'gold-price-1.html',+ id: 'web-1',+ loadPosition: 'before-first-user',+ loadRules: { rule: 'always' },+ policyLoad: 'progressive',+ sourceType: 'web',+ title: 'Gold price',+ },+ {+ content: 'gold news',+ filename: 'gold-news.html',+ id: 'web-2',+ loadPosition: 'before-first-user',+ loadRules: { rule: 'always' },+ policyLoad: 'progressive',+ sourceType: 'web',+ title: 'Gold news',+ },+ ],+ });++ const context = createContext([{ content: 'Hello', id: 'user-1', role: 'user' }]);+ const result = await provider.process(context);++ expect(result.messages[0].content).toMatchInlineSnapshot(`+ "<agent_documents_index>+ 1 user-created doc. Use readDocument(id) for full content.+ 2 web-crawled docs hidden β call listDocuments(sourceType='web') to see them.++ TITLE ID SIZE UPDATED+ Daily Brief 2af6eb88-8bdb-468f-887f-620baa394efa 9 2d ago+ </agent_documents_index>"+ `);+ expect(result.messages[0].content).not.toContain('Gold price');+ expect(result.messages[0].content).not.toContain('Gold news');+ });++ it('should render empty docs with size=empty so the LLM does not retry', async () => {+ const provider = new AgentDocumentContextInjector({+ currentTime: new Date('2026-04-29T00:00:00.000Z'),+ documents: [+ {+ content: '',+ filename: 'placeholder.md',+ id: 'd14dca54-7b38-44d5-9bdb-f3fed8c5f947',+ loadPosition: 'before-first-user',+ loadRules: { rule: 'always' },+ policyLoad: 'progressive',+ sourceType: 'file',+ title: 'ε¨ζ₯δΈεΉ³ε°ε―Ήθ―εζ',+ updatedAt: new Date('2026-04-16T00:00:00.000Z'),+ },+ ],+ });++ const context = createContext([{ content: 'Hello', id: 'user-1', role: 'user' }]);+ const result = await provider.process(context);++ expect(result.messages[0].content).toMatchInlineSnapshot(`+ "<agent_documents_index>+ 1 user-created doc. Use readDocument(id) for full content.++ TITLE ID SIZE UPDATED+ ε¨ζ₯δΈεΉ³ε°ε―Ήθ―εζ d14dca54-7b38-44d5-9bdb-f3fed8c5f947 empty 13d ago+ </agent_documents_index>"+ `);});it('should mix full-content and progressive documents', async () => {const provider = new AgentDocumentContextInjector({+ currentTime: new Date('2026-04-29T00:00:00.000Z'),documents: [{content: 'Always-loaded full content',@@ -227,13 +316,14 @@ describe('AgentDocumentInjector', () => {},{content: 'Progressive content hidden',- description: 'A summary doc',filename: 'summary.md',id: 'doc-p',loadPosition: 'before-first-user',loadRules: { rule: 'always' },policyLoad: 'progressive',+ sourceType: 'file',title: 'Summary',+ updatedAt: new Date('2026-04-28T00:00:00.000Z'),},],});@@ -244,7 +334,8 @@ describe('AgentDocumentInjector', () => {const injected = result.messages[0].content;expect(injected).toContain('Always-loaded full content');expect(injected).toContain('<agent_documents_index>');- expect(injected).toContain('summary.md');+ expect(injected).toContain('Summary');+ expect(injected).toContain('doc-p');expect(injected).not.toContain('Progressive content hidden');});});diff --git a/src/locales/default/plugin.ts b/src/locales/default/plugin.tsindex c5ccd6fd3d9..c352468aedb 100644--- a/src/locales/default/plugin.ts+++ b/src/locales/default/plugin.ts@@ -189,8 +189,8 @@ export default {'builtins.lobe-agent-documents.inspector.docCount': '{{count}} docs','builtins.lobe-agent-documents.inspector.opsCount': '{{count}} ops','builtins.lobe-agent-documents.inspector.opsResult': '{{success}}/{{total}} ops',- 'builtins.lobe-agent-documents.inspector.target.agent': 'in agent',- 'builtins.lobe-agent-documents.inspector.target.currentTopic': 'in topic',+ 'builtins.lobe-agent-documents.inspector.scope.agent': 'in agent',+ 'builtins.lobe-agent-documents.inspector.scope.currentTopic': 'in topic','builtins.lobe-agent-documents.title': 'Agent Documents','builtins.lobe-notebook.actions.collapse': 'Collapse','builtins.lobe-notebook.actions.copy': 'Copy',diff --git a/src/server/routers/lambda/agentDocument.ts b/src/server/routers/lambda/agentDocument.tsindex 27b254b4725..598cecf68bd 100644--- a/src/server/routers/lambda/agentDocument.ts+++ b/src/server/routers/lambda/agentDocument.ts@@ -347,18 +347,23 @@ export const agentDocumentRouter = router({.input(z.object({agentId: z.string(),- target: z.enum(['agent', 'currentTopic']).optional().default('agent'),+ scope: z.enum(['agent', 'currentTopic']).optional().default('agent'),+ sourceType: z.enum(['all', 'file', 'web']).optional().default('all'),topicId: z.string().optional(),}),).query(async ({ ctx, input }) => {- if (input.target === 'currentTopic') {+ if (input.scope === 'currentTopic') {if (!input.topicId) throw new Error('topicId is required to list current topic documents');- return ctx.agentDocumentService.listDocumentsForTopic(input.agentId, input.topicId);+ return ctx.agentDocumentService.listDocumentsForTopic(+ input.agentId,+ input.topicId,+ input.sourceType,+ );}- return ctx.agentDocumentService.listDocuments(input.agentId);+ return ctx.agentDocumentService.listDocuments(input.agentId, input.sourceType);}),/**diff --git a/src/server/services/agentDocuments/index.ts b/src/server/services/agentDocuments/index.tsindex 56caf49a9f4..5ccc2d15d60 100644--- a/src/server/services/agentDocuments/index.ts+++ b/src/server/services/agentDocuments/index.ts@@ -468,20 +468,27 @@ export class AgentDocumentsService {}}- async listDocuments(agentId: string) {+ async listDocuments(agentId: string, sourceType?: 'all' | 'file' | 'web') {const docs = await this.agentDocumentModel.findByAgent(agentId);- return docs.map((d) => ({+ const filtered =+ sourceType && sourceType !== 'all' ? docs.filter((d) => d.sourceType === sourceType) : docs;+ return filtered.map((d) => ({documentId: d.documentId,fileType: d.fileType,filename: d.filename,id: d.id,loadPosition: d.policy?.context?.position,parentId: d.parentId,+ sourceType: d.sourceType,title: d.title,}));}- async listDocumentsForTopic(agentId: string, topicId: string) {+ async listDocumentsForTopic(+ agentId: string,+ topicId: string,+ sourceType?: 'all' | 'file' | 'web',+ ) {const topicDocs = await this.topicDocumentModel.findByTopicId(topicId);const documentIds = topicDocs.map((doc) => doc.id);const docs = await this.agentDocumentModel.findByDocumentIds(agentId, documentIds);@@ -490,6 +497,7 @@ export class AgentDocumentsService {return topicDocs.map((topicDoc) => docsByDocumentId.get(topicDoc.id)).filter((doc): doc is AgentDocumentWithRules => Boolean(doc))+ .filter((doc) => !sourceType || sourceType === 'all' || doc.sourceType === sourceType).map((doc) => ({documentId: doc.documentId,fileType: doc.fileType,@@ -497,6 +505,7 @@ export class AgentDocumentsService {id: doc.id,loadPosition: doc.policy?.context?.position,parentId: doc.parentId,+ sourceType: doc.sourceType,title: doc.title,}));}diff --git a/src/server/services/toolExecution/serverRuntimes/__tests__/agentDocuments.test.ts b/src/server/services/toolExecution/serverRuntimes/__tests__/agentDocuments.test.tsindex 0262c7a8fb6..6ff2f4f166a 100644--- a/src/server/services/toolExecution/serverRuntimes/__tests__/agentDocuments.test.ts+++ b/src/server/services/toolExecution/serverRuntimes/__tests__/agentDocuments.test.ts@@ -153,7 +153,7 @@ describe('agentDocumentsRuntime auto-pin to task', () => {const runtime = agentDocumentsRuntime.factory(buildContext('task-1'));await runtime.createDocument(- { content: 'body', target: 'currentTopic', title: 'Topic Note' },+ { content: 'body', scope: 'currentTopic', title: 'Topic Note' },{ agentId: 'agent-1', topicId: 'topic-1' },);@@ -228,7 +228,7 @@ describe('AgentDocumentsExecutionRuntime.createDocument', () => {expect(stub.createDocument).not.toHaveBeenCalled();});- it('creates a document in the current topic when target is currentTopic', async () => {+ it('creates a document in the current topic when scope is currentTopic', async () => {const stub = makeStub();stub.createTopicDocument.mockResolvedValue({documentId: 'documents-row-id',@@ -239,7 +239,7 @@ describe('AgentDocumentsExecutionRuntime.createDocument', () => {const runtime = new AgentDocumentsExecutionRuntime(stub);const result = await runtime.createDocument(- { content: 'body', target: 'currentTopic', title: 'Topic Note' },+ { content: 'body', scope: 'currentTopic', title: 'Topic Note' },{ agentId: 'agent-1', topicId: 'topic-1' },);@@ -251,7 +251,7 @@ describe('AgentDocumentsExecutionRuntime.createDocument', () => {expect(stub.createTopicDocument).toHaveBeenCalledWith({agentId: 'agent-1',content: 'body',- target: 'currentTopic',+ scope: 'currentTopic',title: 'Topic Note',topicId: 'topic-1',});@@ -263,7 +263,7 @@ describe('AgentDocumentsExecutionRuntime.createDocument', () => {const runtime = new AgentDocumentsExecutionRuntime(stub);const result = await runtime.createDocument(- { content: 'body', target: 'currentTopic', title: 'Topic Note' },+ { content: 'body', scope: 'currentTopic', title: 'Topic Note' },{ agentId: 'agent-1' },);@@ -363,7 +363,7 @@ describe('AgentDocumentsExecutionRuntime.listDocuments', () => {const runtime = new AgentDocumentsExecutionRuntime(stub);const result = await runtime.listDocuments(- { target: 'currentTopic' },+ { scope: 'currentTopic' },{ agentId: 'agent-1', topicId: 'topic-1' },);@@ -382,7 +382,8 @@ describe('AgentDocumentsExecutionRuntime.listDocuments', () => {});expect(stub.listTopicDocuments).toHaveBeenCalledWith({agentId: 'agent-1',- target: 'currentTopic',+ scope: 'currentTopic',+ sourceType: 'all',topicId: 'topic-1',});expect(stub.listDocuments).not.toHaveBeenCalled();diff --git a/src/server/services/toolExecution/serverRuntimes/agentDocuments.test.ts b/src/server/services/toolExecution/serverRuntimes/agentDocuments.test.tsindex 3979e8f714a..e5d98f4a0d5 100644--- a/src/server/services/toolExecution/serverRuntimes/agentDocuments.test.ts+++ b/src/server/services/toolExecution/serverRuntimes/agentDocuments.test.ts@@ -26,7 +26,7 @@ describe('agentDocumentsRuntime', () => {});const result = await runtime.listDocuments({}, { agentId: 'agent-1' });- expect(listDocuments).toHaveBeenCalledWith('agent-1');+ expect(listDocuments).toHaveBeenCalledWith('agent-1', 'all');expect(result).toEqual({content: JSON.stringify([{ filename: 'rules.md', id: 'doc-1', title: 'Rules' },diff --git a/src/server/services/toolExecution/serverRuntimes/agentDocuments.ts b/src/server/services/toolExecution/serverRuntimes/agentDocuments.tsindex 5a7422f625c..c3960b4e19e 100644--- a/src/server/services/toolExecution/serverRuntimes/agentDocuments.ts+++ b/src/server/services/toolExecution/serverRuntimes/agentDocuments.ts@@ -140,8 +140,8 @@ export const agentDocumentsRuntime: ServerRuntimeRegistration = {() => service.createForTopic(agentId, title, content, topicId, { hintIsSkill }),),),- listDocuments: async ({ agentId }) => {- const docs = await service.listDocuments(agentId);+ listDocuments: async ({ agentId, sourceType }) => {+ const docs = await service.listDocuments(agentId, sourceType);return docs.map((d) => ({documentId: d.documentId,filename: d.filename,@@ -149,8 +149,8 @@ export const agentDocumentsRuntime: ServerRuntimeRegistration = {title: d.title,}));},- listTopicDocuments: async ({ agentId, topicId }) => {- const docs = await service.listDocumentsForTopic(agentId, topicId);+ listTopicDocuments: async ({ agentId, sourceType, topicId }) => {+ const docs = await service.listDocumentsForTopic(agentId, topicId, sourceType);return docs.map((d) => ({documentId: d.documentId,filename: d.filename,diff --git a/src/services/agentDocument.ts b/src/services/agentDocument.tsindex 242f5dde851..be350ae1d8d 100644--- a/src/services/agentDocument.ts+++ b/src/services/agentDocument.ts@@ -70,7 +70,8 @@ class AgentDocumentService {listDocuments = async (params: {agentId: string;- target?: 'agent' | 'currentTopic';+ scope?: 'agent' | 'currentTopic';+ sourceType?: 'all' | 'file' | 'web';topicId?: string;}) => {return lambdaClient.agentDocument.listDocuments.query(params);@@ -303,7 +304,9 @@ export const mapAgentDocumentsToContext = (policyId: doc.templateId,policyLoad: doc.policyLoad as 'always' | 'progressive',policyLoadFormat: doc.policy?.context?.policyLoadFormat || doc.policyLoadFormat || undefined,+ sourceType: doc.sourceType ?? undefined,title: doc.title,+ updatedAt: doc.updatedAt ?? undefined,}));export const resolveAgentDocumentsContext = async (params: {diff --git a/src/store/chat/utils/activeTopicDocumentContext.test.ts b/src/store/chat/utils/activeTopicDocumentContext.test.tsindex e1a59e32e8b..ccda58b562a 100644--- a/src/store/chat/utils/activeTopicDocumentContext.test.ts+++ b/src/store/chat/utils/activeTopicDocumentContext.test.ts@@ -37,7 +37,7 @@ describe('activeTopicDocumentContext', () => {expect(agentDocumentService.listDocuments).toHaveBeenCalledWith({agentId: 'agt_1',- target: 'currentTopic',+ scope: 'currentTopic',topicId: 'tpc_1',});expect(context?.initialContext?.activeTopicDocument).toEqual({diff --git a/src/store/chat/utils/activeTopicDocumentContext.ts b/src/store/chat/utils/activeTopicDocumentContext.tsindex 08191809da9..02ce9e39c76 100644--- a/src/store/chat/utils/activeTopicDocumentContext.ts+++ b/src/store/chat/utils/activeTopicDocumentContext.ts@@ -43,7 +43,7 @@ const resolveActiveTopicDocument = async (try {const documents = await agentDocumentService.listDocuments({agentId: context.agentId,- target: 'currentTopic',+ scope: 'currentTopic',topicId: context.topicId,});const matchedDocument = documents.find(diff --git a/src/store/tool/slices/builtin/executors/lobe-agent-documents.ts b/src/store/tool/slices/builtin/executors/lobe-agent-documents.tsindex 129816a007f..2162e854694 100644--- a/src/store/tool/slices/builtin/executors/lobe-agent-documents.ts+++ b/src/store/tool/slices/builtin/executors/lobe-agent-documents.ts@@ -26,8 +26,8 @@ const runtime = new AgentDocumentsExecutionRuntime({topicId,trigger,}),- listDocuments: async ({ agentId }) => {- const docs = await agentDocumentService.listDocuments({ agentId });+ listDocuments: async ({ agentId, sourceType }) => {+ const docs = await agentDocumentService.listDocuments({ agentId, sourceType });return docs.map((d) => ({documentId: d.documentId,filename: d.filename,@@ -35,10 +35,11 @@ const runtime = new AgentDocumentsExecutionRuntime({title: d.title,}));},- listTopicDocuments: async ({ agentId, topicId }) => {+ listTopicDocuments: async ({ agentId, sourceType, topicId }) => {const docs = await agentDocumentService.listDocuments({agentId,- target: 'currentTopic',+ scope: 'currentTopic',+ sourceType,topicId,});return docs.map((d) => ({