File size: 707 Bytes
2bf962d
 
 
a9c5bda
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
from typing import List
from duckduckgo_search import DDGS

# --- Simple Search Tool ---

def simple_search(query: str, max_results: int = 3) -> List[str]:
    """
    Perform a DuckDuckGo search and return a list of strings summarizing the top results.
    """
    with DDGS() as ddgs:
        raw_results = list(ddgs.text(query, max_results=max_results))

    results = []
    for r in raw_results:
        try:
            title = r.get("title", "")
            link = r.get("href") or r.get("link", "")
            summary = f"{title} - {link}"
            results.append(summary)
        except Exception as e:
            print("Skipping malformed search result:", r, "Error:", e)

    return results