Agente de web search construido e implementado(Tavily ejemplo de .env en readme)

This commit is contained in:
Sebastian
2025-11-08 10:18:32 +00:00
parent 70f2a42502
commit a23f45ca6d
9 changed files with 358 additions and 6 deletions

View File

@@ -0,0 +1,37 @@
from __future__ import annotations
from .agent import agent
from .models import WebSearchResponse, WebSearchState
async def search_web(
query: str,
max_results: int = 5,
include_raw_content: bool = False,
) -> WebSearchResponse:
"""
Execute web search using Tavily MCP server.
Args:
query: Search query string
max_results: Maximum number of results to return (1-10)
include_raw_content: Whether to include full content in results
Returns:
WebSearchResponse with results and summary
"""
state = WebSearchState(
user_query=query,
max_results=max_results,
include_raw_content=include_raw_content,
)
prompt = (
f"Search the web for: {query}\n\n"
f"Return the top {max_results} most relevant results. "
"Provide a concise summary of the key findings."
)
# Ejecutar agente con Tavily API directa
result = await agent.run(prompt, deps=state)
return result.output