From d6176e86d6d304159afba06e6f06d83b4b031d98 Mon Sep 17 00:00:00 2001 From: amszuidas <254873068+amszuidas@users.noreply.github.com> Date: Fri, 23 Jan 2026 23:50:40 +0800 Subject: [PATCH] fix: support loading tavily ak from config.yaml --- backend/src/community/tavily/tools.py | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/backend/src/community/tavily/tools.py b/backend/src/community/tavily/tools.py index 9d675d8..6a22d87 100644 --- a/backend/src/community/tavily/tools.py +++ b/backend/src/community/tavily/tools.py @@ -5,7 +5,13 @@ from tavily import TavilyClient from src.config import get_app_config -tavily_client = TavilyClient() + +def _get_tavily_client() -> TavilyClient: + config = get_app_config().get_tool_config("web_search") + api_key = None + if config is not None and "api_key" in config.model_extra: + api_key = config.model_extra.get("api_key") + return TavilyClient(api_key=api_key) @tool("web_search", parse_docstring=True) @@ -19,7 +25,9 @@ def web_search_tool(query: str) -> str: max_results = 5 if config is not None and "max_results" in config.model_extra: max_results = config.model_extra.get("max_results") - res = tavily_client.search(query, max_results=max_results) + + client = _get_tavily_client() + res = client.search(query, max_results=max_results) normalized_results = [ { "title": result["title"], @@ -43,7 +51,8 @@ def web_fetch_tool(url: str) -> str: Args: url: The URL to fetch the contents of. """ - res = tavily_client.extract([url]) + client = _get_tavily_client() + res = client.extract([url]) if "failed_results" in res and len(res["failed_results"]) > 0: return f"Error: {res['failed_results'][0]['error']}" elif "results" in res and len(res["results"]) > 0: