zBotta's picture
Update agent/tools/search_tool.py
3a9613f verified
from langchain_community.tools import DuckDuckGoSearchResults, DuckDuckGoSearchRun, tool
@tool(description="Use this tool to get search results for a query. Input should be a string representing the search query. Output will be a string containing the search results.")
def search_tool(query: str) -> str:
print(f"Invoking search tool with query: {query}")
try:
search_tool = DuckDuckGoSearchResults(engine="duckduckgo")
search_results = search_tool.run(query)
print(f"Search tool returned results: {search_results[:100]}...") # Print first 100 chars of results
return search_results
except Exception as e:
error_message = f"Error invoking search tool: {e}"
return error_message
# search_tool = Tool(
# name = "get_search_results",
# func = get_search_results,
# description = "Use this tool to get search results for a query. Input should be a string representing the search query. Output will be a string containing the search results."
# )
if __name__ == "__main__":
results = search_tool("Who's the current President of France?")
print(results)