from langchain_core.tools import tool from langchain_community.tools import DuckDuckGoSearchRun #from langchain_tavily import TavilySearch import os #from dotenv import load_dotenv #load_dotenv() os.environ["TAVILY_API_KEY"] = os.getenv("TAVILY_API_KEY") @tool def websearch(query: str) -> str: """ Perform a web search using DuckDuckGo. Args: query (str): The search query string. Returns: str: The result of the web search as a string. If an exception occurs, returns a fallback string indicating no results were found. """ search_engine = DuckDuckGoSearchRun() try: response = search_engine.invoke(query) return response except: return f"No results found on the web for this query: {query}."