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 docker-compose.gpu-amd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ services:
- TAVILY_API_KEY=${TAVILY_API_KEY:-}
- SERPER_API_KEY=${SERPER_API_KEY:-}
- YDC_API_KEY=${YDC_API_KEY:-}
- SOFYA_API_KEY=${SOFYA_API_KEY:-}
# PUID / PGID — the user/group the container drops to before
# running uvicorn (entrypoint also chowns /app/data + /app/logs
# to match, so bind-mounted files stay editable from the host).
Expand Down
1 change: 1 addition & 0 deletions docker-compose.gpu-nvidia.yml
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ services:
- TAVILY_API_KEY=${TAVILY_API_KEY:-}
- SERPER_API_KEY=${SERPER_API_KEY:-}
- YDC_API_KEY=${YDC_API_KEY:-}
- SOFYA_API_KEY=${SOFYA_API_KEY:-}
# PUID / PGID — the user/group the container drops to before
# running uvicorn (entrypoint also chowns /app/data + /app/logs
# to match, so bind-mounted files stay editable from the host).
Expand Down
1 change: 1 addition & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ services:
- TAVILY_API_KEY=${TAVILY_API_KEY:-}
- SERPER_API_KEY=${SERPER_API_KEY:-}
- YDC_API_KEY=${YDC_API_KEY:-}
- SOFYA_API_KEY=${SOFYA_API_KEY:-}
# PUID / PGID — the user/group the container drops to before
# running uvicorn (entrypoint also chowns /app/data + /app/logs
# to match, so bind-mounted files stay editable from the host).
Expand Down
3 changes: 3 additions & 0 deletions services/search/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
tavily_search,
serper_search,
you_com_search,
sofya_search,
_get_search_settings,
_get_provider_key,
_get_result_count,
Expand Down Expand Up @@ -125,6 +126,8 @@ def _call_provider(provider_name: str, query: str, count: int, time_filter: str
return serper_search(query, count, time_filter)
elif provider_name == "you_com":
return you_com_search(query, count, time_filter)
elif provider_name == "sofya":
return sofya_search(query, count, time_filter)
return []


Expand Down
66 changes: 64 additions & 2 deletions services/search/providers.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"""Search provider implementations: SearXNG, Brave, DuckDuckGo, Google PSE, Tavily, Serper, You.com."""
"""Search provider implementations: SearXNG, Brave, DuckDuckGo, Google PSE, Tavily, Serper, You.com, Sofya."""

import json
import logging
Expand Down Expand Up @@ -27,6 +27,7 @@
# Keyless by default (free agent search); optional YDC_API_KEY upgrades
# to the keyed Search API. needs_key stays False so fresh installs work.
"you_com": ("You.com", False, False),
"sofya": ("Sofya", True, False),
"disabled": ("Disabled", False, False),
}

Expand Down Expand Up @@ -67,6 +68,7 @@ def _get_provider_key(provider: str) -> str:
"tavily": "tavily_api_key",
"serper": "serper_api_key",
"you_com": "ydc_api_key",
"sofya": "sofya_api_key",
}
field = key_map.get(provider, "")
if field:
Expand All @@ -87,6 +89,7 @@ def _get_provider_key(provider: str) -> str:
"tavily": ("TAVILY_API_KEY",),
"serper": ("SERPER_API_KEY",),
"you_com": ("YDC_API_KEY",),
"sofya": ("SOFYA_API_KEY",),
}
for env_name in env_map.get(provider, ()):
value = (os.environ.get(env_name) or "").strip()
Expand All @@ -108,7 +111,7 @@ def provider_configured(provider: str) -> bool:
"""Configuration readiness only; a configured engine can still fail upstream."""
if provider in {"searxng", "searxng_yep", "duckduckgo", "you_com"}:
return True
if provider not in {"brave", "google_pse", "tavily", "serper"}:
if provider not in {"brave", "google_pse", "tavily", "serper", "sofya"}:
return False
if not _get_provider_key(provider):
return False
Expand Down Expand Up @@ -853,3 +856,62 @@ def you_com_search(query: str, count: Optional[int] = None, time_filter: Optiona
results = _you_com_parse_results(data, count)
logger.info(f"You.com returned {len(results)} results")
return results


# ── Sofya ──

def sofya_search(query: str, count: Optional[int] = None, time_filter: Optional[str] = None) -> List[dict]:
"""Search using Sofya API. Requires search_api_key or SOFYA_API_KEY env var."""
count = count if count is not None else _get_result_count()
api_key = _get_provider_key("sofya") or os.environ.get("SOFYA_API_KEY", "")
if not api_key:
logger.warning("Sofya: no API key configured")
return []

# "snippets" returns the SERP only. Odysseus fetches the pages it wants
# itself, so the full-text "basic" depth would only add latency and cost.
payload = {
"query": query,
"max_results": count,
"search_depth": "snippets",
}
if time_filter in ("day", "week", "month", "year"):
payload["freshness"] = time_filter

try:
response = httpx.post(
"https://sofya.co/v1/search",
json=payload,
headers={"Authorization": f"Bearer {api_key}", "Content-Type": "application/json"},
timeout=REQUEST_TIMEOUT,
)
if response.status_code == 429:
raise RateLimitError("Sofya rate limit hit")
response.raise_for_status()
except httpx.RequestError as e:
error_logger.error(f"Sofya search failed: {e}")
return []
except RateLimitError as e:
error_logger.error(str(e))
return []

try:
data = response.json()
except json.JSONDecodeError as e:
error_logger.error(f"Sofya returned invalid JSON: {e}")
return []

results = []
for item in data.get("results", [])[:count]:
url = item.get("url", "")
if not url:
continue
results.append({
"title": item.get("title") or "",
"url": url,
"snippet": item.get("description") or item.get("content") or "",
"age": item.get("published_date") or "",
})

logger.info(f"Sofya returned {len(results)} results")
return results
2 changes: 1 addition & 1 deletion specs/search.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ Research provider naming is not fully normalized in the UI: some frontend select

`services/search/service.py` owns `SearchService`, the async facade exported by `services.search` and `services`. It wraps the synchronous comprehensive search path off the event loop and maps route-style output into service result rows.

`services/search/providers.py` owns provider-specific calls for SearXNG, Brave, DuckDuckGo, Google PSE, Tavily, Serper, and You.com. `PROVIDER_INFO`, provider availability, missing-key behavior, and provider dispatch live there.
`services/search/providers.py` owns provider-specific calls for SearXNG, Brave, DuckDuckGo, Google PSE, Tavily, Serper, You.com, and Sofya. `PROVIDER_INFO`, provider availability, missing-key behavior, and provider dispatch live there.

`services/search/query.py` owns query enhancement and sanitization, including stripping markdown/code-fence noise from model- or user-supplied queries before provider calls and extracting Unicode/non-ASCII capitalized entity names. `services/search/ranking.py` owns result ranking, including word-boundary title/snippet/subject matching so short query terms do not match unrelated substrings.

Expand Down
3 changes: 2 additions & 1 deletion src/agent_tools/admin_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -535,7 +535,8 @@ async def do_manage_settings(content: str, owner: Optional[str] = None) -> Dict:
# so API keys never flow through chat. User sets these in the panel.
_SECRET_KEYS = {
"brave_api_key", "google_pse_key", "google_pse_cx",
"tavily_api_key", "serper_api_key", "ydc_api_key", "app_public_url",
"tavily_api_key", "serper_api_key", "ydc_api_key", "sofya_api_key",
"app_public_url",
}
def _is_secret(k):
# `token` must be a suffix, not a substring: otherwise the int
Expand Down
4 changes: 3 additions & 1 deletion src/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,8 @@ def _invalidate_caches():
# Google PSE safe=active (omitted for "off"; PSE has no middle tier)
# Serper.dev safe=active (omitted for "off"; proxies Google's `safe`)
# You.com safesearch=off/moderate/strict
# Providers NOT touched: Tavily (no SafeSearch knob; filters at index time)
# Providers NOT touched: Tavily (no SafeSearch knob; filters at index time),
# Sofya (no SafeSearch knob)
# and any custom backend reached via search_url — they keep whatever the
# backend itself decides, so operators stay in control of self-hosted /
# niche search instances.
Expand All @@ -103,6 +104,7 @@ def _invalidate_caches():
"tavily_api_key": "",
"serper_api_key": "",
"ydc_api_key": "",
"sofya_api_key": "",
"research_endpoint_id": "",
"research_model": "",
"research_search_provider": "",
Expand Down
2 changes: 2 additions & 0 deletions static/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -1844,6 +1844,7 @@ <h2><svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentC
<option value="tavily" data-search-logo="tavily">Tavily</option>
<option value="serper" data-search-logo="serper">Serper.dev</option>
<option value="you_com" data-search-logo="you_com">You.com (free, optional key)</option>
<option value="sofya" data-search-logo="sofya">Sofya</option>
<option value="disabled" data-search-logo="disabled">Disabled</option>
</select>
<button type="button" class="admin-btn-sm" id="set-searchTestBtn" title="Run a test query against the configured provider" style="margin-left:2px;flex-shrink:0;position:relative;top:2px;display:inline-flex;align-items:center;gap:4px;">
Expand Down Expand Up @@ -1906,6 +1907,7 @@ <h2><svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentC
<option value="google" data-search-logo="google_pse">Google</option>
<option value="serper" data-search-logo="serper">Serper</option>
<option value="you_com" data-search-logo="you_com">You.com</option>
<option value="sofya" data-search-logo="sofya">Sofya</option>
</select>
</div>
<div class="settings-row">
Expand Down
2 changes: 1 addition & 1 deletion static/js/cookbookRunning.js
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ function _redactCrashReportText(text) {
.replace(/\b(sk-[A-Za-z0-9_-]{16,})\b/g, '[redacted-api-key]')
.replace(/\b(xox[baprs]-[A-Za-z0-9-]{16,})\b/g, '[redacted-slack-token]')
.replace(/\b(AIza[0-9A-Za-z_-]{20,})\b/g, '[redacted-google-key]')
.replace(/\b((?:HF_TOKEN|HUGGING_FACE_HUB_TOKEN|OPENAI_API_KEY|ANTHROPIC_API_KEY|BRAVE_API_KEY|TAVILY_API_KEY|SERPER_API_KEY|YDC_API_KEY|GOOGLE_API_KEY|API_KEY|TOKEN|PASSWORD)\s*=\s*)(['"]?)[^\s'"\\]+/gi, '$1$2[redacted]')
.replace(/\b((?:HF_TOKEN|HUGGING_FACE_HUB_TOKEN|OPENAI_API_KEY|ANTHROPIC_API_KEY|BRAVE_API_KEY|TAVILY_API_KEY|SERPER_API_KEY|YDC_API_KEY|SOFYA_API_KEY|GOOGLE_API_KEY|API_KEY|TOKEN|PASSWORD)\s*=\s*)(['"]?)[^\s'"\\]+/gi, '$1$2[redacted]')
.replace(/\b(--(?:api-key|token|hf-token|password)\s+)([^\s]+)/gi, '$1[redacted]');
}

Expand Down
2 changes: 1 addition & 1 deletion static/js/research/panel.js
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,7 @@ export function closePanel() {
}

function _buildPanelHTML() {
const searchProviders = ['', 'searxng', 'duckduckgo', 'tavily', 'brave', 'google', 'serper', 'you_com'];
const searchProviders = ['', 'searxng', 'duckduckgo', 'tavily', 'brave', 'google', 'serper', 'you_com', 'sofya'];
const providerOpts = searchProviders.map(p =>
`<option value="${p}">${p || 'Default'}</option>`
).join('');
Expand Down
2 changes: 1 addition & 1 deletion static/js/search.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export function getCurrentProvider() {
const _labels = {
searxng: 'SearXNG', brave: 'Brave', duckduckgo: 'DuckDuckGo',
google_pse: 'Google', tavily: 'Tavily', serper: 'Serper',
you_com: 'You.com', disabled: 'search (disabled)',
you_com: 'You.com', sofya: 'Sofya', disabled: 'search (disabled)',
};

export function getProviderLabel() {
Expand Down
1 change: 1 addition & 0 deletions static/js/searchProviderIcons.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 5 additions & 3 deletions static/js/settings/searchProviders.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,24 +18,25 @@ var _searchProviderHints = {
tavily: 'AI-optimized search. 1,000 free credits/month at ' + _LINK('https://tavily.com/', 'tavily.com'),
serper: 'Google results via API. 2,500 free queries at ' + _LINK('https://serper.dev/', 'serper.dev'),
you_com: 'Works with no key, but keyless requests are subject to usage limits and Deep Research can consume multiple requests. Optional API key from ' + _LINK('https://you.com/platform?utm_source=odysseus-dev-odysseus&utm_medium=oss_integration&utm_campaign=2026-10-oss-integrations&utm_content=settings', 'you.com/platform') + ' for higher limits.',
sofya: 'Search API for agents. Free credits at ' + _LINK('https://sofya.co/', 'sofya.co'),
disabled: 'Web search and deep research tools will be unavailable.',
};

var _searchNeedsKey = { brave: 1, google_pse: 1, tavily: 1, serper: 1 };
var _searchNeedsKey = { brave: 1, google_pse: 1, tavily: 1, serper: 1, sofya: 1 };

// Optional key: show the key field but do not treat a missing key as misconfigured.
var _searchOptionalKey = { you_com: 1 };

var _searchLabels = {
searxng: 'SearXNG', duckduckgo: 'DuckDuckGo', brave: 'Brave Search',
google_pse: 'Google PSE', tavily: 'Tavily', serper: 'Serper',
you_com: 'You.com', disabled: 'Disabled',
you_com: 'You.com', sofya: 'Sofya', disabled: 'Disabled',
};

var _searchKeyFields = {
brave: 'brave_api_key', google_pse: 'google_pse_key',
tavily: 'tavily_api_key', serper: 'serper_api_key',
you_com: 'ydc_api_key',
you_com: 'ydc_api_key', sofya: 'sofya_api_key',
};

export async function initSearchSettings() {
Expand Down Expand Up @@ -73,6 +74,7 @@ export async function initSearchSettings() {
else if (prov === 'tavily') keyInput.placeholder = 'Tavily API key';
else if (prov === 'serper') keyInput.placeholder = 'Serper API key';
else if (prov === 'you_com') keyInput.placeholder = 'YDC_API_KEY (optional)';
else if (prov === 'sofya') keyInput.placeholder = 'Sofya API key';
else keyInput.placeholder = 'API key';
loadKeyForProvider(prov);
}
Expand Down
1 change: 1 addition & 0 deletions tests/test_search_config_provider_key.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"GOOGLE_API_KEY",
"TAVILY_API_KEY",
"SERPER_API_KEY",
"SOFYA_API_KEY",
)


Expand Down
5 changes: 5 additions & 0 deletions tests/test_search_provider_json.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ def _offline(monkeypatch):
monkeypatch.setenv("DATA_BRAVE_API_KEY", "k")
monkeypatch.setenv("TAVILY_API_KEY", "k")
monkeypatch.setenv("SERPER_API_KEY", "k")
monkeypatch.setenv("SOFYA_API_KEY", "k")
monkeypatch.setenv("GOOGLE_API_KEY", "k")
monkeypatch.setenv("GOOGLE_PSE_CX", "cx")
monkeypatch.setenv("YDC_API_KEY", "k")
Expand All @@ -51,6 +52,10 @@ def test_serper_malformed_json_returns_empty():
assert providers.serper_search("hello") == []


def test_sofya_malformed_json_returns_empty():
assert providers.sofya_search("hello") == []


def test_google_pse_malformed_json_returns_empty():
assert providers.google_pse_search("hello") == []

Expand Down
Loading