| from langchain_tavily import TavilySearch | |
| from langchain.tools import tool | |
| from dotenv import load_dotenv | |
| load_dotenv() | |
| search_tool = TavilySearch(max_results=5) | |
| def web_search_tool(question: str) -> str: | |
| """Searches the web for an answer to a user's question. | |
| Args: | |
| question: User question | |
| """ | |
| try: | |
| search_results = search_tool.invoke(question) | |
| return search_results | |
| except Exception as e: | |
| return f"Error searching web: {str(e)}" | |