$ pip install "duckduckgo-search==7.1.0"


from crewai.tools import tool
from duckduckgo_search import DDGS

@tool("web_search")
def web_search(query: str) -> str:
    """Search the web; return up to 3 hits
    as title, snippet, and source URL."""
    with DDGS() as ddgs:
        hits = list(
            ddgs.text(query, max_results=3)
        )
    if not hits:
        return "No results found."
    return "\n".join(
        f"- {h['title']}: {h['body']} "
        f"({h['href']})"
        for h in hits
    )
