From 43a78a6ce0ffdf07b5d76b5ca34e4147a83bdcb6 Mon Sep 17 00:00:00 2001 From: itsautomata <112640947+itsautomata@users.noreply.github.com> Date: Tue, 26 May 2026 22:24:55 +0200 Subject: [PATCH] fix: gate search tool registration on TAVILY_API_KEY presence The search tool was registered unconditionally in getTools(), so the LLM would attempt to call it even when TAVILY_API_KEY was unset. The Tavily client then errored inside execute(), and the UI rendered "An error occurred while searching for..." for any search-y query, regardless of whether the deployment intended search to be enabled. Match the existing SERPER_API_KEY pattern in the same file's videoSearch registration: only register the tool when its required key is present. The LLM then answers from its own knowledge for queries that would have triggered search, with no misleading error card. Also adds TAVILY_API_KEY to .env.local.example with a note documenting the runtime behavior when unset. --- .env.local.example | 4 ++++ lib/agents/tools/index.tsx | 11 +++++++---- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/.env.local.example b/.env.local.example index e52eec0c..e116efa3 100644 --- a/.env.local.example +++ b/.env.local.example @@ -20,6 +20,10 @@ NEXT_PUBLIC_COMPOSIO_USER_ID=user@example.com # Gemini 3.1 Pro (Google Generative AI) GEMINI_3_PRO_API_KEY=your_gemini_3_pro_api_key_here +# Search API (https://tavily.com) +# If not set, the `search` tool is skipped and the LLM answers from its own knowledge. +TAVILY_API_KEY=your_tavily_api_key + # Supabase Credentials NEXT_PUBLIC_SUPABASE_URL=YOUR_SUPABASE_URL_HERE NEXT_PUBLIC_SUPABASE_ANON_KEY=YOUR_SUPABASE_ANON_KEY_HERE diff --git a/lib/agents/tools/index.tsx b/lib/agents/tools/index.tsx index 4c22b887..2491cf9c 100644 --- a/lib/agents/tools/index.tsx +++ b/lib/agents/tools/index.tsx @@ -14,10 +14,6 @@ export interface ToolProps { export const getTools = ({ uiStream, fullResponse, mapProvider }: ToolProps) => { const tools: any = { - search: searchTool({ - uiStream, - fullResponse - }), retrieve: retrieveTool({ uiStream, fullResponse @@ -28,6 +24,13 @@ export const getTools = ({ uiStream, fullResponse, mapProvider }: ToolProps) => }) } + if (process.env.TAVILY_API_KEY) { + tools.search = searchTool({ + uiStream, + fullResponse + }) + } + if (process.env.SERPER_API_KEY) { tools.videoSearch = videoSearchTool({ uiStream,