Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion astrbot/core/astr_agent_hooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,12 +94,14 @@ async def on_tool_end(
and isinstance(first_part.content, str)
):
# we assume system part is str
first_part.content += (
citation_prompt = (
"Always cite web search results you rely on. "
"Index is a unique identifier for each search result. "
"Use the exact citation format <ref>index</ref> (e.g. <ref>abcd.3</ref>) "
"after the sentence that uses the information. Do not invent citations."
)
if citation_prompt not in first_part.content:
first_part.content += citation_prompt
Comment on lines +103 to +104
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

直接将 citation_prompt 拼接在 first_part.content 后面可能会导致提示词与原系统提示词内容紧贴在一起(例如 ...assistant.Always cite...),缺乏适当的分隔(如换行符),这会影响 Prompt 的结构和 LLM 的理解效果。

建议在拼接前使用 .rstrip() 清理末尾空白,并统一添加 \n\n 作为分隔符,以确保 Prompt 格式整洁。

Suggested change
if citation_prompt not in first_part.content:
first_part.content += citation_prompt
if citation_prompt not in first_part.content:
first_part.content = first_part.content.rstrip() + "\n\n" + citation_prompt



class EmptyAgentHooks(BaseAgentRunHooks[AstrAgentContext]):
Expand Down
Loading