Skip to content

Build your personal knowledge base with Trilium Notes

feat(llm): disable web search when note tools are active

Elian Doran21e16261d241
diff --git a/apps/client/src/translations/en/translation.json b/apps/client/src/translations/en/translation.json
index 1609e9ca9b..6b17f59ff5 100644
--- a/apps/client/src/translations/en/translation.json
+++ b/apps/client/src/translations/en/translation.json
@@ -1786,6 +1786,7 @@
"empty_state": "Start a conversation by typing a message below.",
"searching_web": "Searching the web...",
"web_search": "Web search",
+ "web_search_unavailable_gemini": "Not available on Gemini models while note access is on — Google's API does not allow combining both. Disable note access or switch to a different provider to use web search.",
"note_tools": "Note access",
"sources": "Sources",
"sources_summary": "{{count}} sources from {{sites}} sites",
diff --git a/apps/client/src/widgets/type_widgets/llm_chat/ChatInputBar.tsx b/apps/client/src/widgets/type_widgets/llm_chat/ChatInputBar.tsx
index 9dc171256f..a340f19e3a 100644
--- a/apps/client/src/widgets/type_widgets/llm_chat/ChatInputBar.tsx
+++ b/apps/client/src/widgets/type_widgets/llm_chat/ChatInputBar.tsx
@@ -191,6 +191,11 @@ export default function ChatInputBar({
const currentModel = chat.availableModels.find(m => m.id === chat.selectedModel);
const currentModels = chat.availableModels.filter(m => !m.isLegacy);
const legacyModels = chat.availableModels.filter(m => m.isLegacy);
+ // Gemini 2.x cannot combine googleSearch with function tools in a single
+ // request. When note tools are enabled on a Gemini model we silently drop
+ // web search server-side; reflect that here by disabling the toggle so the
+ // user understands the trade-off instead of seeing it mysteriously ignored.
+ const webSearchUnavailable = currentModel?.provider === "google" && chat.enableNoteTools;
const contextWindow = currentModel?.contextWindow || 200000;
const percentage = Math.min((chat.lastPromptTokens / contextWindow) * 100, 100);
const isWarning = percentage > 75;
@@ -343,9 +348,10 @@ export default function ChatInputBar({
<FormListToggleableItem
icon="bx bx-globe"
title={t("llm_chat.web_search")}
- currentValue={chat.enableWebSearch}
+ currentValue={chat.enableWebSearch && !webSearchUnavailable}
onChange={handleWebSearchToggle}
- disabled={chat.isStreaming}
+ disabled={chat.isStreaming || webSearchUnavailable}
+ disabledTooltip={webSearchUnavailable ? t("llm_chat.web_search_unavailable_gemini") : undefined}
/>
<FormListToggleableItem
icon="bx bx-note"
diff --git a/apps/server/src/services/llm/providers/google.ts b/apps/server/src/services/llm/providers/google.ts
index d879ab2ca8..2d02c1e77d 100644
--- a/apps/server/src/services/llm/providers/google.ts
+++ b/apps/server/src/services/llm/providers/google.ts
@@ -2,9 +2,22 @@ import { createGoogleGenerativeAI, type GoogleGenerativeAIProvider } from "@ai-s
import { streamText, stepCountIs, type ToolSet } from "ai";
import type { LlmMessage } from "@triliumnext/commons";
+import log from "../../log.js";
import type { LlmProviderConfig, StreamResult } from "../types.js";
import { BaseProvider, buildModelList } from "./base_provider.js";
+/**
+ * Gemini 2.x models (every model we currently expose) cannot combine
+ * provider-defined tools like `googleSearch` with function declarations in a
+ * single request — Google's API rejects the combination. Combined tool use is
+ * Gemini-3-only and even there is flagged as Preview. When both are requested
+ * we silently drop `googleSearch` and keep function tools, since note access
+ * is Trilium's higher-value capability and is what the user explicitly toggled.
+ */
+function geminiHasToolConflict(config: LlmProviderConfig): boolean {
+ return !!(config.enableWebSearch && config.enableNoteTools);
+}
+
/**
* Available Google Gemini models with pricing (USD per million tokens).
* Source: https://ai.google.dev/gemini-api/docs/pricing
@@ -64,6 +77,22 @@ export class GoogleProvider extends BaseProvider {
tools.google_search = this.google.tools.googleSearch({});
}
+ protected override buildTools(config: LlmProviderConfig): ToolSet {
+ if (geminiHasToolConflict(config)) {
+ log.info("Gemini: dropping google_search because note tools are enabled (Google API does not allow combining provider-defined tools with function declarations)");
+ return super.buildTools({ ...config, enableWebSearch: false });
+ }
+ return super.buildTools(config);
+ }
+
+ protected override buildSystemPrompt(messages: LlmMessage[], config: LlmProviderConfig): string | undefined {
+ const basePrompt = super.buildSystemPrompt(messages, config);
+ if (!geminiHasToolConflict(config) || !basePrompt) {
+ return basePrompt;
+ }
+ return `${basePrompt}\n\nNote: web search is unavailable in this turn because note tools are enabled — Google's Gemini API does not allow combining the two. If the user asks you to search the web, tell them they need to either switch to a different provider (OpenAI/Anthropic) or disable note tools.`;
+ }
+
/**
* Override chat to add Google-specific extended thinking support.
* Gemini 2.5 uses thinkingBudget, Gemini 3.x uses thinkingLevel.