Skip to content

feat(web-search): add Tencent Yuanbao provider - #10745

Open
helo060228 wants to merge 2 commits into
AstrBotDevs:masterfrom
helo060228:feat/yuanbao-web-search
Open

helo060228 wants to merge 2 commits into
AstrBotDevs:masterfrom
helo060228:feat/yuanbao-web-search

Conversation

@helo060228

@helo060228 helo060228 commented Oct 25, 2026 •

Copy link
Copy Markdown

Summary

  • add Tencent Yuanbao SearchPro as a configurable web-search provider
  • support multiple API keys with auth/quota failover and normalize JSON-string pages
  • register the provider in built-in tool injection and add focused tests

Closes #10654

Verification

  • uv run --group dev pytest tests/unit/test_web_search_tools.py tests/unit/test_astr_main_agent.py -q -k 'yuanbao or apply_web_search_tools'
  • uv run ruff check astrbot/core/tools/web_search_tools.py astrbot/core/astr_main_agent.py astrbot/core/config/default.py tests/unit/test_web_search_tools.py tests/unit/test_astr_main_agent.py
  • git diff --check

Summary by Sourcery

Add Tencent Yuanbao web search support with configurable credentials, resilient key failover, and integrated agent and citation handling.

New Features:

  • Add Tencent Yuanbao SearchPro as a configurable web-search provider with tool registration and result citation support.

Enhancements:

  • Support multiple Yuanbao API keys with failover for retryable authentication, quota, and availability errors, and normalize JSON-encoded search pages into standard results.

Tests:

  • Add focused coverage for Yuanbao result parsing, key failover, business errors, tool export, and built-in tool injection.

@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 5 issues

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="351" />
<code_context>
+        }
+        async with aiohttp.ClientSession(trust_env=True) as session:
+            async with session.post(
+                "https://api.wsa.cloud.tencent.com/SearchPro",
+                json=payload,
+                headers=headers,
</code_context>
<issue_to_address>
**Yuanbao requests hit missing endpoint**

The API returns 404 for the unversioned route, so `_yuanbao_search` raises a non-retryable error and Yuanbao searches fail.

Post to `https://api.wsa.cloud.tencent.com/v1/SearchPro`.
</issue_to_address>

### Comment 2
<location path="astrbot/core/tools/web_search_tools.py" line_range="34" />
<code_context>
         "image_search_serpapi",
         "finance_search_serpapi",
         "scholar_search_serpapi",
+        "web_search_yuanbao",
     }
 )
</code_context>
<issue_to_address>
**Yuanbao citations are missing**

When a Yuanbao result is cited in dashboard chat, live chat, web chat, or the deprecated chat view, the hard-coded supported-tool lists in the citation extractors omit `web_search_yuanbao`, so they discard its result indices and users see missing or unresolved citation links.

Add `web_search_yuanbao` to the supported-tool lists in every citation extractor.

Also at `astrbot/core/astr_main_agent.py:177`, `astrbot/core/tools/web_search_tools.py:411-412`.
</issue_to_address>

### Comment 3
<location path="tests/unit/test_astr_main_agent.py" line_range="822" />
<code_context>
+        search_tool = MagicMock(spec=FunctionTool)
+        search_tool.name = "web_search_yuanbao"
+        tool_mgr = MagicMock()
+        tool_mgr.get_builtin_tool.return_value = search_tool
+        mock_context.get_llm_tool_manager.return_value = tool_mgr
+
</code_context>
<issue_to_address>
**Unregistered tool still passes injection test**

When the Yuanbao tool is missing from the builtin-tool registry, in `test_yuanbao_injects_search_tool`, `tool_mgr.get_builtin_tool.return_value = search_tool` (line 822) makes the mock return a tool regardless of registry state, so the assertions pass even though a real lookup would raise and prevent injection.

Use a real tool manager for the lookup, or separately assert that the Yuanbao class is registered.
</issue_to_address>

### Comment 4
<location path="tests/unit/test_web_search_tools.py" line_range="1967" />
<code_context>
+    )
+
+    assert results[0].url == "https://example.com"
+    assert len(session.calls) == 2
+
+
</code_context>
<issue_to_address>
**Quota retry can reuse the same key**

When the quota retry sends the first key again instead of rotating to the second, in `test_yuanbao_search_retries_business_quota_errors`, the fake serves responses by call order and line 1967 checks only the call count; the test passes when both requests use `first-key`, leaving broken key rotation on quota errors undetected.

Assert that the retry request's Authorization header uses `second-key`.
</issue_to_address>

### Comment 5
<location path="astrbot/core/tools/web_search_tools.py" line_range="337" />
<code_context>
+    provider_settings: dict,
+    payload: dict,
+) -> list[SearchResult]:
+    """Call Tencent Yuanbao SearchPro and normalize its JSON-string pages."""
+    keys = provider_settings.get("websearch_yuanbao_key", [])
+    if not keys:
</code_context>
<issue_to_address>
**Yuanbao helper lacks parameter docs**

When the new helper's docstring is checked against the repository's format rule, the docstring omits `Args:` and `Returns:` sections even though the helper accepts parameters and returns results, so it does not follow the required Google format.

Add Google-format `Args:` and `Returns:` sections to the docstring.
</issue_to_address>

Sourcery assessment

Needs a human reviewer. 4 findings to address first, and when Yuanbao is selected, each search query and its bearer API key are sent to Tencent’s SearchPro service; requests already made cannot be undone if that disclosure was unintended. Reverting stops future requests, and the provider is not enabled by this change for users who have not selected it.

Blocking findings: astrbot/core/tools/web_search_tools.py:351, astrbot/core/tools/web_search_tools.py:34, tests/unit/test_astr_main_agent.py:822, tests/unit/test_web_search_tools.py:1967


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

}
async with aiohttp.ClientSession(trust_env=True) as session:
async with session.post(
"https://api.wsa.cloud.tencent.com/SearchPro",

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.

🟠 High · Yuanbao requests hit missing endpoint

The API returns 404 for the unversioned route, so _yuanbao_search raises a non-retryable error and Yuanbao searches fail.

Post to https://api.wsa.cloud.tencent.com/v1/SearchPro.

Prompt for AI agents
In `astrbot/core/tools/web_search_tools.py` at line 351:

**Yuanbao requests hit missing endpoint**

The API returns 404 for the unversioned route, so `_yuanbao_search` raises a non-retryable error and Yuanbao searches fail.

Post to `https://api.wsa.cloud.tencent.com/v1/SearchPro`.

Comment thread astrbot/core/tools/web_search_tools.py
Comment thread tests/unit/test_astr_main_agent.py Outdated
Comment thread tests/unit/test_web_search_tools.py Outdated
Comment thread astrbot/core/tools/web_search_tools.py Outdated
Add web_search_yuanbao to the dashboard, live, and deprecated chat
citation lists. Look up the registered Yuanbao tool in the injection
test, assert quota retries use the second API key, and document
_yuanbao_search.

Co-authored-by: helo060228 <helo060228@users.noreply.github.com>

This branch has not been deployed

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature] 网页搜索提供商添加腾讯元宝搜索支持

2 participants