fix: Prevent duplicate web search citation prompts from being repeatedly appended to the system message after multiple tool invocations in a single interaction#8642
Conversation
…dly appended to the system message after multiple tool invocations in a single interaction
There was a problem hiding this comment.
Code Review
This pull request refactors the injection of web search citation prompts. Instead of injecting the citation prompt dynamically inside the on_tool_end hook, it is now injected upfront into the system prompt during the main agent build phase (build_main_agent) if the platform is "webchat" and a web search tool is present. Unit tests have been added to verify this behavior. The reviewer suggested adding web_search_firecrawl to the WEB_SEARCH_CITATION_TOOL_NAMES set to ensure proper citations are also generated for Firecrawl search results.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
| WEB_SEARCH_CITATION_TOOL_NAMES = frozenset( | ||
| { | ||
| "web_search_baidu", | ||
| "web_search_tavily", | ||
| "web_search_bocha", | ||
| "web_search_brave", | ||
| } | ||
| ) |
There was a problem hiding this comment.
The web_search_firecrawl tool is missing from WEB_SEARCH_CITATION_TOOL_NAMES. Since Firecrawl search results also return structured search results with indices (via _search_result_payload), they should also trigger the web search citation prompt on the webchat platform to ensure proper citations are generated.
WEB_SEARCH_CITATION_TOOL_NAMES = frozenset(
{
"web_search_baidu",
"web_search_tavily",
"web_search_bocha",
"web_search_brave",
"web_search_firecrawl",
}
)There was a problem hiding this comment.
Hey - I've left some high level feedback:
- In
_apply_web_search_citation_prompt, you hardcode a single tool name in the tests; consider parameterizing the tests usingWEB_SEARCH_CITATION_TOOL_NAMESso they continue to validate behavior if the set of web search tools changes. - The citation guidance is now a fixed English string; if this needs to support other locales or be customized per deployment, it may be better to source
WEB_SEARCH_CITATION_PROMPTfrom configuration rather than hardcoding it inastr_main_agent.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- In `_apply_web_search_citation_prompt`, you hardcode a single tool name in the tests; consider parameterizing the tests using `WEB_SEARCH_CITATION_TOOL_NAMES` so they continue to validate behavior if the set of web search tools changes.
- The citation guidance is now a fixed English string; if this needs to support other locales or be customized per deployment, it may be better to source `WEB_SEARCH_CITATION_PROMPT` from configuration rather than hardcoding it in `astr_main_agent`.Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
fix: #8414
Modifications / 改动点
Screenshots or Test Results / 运行截图或测试结果
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 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
Ensure web search citation guidance is injected once at agent build time instead of on every tool invocation.
Bug Fixes:
Enhancements:
Tests: