from smolagents import Tool from langchain_community.tools import WikipediaQueryRun from langchain_community.utilities import WikipediaAPIWrapper class WikipediaSearcher(Tool): name = "wikipedia_search" description = "Search Wikipedia and return a summary for a given query." inputs = { "query": { "type": "string", "description": "Search term for Wikipedia" } } output_type = "string" def __init__(self): super().__init__() self.wikipedia = WikipediaQueryRun(api_wrapper=WikipediaAPIWrapper()) def forward(self, query: str) -> str: try: return self.wikipedia.run(query) except Exception as e: return f"Error retrieving Wikipedia data: {e}"