feat(web_search): add olostep provider

Adds Olostep (https://www.olostep.com) as an optional web_search backend
using the official olostep Python SDK (client.answers.create()).

Changes:
- pyproject.toml: adds olostep>=0.1.0 optional dependency
- schema.py: adds olostep to provider comment in WebSearchConfig
- web.py: adds _search_olostep() with lazy import and provider branching
- docs/configuration.md: documents Olostep setup under web search config
- tests: unit tests for the new provider

Backward compatible: existing users see no behavior change unless they
opt into provider: "olostep". No hard dependency at runtime path.

Co-authored-by: umerkay <umerkk164@gmail.com>
This commit is contained in:
chengyongru
2026-04-28 19:09:38 +08:00
committed by Xubin Ren
co-authored by umerkay
parent 0053e68423
commit 28f9bbff31
5 changed files with 157 additions and 1 deletions
+57
View File
@@ -119,6 +119,9 @@ class WebSearchTool(Tool):
if provider == "kagi":
api_key = self.config.api_key or os.environ.get("KAGI_API_KEY", "")
return "kagi" if api_key else "duckduckgo"
if provider == "olostep":
api_key = self.config.api_key or os.environ.get("OLOSTEP_API_KEY", "")
return "olostep" if api_key else "duckduckgo"
return provider
@property
@@ -134,6 +137,8 @@ class WebSearchTool(Tool):
provider = self.config.provider.strip().lower() or "brave"
n = min(max(count or self.config.max_results, 1), 10)
if provider == "olostep":
return await self._search_olostep(query, n)
if provider == "duckduckgo":
return await self._search_duckduckgo(query, n)
elif provider == "tavily":
@@ -149,6 +154,58 @@ class WebSearchTool(Tool):
else:
return f"Error: unknown search provider '{provider}'"
async def _search_olostep(self, query: str, n: int) -> str:
try:
from olostep import AsyncOlostep, Olostep_BaseError
except ImportError:
return "Error: olostep package not installed. Run: pip install olostep"
api_key = self.config.api_key or os.environ.get("OLOSTEP_API_KEY", "")
if not api_key:
logger.warning("OLOSTEP_API_KEY not set, falling back to DuckDuckGo")
return await self._search_duckduckgo(query, n)
try:
async with AsyncOlostep(api_key=api_key) as client:
if self.proxy:
transport = getattr(client, "_transport", None)
http_client = getattr(transport, "_client", None)
if transport is not None and isinstance(http_client, httpx.AsyncClient):
await http_client.aclose()
transport._client = httpx.AsyncClient( # type: ignore[attr-defined]
proxy=self.proxy,
headers=dict(http_client.headers),
timeout=http_client.timeout,
limits=httpx.Limits(
max_keepalive_connections=100,
max_connections=200,
),
http2=True,
)
result = await client.answers.create(task=query)
sources = getattr(result, "sources", None) or []
source_lines = []
for i, source in enumerate(sources[:n], 1):
if isinstance(source, dict):
title = source.get("title", "")
url = source.get("url", "")
else:
title = getattr(source, "title", "")
url = getattr(source, "url", "")
if title and url:
source_lines.append(f"{i}. {title}{url}")
elif url:
source_lines.append(f"{i}. {url}")
elif title:
source_lines.append(f"{i}. {title}")
answer_text = getattr(result, "answer", "") or ""
items = [{"title": answer_text or "Olostep answer", "url": "", "content": "\n".join(source_lines)}]
return _format_results(query, items, n)
except Olostep_BaseError as e:
return f"Olostep search error: {type(e).__name__}: {e}"
except Exception as e:
return f"Olostep search error: {type(e).__name__}: {e}"
async def _search_brave(self, query: str, n: int) -> str:
api_key = self.config.api_key or os.environ.get("BRAVE_API_KEY", "")
if not api_key: