Skip to content

Build your personal knowledge base with Trilium Notes

feat(llm): tell the model a declined tool call is the user's decision

Elian Doran611ab5e04695
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 662a8666b2..471927268d 100644
--- a/packages/trilium-core/src/services/llm/system_prompt.spec.ts
+++ b/packages/trilium-core/src/services/llm/system_prompt.spec.ts
@@ -39,6 +39,15 @@ describe("buildSystemPrompt", () => {
expect(prompt).not.toContain("do not have access to web search");
});
+ it("tells a model with tools that a declined call is the user's decision, not an error to work around", () => {
+ for (const config of [ { enableNoteTools: true }, { enableWebSearch: true } ]) {
+ const prompt = buildSystemPrompt([], config) ?? "";
+ expect(prompt).toContain("declines a tool call");
+ expect(prompt).toContain("through another tool or the file system");
+ }
+ expect(buildSystemPrompt([], {})).not.toContain("declines a tool call");
+ });
+
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 44aa103cf6..4ae3ec95fd 100644
--- a/packages/trilium-core/src/services/llm/system_prompt.ts
+++ b/packages/trilium-core/src/services/llm/system_prompt.ts
@@ -81,6 +81,9 @@ export function buildSystemPrompt(messages: LlmMessage[], config: LlmProviderCon
parts.push(
`When you need several independent pieces of information, issue the tool calls in parallel within the same turn instead of waiting for each result before requesting the next. Only chain calls sequentially when a later call genuinely depends on the output of an earlier one.`
);
+ parts.push(
+ `When the user declines a tool call, that is their decision about what you may access or change, not an error: do not retry the call, and do not try to reach the same information or make the same change through another tool or the file system. Continue with what you already have, or ask the user how to proceed.`
+ );
}
// Markdown formatting hints