Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ DATABASE_URL=postgresql://postgres:postgres@localhost:5432/openworkers
ANTHROPIC_API_KEY=your_anthropic_api_key_here
OPENAI_API_KEY=your_openai_api_key_here
DEEPSEEK_API_KEY=your_deepseek_api_key_here
TAVILY_API_KEY=your_tavily_api_key_here

# ─── Per-Mode Provider + Model ──────────────────────────────────
# Three modes control which provider AND model each agent uses:
Expand Down
1 change: 1 addition & 0 deletions core/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ class Settings(BaseSettings):
anthropic_api_key: str = ""
openai_api_key: str = ""
deepseek_api_key: str = ""
tavily_api_key: str = ""

# ── budget guard ────────────────────────────────────────────────────
max_budget_usd: Optional[float] = None
Expand Down
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ dependencies = [
"anthropic>=0.25.0",
"openai>=1.14.0",
"duckduckgo-search>=5.2.0",
"tavily-python>=0.5.0",
"pymupdf>=1.24.0",
"httpx>=0.27.0",
"tenacity>=9.0.0",
Expand Down
24 changes: 24 additions & 0 deletions tools/mcp/engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
from typing import Any

from duckduckgo_search import DDGS
from tavily import TavilyClient

from core.config import get_settings
from tools.cache import SearchCache, get_default_cache


Expand Down Expand Up @@ -93,6 +95,28 @@ async def execute_impl(self, params: dict[str, Any]) -> dict[str, Any]:
if not query:
return {"results": []}

tavily_api_key = get_settings().tavily_api_key
if tavily_api_key:
try:
return await self._tavily_search(query, tavily_api_key)
except Exception as e:
logging.warning(f"Tavily search failed, falling back to DDGS: {e}")

return await self._ddgs_search(query)

async def _tavily_search(self, query: str, api_key: str) -> dict[str, Any]:
def _search():
client = TavilyClient(api_key=api_key)
return client.search(query=query, max_results=5)

response = await asyncio.to_thread(_search)
formatted_results = [
f"{r.get('title', '')} - {r.get('content', '')} ({r.get('url', '')})"
for r in response.get("results", [])
]
return {"results": formatted_results}

async def _ddgs_search(self, query: str) -> dict[str, Any]:
def _search():
with DDGS() as ddgs:
return list(ddgs.text(query, max_results=5))
Expand Down