"""Tavily web search wrapper.""" from tavily import TavilyClient import config def search(query: str, max_results: int = 5) -> str: """Search the web and return a formatted markdown string.""" client = TavilyClient(api_key=config.TAVILY_API_KEY) resp = client.search(query, max_results=max_results) lines = [f"**Query:** {query}\n"] for r in resp.get("results", []): lines.append(f"### {r.get('title', 'No title')}") lines.append(f"URL: {r.get('url', '')}") lines.append(r.get("content", "").strip()) lines.append("") return "\n".join(lines)