diff --git a/memento-note/app/api/chat/route.ts b/memento-note/app/api/chat/route.ts index bc6afdc..00dd784 100644 --- a/memento-note/app/api/chat/route.ts +++ b/memento-note/app/api/chat/route.ts @@ -419,7 +419,11 @@ Never switch to another language. Even if the user writes in a different languag webSearch: !!webSearch, config, } - const chatTools = toolRegistry.buildToolsForChat(chatToolContext) + // When scoped to "this note", only provide web tools — no note_search/note_read + // to prevent the AI from pulling information from other notes + const chatTools = noteContext + ? toolRegistry.buildToolsForChat({ ...chatToolContext, webOnly: true }) + : toolRegistry.buildToolsForChat(chatToolContext) // 8. Save user message to DB before streaming if (isNewMessage && lastIncoming) { diff --git a/memento-note/lib/ai/tools/registry.ts b/memento-note/lib/ai/tools/registry.ts index 262b621..e1eb75a 100644 --- a/memento-note/lib/ai/tools/registry.ts +++ b/memento-note/lib/ai/tools/registry.ts @@ -49,9 +49,10 @@ class ToolRegistry { /** * Build tools for the chat endpoint. * Includes internal tools (note_search, note_read) and web tools when configured. + * When webOnly is true, only web tools are included (no note access). */ - buildToolsForChat(ctx: ToolContext): Record { - const toolNames: string[] = ['note_search', 'note_read'] + buildToolsForChat(ctx: ToolContext & { webOnly?: boolean }): Record { + const toolNames: string[] = ctx.webOnly ? [] : ['note_search', 'note_read'] // Add web tools only when user toggled web search AND config is present if (ctx.webSearch) {