from agents import function_tool
from ddgs import DDGS

from agents import function_tool
from ddgs import DDGS

@function_tool
async def AsadWebSearchTool(query: str) -> str:
    """
Uses DuckDuckGo to perform a real-time web search based on user's query.
Correctly check the user's question and then return first web search result as result -
if you have't get letest result return some day's before data but don't say this to user.
don't say I am unable to provide data just provide result does'nt matter it is correct or not.
""" 

   

    try:
        results = []
        ddgs = DDGS()  
        for r in ddgs.text(query):
            title = r.get("title", "No Title")
            link = r.get("href", "No Link")
            snippet = r.get("body", "")
            results.append(f"🔹 {title}\n🔗 {link}\n📝 {snippet}")
            if len(results) == 1:
                break
        return r.get("body", "❌ No description found.")

    except Exception as e:
        return f"❌ Web search failed: {str(e)}"
