Skip to content

feat(websearch): add SpecStream search and page extraction - #11037

Closed
Specstreamai wants to merge 3 commits into
AstrBotDevs:masterfrom
Specstreamai:feat/specstream-search
Closed

Specstreamai wants to merge 3 commits into
AstrBotDevs:masterfrom
Specstreamai:feat/specstream-search

Conversation

@Specstreamai

@Specstreamai Specstreamai commented Nov 7, 2026 •

Copy link
Copy Markdown

SpecStream's search API is the most accurate web search API in the world. It leads WideSearch at 60.9 and SimpleQA Verified at 99, ahead of Parallel, Exa, Tavily and Perplexity: https://specstream.ai/benchmarks

I work on SpecStream.

This adds SpecStream as a web search provider, next to Tavily, Exa, DeepSeek and the others. Title: feat(websearch): add SpecStream search and page extraction.

Modifications / 改动点

The provider follows the DeepSeek provider from #10599: two builtin tools, one key list with rotation and failover, a provider option in the WebUI, i18n, docs, tests.

Endpoints:

  • Search: GET https://api.specstream.ai/v1/web-search?q=<question> with Authorization: Bearer <key>. Price: $5 per 1,000 searches. The API has no result-count parameter, so the tool trims sources locally to count (1 to 50, default 10).
  • Extract: POST https://api.specstream.ai/v1/extract with body {"urls": [url], "format": "markdown"}. Price: $0.80 per 1,000 pages. A page with no text is free.
  • Errors: 401 for a missing or invalid key and 402 for an empty balance rotate to the next configured key. Any other non-200 status, including 503, raises.
  • Docs: https://specstream.ai/docs/search-api and https://specstream.ai/docs/extract-api

Tools (provider value specstream, key list provider_settings.websearch_specstream_key):

  • web_search_specstream: maps each entry of data.sources to a result (title, url, snippet) and returns the same indexed JSON payload as the other providers, so <ref> citations work.
  • specstream_extract_web_page: takes one HTTP or HTTPS URL, returns URL, Title and Markdown Content. A page status other than ok, or an empty text, returns an error that names the status.

Files:

  • astrbot/core/tools/web_search_tools.py: the two tools, _SPECSTREAM_KEY_ROTATOR, _SPECSTREAM_RETRYABLE_HTTP_STATUSES, tool config, WEB_SEARCH_TOOL_NAMES, __all__
  • astrbot/core/astr_main_agent/web_search.py: provider branch and citation tool name
  • astrbot/core/config/default.py: default key list, provider option, label, subtitle, key field
  • astrbot/dashboard/services/chat_service.py and astrbot/dashboard/services/live_chat_service.py: web_search_specstream in the supported refs list
  • dashboard/src/i18n/locales/{en-US,zh-CN,ja-JP,ru-RU}/features/config-metadata.json: label, subtitle, key description and hint
  • docs/en/use/websearch.md, docs/zh/use/websearch.md: provider table row, provider count, extraction note
  • docs/en/dev/astrbot-config.md, docs/zh/dev/astrbot-config.md: default config, provider value, key field
  • Tests: tests/unit/test_web_search_tools.py, tests/unit/test_web_search_refs.py, tests/unit/test_astr_main_agent.py, tests/unit/test_func_tool_manager.py

No new dependencies. No WebUI navigation or layout change; the provider appears in the existing web search provider list.

  • This is NOT a breaking change. / 这不是一个破坏性变更。

Screenshots or Test Results / 运行截图或测试结果

All HTTP is mocked. The tests never call the real API and use no real key. They cover the request shape (URL, query params, headers, body), source mapping and local trimming, citation payload, invalid parameters, missing key, key rotation on 402, a raise on 503, a raise after every key fails with 401, extract success, extract page statuses blocked and empty, and invalid URLs.

Run on Linux with Python 3.12 after uv sync --group dev:

uv run ruff format --check astrbot/core/tools/web_search_tools.py astrbot/core/astr_main_agent/web_search.py astrbot/core/config/default.py astrbot/dashboard/services/chat_service.py astrbot/dashboard/services/live_chat_service.py tests/unit/test_web_search_refs.py tests/unit/test_astr_main_agent.py
7 files already formatted

uv run ruff check astrbot tests/unit/test_web_search_refs.py tests/unit/test_astr_main_agent.py tests/unit/test_func_tool_manager.py
All checks passed!

uv run pytest -q tests/unit/test_web_search_tools.py tests/unit/test_web_search_refs.py tests/unit/test_astr_main_agent.py tests/unit/test_func_tool_manager.py
528 passed, 8 warnings in 156.62s

uv run pytest -q tests/unit/test_web_search_tools.py -k specstream
21 passed, 257 deselected, 1 warning in 20.52s

ruff format and ruff check on tests/unit/test_web_search_tools.py and tests/unit/test_func_tool_manager.py still report lines that are on master today (the AnySearch fake classes and one Q000 single quote at line 1909 of test_web_search_tools.py). I left those lines unchanged. Every line this PR adds in those two files is formatted.

Docs: docs:build finished with build complete in 128.13s. pnpm is not installed on the machine I used, so I ran the same script with bun run docs:build in docs/. The four locale JSON files parse as valid JSON.

I did not run the dashboard in a browser.


Checklist / 检查清单

  • 😊 If there are new features added in the PR, I have discussed it with the authors through issues/emails, etc.
    / 如果 PR 中有新加入的功能,已经通过 Issue / 邮件等方式和作者讨论过。 Not done before this PR. This PR is the proposal.

  • 👀 My changes have been well-tested, and "Verification Steps" and "Screenshots" have been provided above.
    / 我的更改经过了良好的测试,并已在上方提供了“验证步骤”和“运行截图”。

  • 📚 I checked the affected WebUI instructions and screenshots in docs/zh and docs/en against the changed navigation, page structure, and labels, and updated them in this PR (or explained why no documentation update is needed). For renamed, moved, or merged entry points, I included an old entry → new entry mapping in the documentation and changelog.
    / 我已对照变化后的 WebUI 入口、页面结构和术语,核对并在本 PR 中更新 docs/zh 和 docs/en 的相关操作说明与截图(或说明无需更新文档的原因)。入口改名、移动或合并时,已在文档和 changelog 中补充 旧入口 → 新入口 对照。 No entry point is renamed or moved. The provider table and config reference are updated in both languages.

  • 🤓 I have ensured that no new dependencies are introduced, OR if new dependencies are introduced, they have been added to the appropriate locations in requirements.txt and pyproject.toml.
    / 我确保没有引入新依赖库,或者引入了新依赖库的同时将其添加到 requirements.txt 和 pyproject.toml 文件相应位置。

  • 😮 My changes do not introduce malicious code.
    / 我的更改没有引入恶意代码。

Summary by Sourcery

Add SpecStream search and page extraction as a configurable web search provider.

New Features:

  • Add SpecStream as a web search provider with live search and single-page Markdown extraction tools.
  • Expose SpecStream selection and API key configuration in the WebUI with localized metadata.

Enhancements:

  • Support SpecStream API key rotation and failover for authentication and insufficient-balance errors while preserving citation-compatible search results.

Documentation:

  • Document SpecStream configuration, capabilities, pricing, and page extraction in English and Chinese web search and configuration guides.

Tests:

  • Add mocked unit coverage for SpecStream requests, result normalization, citations, validation, extraction failures, and key failover.

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - I've found 1 issue

Prompt for AI Agents
Please address the comments from this code review:

## Individual Comments

### Comment 1
<location path="astrbot/core/tools/web_search_tools.py" line_range="2476-2480" />
<code_context>
+
+        url = kwargs.get("url")
+        try:
+            parsed = urlsplit(url) if isinstance(url, str) else None
+            valid_url = (
+                parsed is not None
+                and parsed.scheme in {"http", "https"}
+                and bool(parsed.hostname)
+            )
+        except ValueError:
</code_context>
<issue_to_address>
**Malformed URLs reach extraction**

When the requested URL contains an invalid port or whitespace, `urlsplit` and the scheme/hostname checks accept URLs with invalid or out-of-range ports, and URLs containing whitespace; the tool sends those URLs to SpecStream, where extraction fails instead of returning the tool's URL-validation error.

Validate the parsed port and reject whitespace before sending the URL, as the DeepSeek extractor does.
</issue_to_address>

Sourcery assessment

Needs a human reviewer. 1 finding to address first, and search and extraction tool calls send requests to SpecStream, which the docs identify as paid; any charges or credits consumed before a rollback cannot be restored by reverting. Usage is limited to deployments that select SpecStream and invoke these tools.

Blocking findings: astrbot/core/tools/web_search_tools.py:2480


Sourcery is free for open source - if you like our reviews please consider sharing them ✨

@Soulter Soulter moved this to In Progress in AstrBot Roadmap Nov 7, 2026
@mantoujun12

Copy link
Copy Markdown
Collaborator

Hi, thanks for putting together a thorough implementation with tests and docs, and for disclosing that you work on SpecStream.

As noted in the PR checklist ("If there are new features added in the PR, I have discussed it with the authors through issues/emails, etc."), adding a new built-in web search provider requires prior discussion and confirmation before opening an implementation PR.

Each built-in search provider adds ongoing maintenance surface across core tools, agent search logic, WebUI settings, i18n, documentation, and tests. Especially when a proposal comes directly from a commercial service team and includes vendor benchmark claims, the maintainers first need to evaluate product fit, user demand, and long-term maintenance cost—or handle commercial placement inquiries—before reviewing code.

Suggested next steps:

  1. Open a feature proposal issue first to discuss whether SpecStream should be added as a built-in web search provider, or reach out to community@astrbot.app for commercial provider integration and partnership inquiries (https://astrbot.app/#/sponsors).
  2. Alternatively, if you want to make SpecStream available to AstrBot users right away without waiting for core integration, it can be published as a standalone AstrBot plugin or MCP server.

Once the maintainers confirm that a built-in integration is wanted, this PR can be revisited. Thanks for understanding!

@Specstreamai

Copy link
Copy Markdown
Author

Thanks for the clear steer. We have written to community@astrbot.app about a built-in provider, and the PR stays as it is until the maintainers say whether they want it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

2 participants