File size: 553 Bytes
7bfec74
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# tools/wikipedia_tool.py

import wikipedia

wikipedia.set_lang("en")

def wiki_search(query: str) -> str:
    """
    Search Wikipedia and return a short summary of the topic.

    Args:
        query (str): The search query.

    Returns:
        str: Summary text or error message.
    """
    try:
        # Try to fetch a summary of the most relevant page
        return wikipedia.summary(query, sentences=3, auto_suggest=True, redirect=True)
    except wikipedia.DisambiguationError as e:
        # If multiple results, return options
        pass