Skip to content

Commit b94531d

Browse files
author
wuxiaohan10
committed
fix: add warning log and clearer error message for missing Tavily API key
Log a warning at startup when TAVILY_API_KEY is not configured, and return a more actionable error message when search is invoked without it. Made-with: Cursor
1 parent 2c0e4ae commit b94531d

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

backend/app/core/tools/buildin/research_tools.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,15 @@
44
using Tavily for URL discovery and fetching full webpage content.
55
"""
66

7+
import logging
8+
79
import httpx
810
from langchain_core.tools import InjectedToolArg, tool
911
from markdownify import markdownify
1012
from typing_extensions import Annotated, Literal
1113

14+
logger = logging.getLogger(__name__)
15+
1216
try:
1317
from tavily import TavilyClient
1418
except ImportError:
@@ -18,6 +22,10 @@
1822
try:
1923
tavily_client = TavilyClient() if TavilyClient else None
2024
except Exception:
25+
logger.warning(
26+
"Tavily client initialization failed. "
27+
"Please set the TAVILY_API_KEY environment variable to enable web search."
28+
)
2129
tavily_client = None
2230

2331

@@ -62,7 +70,10 @@ def tavily_search(
6270
Formatted search results with full webpage content
6371
"""
6472
if tavily_client is None:
65-
return "Error: Tavily client is not available. Please install tavily-python package."
73+
return (
74+
"Error: Tavily client is not available. "
75+
"Please set the TAVILY_API_KEY environment variable and restart the service."
76+
)
6677

6778
# Use Tavily to discover URLs
6879
search_results = tavily_client.search(

0 commit comments

Comments
 (0)