Skip to content

Build your personal knowledge base with Trilium Notes

feat(llm): read a linked note by the ID in its link

Elian Doranc09f8ee22854
diff --git a/packages/trilium-core/src/services/llm/system_prompt.spec.ts b/packages/trilium-core/src/services/llm/system_prompt.spec.ts
index 471927268d..1d55355dc7 100644
--- a/packages/trilium-core/src/services/llm/system_prompt.spec.ts
+++ b/packages/trilium-core/src/services/llm/system_prompt.spec.ts
@@ -48,6 +48,11 @@ describe("buildSystemPrompt", () => {
expect(buildSystemPrompt([], {})).not.toContain("declines a tool call");
});
+ it("tells a model with note tools to read a linked note by the ID in its link", () => {
+ expect(buildSystemPrompt([], { enableNoteTools: true })).toContain("#root/<noteId>");
+ expect(buildSystemPrompt([], { enableWebSearch: true })).not.toContain("#root/<noteId>");
+ });
+
it("emits the context-note-only notice when a context note is set but note tools are off", () => {
const prompt = buildSystemPrompt([], { contextNoteId: "ctx" }) ?? "";
expect(prompt).toContain("cannot search or access other notes");
diff --git a/packages/trilium-core/src/services/llm/system_prompt.ts b/packages/trilium-core/src/services/llm/system_prompt.ts
index 4ae3ec95fd..1802ee1eb2 100644
--- a/packages/trilium-core/src/services/llm/system_prompt.ts
+++ b/packages/trilium-core/src/services/llm/system_prompt.ts
@@ -47,6 +47,9 @@ export function buildSystemPrompt(messages: LlmMessage[], config: LlmProviderCon
parts.push(
`When referring to notes in your responses, use the wiki-link format [[noteId]] to create clickable internal links. Use the note ID (not the title) from tool results. The link will automatically display the note's title and icon, so don't repeat the title in your text. For example: "You can find more details in [[ZjSfLhzlqNY6]]" instead of "You can find more details in the Meeting Notes note ([[ZjSfLhzlqNY6]])".`
);
+ parts.push(
+ `A note the user links in a message appears as a Markdown link to #root/<noteId>, where the last part of the path is its note ID. To read a linked note, call get_note or get_note_content with that ID rather than searching for its title, which other notes can share.`
+ );
parts.push(
`Do not create, modify, or delete notes unless the user explicitly asks you to (e.g. "create a note", "save this to a note"). The chat supports rich Markdown rendering including code blocks, math equations, mermaid diagrams, and tables — so always present content directly in your response rather than creating a note for it. For example, if asked to "visualize an algorithm", render a mermaid diagram in the chat, don't create a note.`
);