File size: 727 Bytes
6ae13c3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26

@tool
def web_search(query: str) -> str:
    """Performs a DuckDuckGo search for the given query and returns the results.

    Args:
        query: The search query.

    Returns:
        The top search results as a string.
    """
    try:
        if not query or not query.strip():
            return "Error: Search query cannot be empty"
        
        search_tool = DuckDuckGoSearchRun()
        results = search_tool.invoke(query.strip())
        
        # Clean up the results a bit
        if len(results) > 2000:  # Truncate very long results
            results = results[:2000] + "... (truncated)"
        
        return results
    except Exception as e:
        return f"Error performing web search: {str(e)}"