Repository navigation
feat(web-search): add Tencent Yuanbao provider - #10745
helo060228 wants to merge 2 commits into
Conversation
There was a problem hiding this comment.
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
| } | ||
| async with aiohttp.ClientSession(trust_env=True) as session: | ||
| async with session.post( | ||
| "https://api.wsa.cloud.tencent.com/SearchPro", |
There was a problem hiding this comment.
🟠 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`.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>
Summary
Closes #10654
Verification
Summary by Sourcery
Add Tencent Yuanbao web search support with configurable credentials, resilient key failover, and integrated agent and citation handling.
New Features:
Enhancements:
Tests: