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): basic tool to get child notes
Elian Doranbac25c9173df
diff --git a/apps/server/src/services/llm/providers/anthropic.ts b/apps/server/src/services/llm/providers/anthropic.tsindex e8fc71cce1..af415dd020 100644--- a/apps/server/src/services/llm/providers/anthropic.ts+++ b/apps/server/src/services/llm/providers/anthropic.ts@@ -3,7 +3,7 @@ import { generateText, streamText, stepCountIs, type CoreMessage, type ToolSet }import type { LlmMessage } from "@triliumnext/commons";import becca from "../../../becca/becca.js";-import { noteTools, attributeTools, currentNoteTools } from "../tools/index.js";+import { noteTools, attributeTools, hierarchyTools, currentNoteTools } from "../tools/index.js";import type { LlmProvider, LlmProviderConfig, ModelInfo, ModelPricing, StreamResult } from "../types.js";const DEFAULT_MODEL = "claude-sonnet-4-6";@@ -206,6 +206,7 @@ export class AnthropicProvider implements LlmProvider {if (config.enableNoteTools) {Object.assign(tools, noteTools);Object.assign(tools, attributeTools);+ Object.assign(tools, hierarchyTools);}if (Object.keys(tools).length > 0) {diff --git a/apps/server/src/services/llm/tools/hierarchy_tools.ts b/apps/server/src/services/llm/tools/hierarchy_tools.tsnew file mode 100644index 0000000000..8da42900b9--- /dev/null+++ b/apps/server/src/services/llm/tools/hierarchy_tools.ts@@ -0,0 +1,35 @@+/**+ * LLM tools for navigating the note hierarchy (tree structure, branches).+ */++import { tool } from "ai";+import { z } from "zod";++import becca from "../../../becca/becca.js";++/**+ * Get the child notes of a given note.+ */+export const getChildNotes = tool({+ description: "Get the immediate child notes of a note. Returns each child's ID, title, type, and whether it has children of its own. Use noteId 'root' to list top-level notes.",+ inputSchema: z.object({+ noteId: z.string().describe("The ID of the parent note (use 'root' for top-level)")+ }),+ execute: async ({ noteId }) => {+ const note = becca.getNote(noteId);+ if (!note) {+ return { error: "Note not found" };+ }++ return note.getChildNotes().map((child) => ({+ noteId: child.noteId,+ title: child.getTitleOrProtected(),+ type: child.type,+ childCount: child.getChildNotes().length+ }));+ }+});++export const hierarchyTools = {+ get_child_notes: getChildNotes+};diff --git a/apps/server/src/services/llm/tools/index.ts b/apps/server/src/services/llm/tools/index.tsindex dc2257ef1b..0540b9d617 100644--- a/apps/server/src/services/llm/tools/index.ts+++ b/apps/server/src/services/llm/tools/index.ts@@ -5,3 +5,4 @@export { noteTools, currentNoteTools } from "./note_tools.js";export { attributeTools } from "./attribute_tools.js";+export { hierarchyTools } from "./hierarchy_tools.js";