Repository navigation
Integrate SerpApi Google News API - #10773
Open
magentaqin wants to merge 3 commits into
Open
magentaqin wants to merge 3 commits into
magentaqin wants to merge 3 commits into
Conversation
Contributor
There was a problem hiding this comment.
Hey - I've found 2 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="9" />
<code_context>
from urllib.parse import quote, urlsplit
import aiohttp
+import serpapi
from pydantic import Field
from pydantic.dataclasses import dataclass as pydantic_dataclass
</code_context>
<issue_to_address>
**Installations fail at startup**
When astrBot is installed from requirements.txt rather than resolving dependencies from pyproject.toml, `web_search_tools.py` imports `serpapi` unconditionally, but `requirements.txt` omits it, so startup and smoke-test imports raise `ModuleNotFoundError`.
Add the SerpApi dependency to `requirements.txt` so installations using that manifest can import the search tools.
Also at `pyproject.toml:77`.
</issue_to_address>
### Comment 2
<location path="astrbot/core/tools/web_search_tools.py" line_range="697" />
<code_context>
+ {
+ "title": article.get("title") or "",
+ "url": source_url,
+ "snippet": article.get("snippet") or "",
+ "source": source.get("name") or source.get("title") or "",
+ "authors": source.get("authors") or [],
</code_context>
<issue_to_address>
**News links can hijack the dashboard tab**
When an attacker-controlled publisher URL appears in Google News results and a user clicks its citation, the publisher URL is returned as a citation and the dashboard opens it with `window.open(url, "_blank")` without disabling `window.opener`; a clicked attacker-controlled article can navigate the original AstrBot tab to a phishing page.
Open citation links with `noopener` (and preferably `noreferrer`) or use an anchor with a safe `rel` attribute.
</issue_to_address>Sourcery assessment
Approval pending. 2 findings to address first.
Blocking findings: astrbot/core/tools/web_search_tools.py:9, astrbot/core/tools/web_search_tools.py:697
Soulter
reviewed
Oct 26, 2026
| continue | ||
| raise last_error | ||
| except (aiohttp.ClientError, asyncio.TimeoutError): | ||
| client = serpapi.Client(api_key=api_key, timeout=60) |
Member
There was a problem hiding this comment.
Hi, Thanks for your contribution! Is it possible to make requests to SerpApi directly via the HTTP API? This would avoid the need to include a SerpApi python package, helping to keep the main codebase clean.
Author
There was a problem hiding this comment.
No problem! I just updated the code!
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Modifications / 改动点
Add Google News search support through SerpApi so agents can retrieve current news articles with structured metadata and source links.
news_search_serpapitool backed by the Google News API.Screenshots or Test Results / 运行截图或测试结果
1)automated tests:

2)End-to-end verification
Configured an OpenAI chat model and a SerpApi API key in AstrBot, then sent the following request through the WebUI:
Checklist / 检查清单
😊 If there are new features added in the PR, I have discussed it with the authors through issues/emails, etc.
/ 如果 PR 中有新加入的功能,已经通过 Issue / 邮件等方式和作者讨论过。
👀 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/zhanddocs/enagainst 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 中补充 旧入口 → 新入口 对照。🤓 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.txtandpyproject.toml./ 我确保没有引入新依赖库,或者引入了新依赖库的同时将其添加到
requirements.txt和pyproject.toml文件相应位置。😮 My changes do not introduce malicious code.
/ 我的更改没有引入恶意代码。
Summary by Sourcery
Enable agents to retrieve current, citation-ready news articles through SerpApi Google News.
New Features:
Enhancements:
Documentation:
Tests:
Chores: