Skip to content

fix: Prevent duplicate web search citation prompts from being repeatedly appended to the system message after multiple tool invocations in a single interaction#8642

Merged
Soulter merged 1 commit into
masterfrom
fix/8414
Jun 7, 2026
Merged

Conversation

@Soulter
Copy link
Copy Markdown
Member

@Soulter Soulter commented Jun 7, 2026

fix: #8414

Modifications / 改动点

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

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.txt and pyproject.toml.
    / 我确保没有引入新依赖库,或者引入了新依赖库的同时将其添加到 requirements.txtpyproject.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:

  • Prevent duplicate web search citation prompts from being appended to the system message during multiple tool runs in a single interaction.

Enhancements:

  • Centralize web search citation prompt injection in the main agent build flow using a shared helper and constant prompt text.

Tests:

  • Add unit tests to verify citation prompt injection only for webchat, idempotency of the helper, and absence on non-webchat platforms.

…dly appended to the system message after multiple tool invocations in a single interaction
@dosubot dosubot Bot added size:M This PR changes 30-99 lines, ignoring generated files. area:core The bug / feature is about astrbot's core, backend labels Jun 7, 2026
@Soulter Soulter merged commit c7e9d5b into master Jun 7, 2026
20 checks passed
Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

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

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.

Comment on lines +118 to +125
WEB_SEARCH_CITATION_TOOL_NAMES = frozenset(
{
"web_search_baidu",
"web_search_tavily",
"web_search_bocha",
"web_search_brave",
}
)
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.

medium

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",
    }
)

Copy link
Copy Markdown
Contributor

@sourcery-ai sourcery-ai Bot left a comment

Choose a reason for hiding this comment

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

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 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.
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`.

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

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

Labels

area:core The bug / feature is about astrbot's core, backend size:M This PR changes 30-99 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] System Prompt 结尾重复追加搜索引用提示词

1 participant