Build your personal knowledge base with Trilium Notes
TypeScript electronelectron-appknowledge-baseknowledge-graphknowledge-managementknowledge-management-graphlocal-firstnote-managmentnote-takernote-takingnotebooknotesnotes-apppersonal-knowledge-basepersonal-wikiscriptableself-hostedself-hostingwiki
feat(llm): inject current note ID in the system prompt
Elian Doran57a299de8fe9
diff --git a/apps/client/src/translations/en/translation.json b/apps/client/src/translations/en/translation.jsonindex 85093a475b..97c8e27aae 100644--- a/apps/client/src/translations/en/translation.json+++ b/apps/client/src/translations/en/translation.json@@ -2346,7 +2346,6 @@"update_note_content": "Update note content","append_to_note": "Append to note","create_note": "Create note",- "get_current_note": "Read current note","get_attributes": "Get attributes","get_attribute": "Get attribute","set_attribute": "Set attribute",diff --git a/apps/server/src/services/llm/providers/base_provider.ts b/apps/server/src/services/llm/providers/base_provider.tsindex 1b34ccada4..d29467a6ed 100644--- a/apps/server/src/services/llm/providers/base_provider.ts+++ b/apps/server/src/services/llm/providers/base_provider.ts@@ -33,7 +33,7 @@ function buildNoteHint(noteId: string): string | null {return null;}- return `The user is currently viewing a ${note.type} note titled "${note.title}". Use the get_current_note tool to read its content if needed.`;+ return `The user is currently viewing a ${note.type} note titled "${note.title}" (noteId: ${note.noteId}). This is the current note.`;}/**diff --git a/apps/server/src/services/llm/tools/note_tools.ts b/apps/server/src/services/llm/tools/note_tools.tsindex 0ee1d0110f..e3a105d2e0 100644--- a/apps/server/src/services/llm/tools/note_tools.ts+++ b/apps/server/src/services/llm/tools/note_tools.ts@@ -11,7 +11,7 @@ import markdownImport from "../../import/markdown.js";import noteService from "../../notes.js";import SearchContext from "../../search/search_context.js";import searchService from "../../search/services/search.js";-import { defineTools, type ToolContext } from "./tool_registry.js";+import { defineTools } from "./tool_registry.js";/*** Convert note content to a format suitable for LLM consumption.@@ -246,27 +246,5 @@ export const noteTools = defineTools({return { error: err instanceof Error ? err.message : "Failed to create note" };}}- },-- get_current_note: {- description: "Read the content of the note the user is currently viewing. Call this when the user asks about or refers to their current note.",- inputSchema: z.object({}),- needsContext: true as const,- execute: async (_args: Record<string, never>, { contextNoteId }: ToolContext) => {- const note = becca.getNote(contextNoteId);- if (!note) {- return { error: "Note not found" };- }- if (!note.isContentAvailable()) {- return { error: "Note is protected" };- }-- return {- noteId: note.noteId,- title: note.getTitleOrProtected(),- type: note.type,- content: getNoteContentForLlm(note)- };- }}});