[Bug] Tool call announcements break role-play immersion
[Bug] Tool call announcements break role-play immersion
问题描述 / Issue Description
当 AstrBot 需要调用工具(如查看历史消息)时,会先说出类似"我先确认一下当前对话状态,再接着回你。"这样的话,这种"旁白式"的表达严重破坏了角色扮演的沉浸感和对话的自然性。
When AstrBot needs to call tools (e.g., checking message history), it announces what it's doing with phrases like "Let me check the conversation state first, then I'll get back to you." This "narrator-style" output significantly breaks role-play immersion and conversational naturalness.
重现步骤 / Steps to Reproduce
- 配置 AstrBot 使用任何 LLM 提供商
- 开始一段对话
- 发送需要 AI 查看历史消息的问题
- 观察 AI 的回复
预期行为 / Expected Behavior
AI 应该静默调用工具,直接呈现结果,就像它天然知道上下文一样自然回复,而不是说出"我先查看一下"、"让我确认一下"等旁白。
AI should silently invoke tools and present results naturally, as if it already knew the context, without announcing actions like "let me check" or "I need to verify."
实际行为 / Actual Behavior
AI 会在调用工具前先说明自己要做什么,例如:
- "我先确认一下当前对话状态,再接着回你。"
- "让我查看一下历史消息。"
- "我需要检查一下之前的内容。"
AI announces its actions before calling tools, such as:
- "Let me check the conversation state first."
- "I need to look at the message history."
- "I'll verify the previous content."
根本原因 / Root Cause
在 astrbot/core/astr_main_agent_resources.py 文件中,系统提示词明确要求 AI 在调用工具前说明目的:
TOOL_CALL_PROMPT_SKILLS_LIKE_MODE = (
"You MUST NOT return an empty response, especially after invoking a tool."
" Before calling any tool, provide a brief explanatory message to the user stating the purpose of the tool call."
" After the tool call is completed, you must briefly summarize the results returned by the tool for the user."
...
)
关键问题:"Before calling any tool, provide a brief explanatory message to the user stating the purpose of the tool call."
建议的修复 / Proposed Fix
修改系统提示词,要求 AI 静默调用工具,不要说出操作过程:
修改前:
" Before calling any tool, provide a brief explanatory message to the user stating the purpose of the tool call."
" After the tool call is completed, you must briefly summarize the results returned by the tool for the user."
修改后:
" When using tools, do not announce what you are doing beforehand (e.g., do not say 'let me check' or 'I will look at')."
" Simply use the tool silently and present the results naturally, as if you already knew the information."
" After the tool call is completed, incorporate the results naturally into your response without explicitly stating that you used a tool."
" Keep the role-play and style consistent throughout the conversation."
同样的问题也存在于 TOOL_CALL_PROMPT 中:
修改前:
"briefly explain the purpose when starting a new type of task, but not before every tool call"
修改后:
"use tools silently without announcing what you are doing (do not say 'let me check' or 'I will look at'); "
"present results naturally as if you already knew the information"
影响范围 / Impact
这个问题影响所有使用 AstrBot 进行角色扮演、对话机器人的场景,尤其是:
- 虚拟角色聊天
- 游戏 NPC
- 客服机器人
- 任何需要自然对话体验的场景
This issue affects all scenarios using AstrBot for role-playing and conversational bots, especially:
- Virtual character chat
- Game NPCs
- Customer service bots
- Any scenario requiring natural conversation experience
环境信息 / Environment
- AstrBot 版本 / Version: 4.26.7
- 复现于多个 LLM 提供商 / Reproduced with multiple LLM providers
相关文件 / Related Files
astrbot/core/astr_main_agent_resources.pyTOOL_CALL_PROMPT(line ~25)TOOL_CALL_PROMPT_SKILLS_LIKE_MODE(line ~33)
标签建议 / Suggested Labels
bug, enhancement, user-experience, immersion
我反而希望他给我回复,但他有时候不回复我只能在提示词里提醒,不回复的话稍微长一点的任务他回复慢了我只能空等
我按当前默认分支 master@6494ac2 复核了提示词注入和 Agent Runner 配置。结合楼上的新反馈,这更适合做成按 Agent 配置的行为选项,不宜把所有场景统一改成静默或统一改成播报。
判断与代码依据
astrbot/core/astr_main_agent_resources.py当前有两套硬编码策略:TOOL_CALL_PROMPT要求“开始一种新任务时简短说明,但不要每次工具调用都说明”;TOOL_CALL_PROMPT_SKILLS_LIKE_MODE要求“每次调用工具前说明目的”。
astrbot/core/astr_main_agent.py::build_main_agent()在工具集非空时,仅根据MainAgentBuildConfig.tool_schema_mode二选一并追加到req.system_prompt。也就是说,工具 schema 的传递方式同时意外决定了用户是否看到进度播报;persona、角色扮演用途和任务耗时都无法选择。astrbot/core/config/agent_runner.py::AGENT_RUNNER_CONFIG_DEFAULTS["local"]["misc"]目前只有max_steps、tool_schema_mode、超时和上下文清理选项,MainAgentBuildConfig也没有独立的播报策略字段。- 当前 PR #9966 只把 skills-like 的“每次工具前播报”放宽成与 full 类似的“新任务类型开始时播报”。这能减少重复旁白,但仍不能满足本 issue 的静默角色扮演诉求;反过来,全局改成静默又会让楼上所述长任务缺少进度反馈。
修改建议
建议把“schema 模式”和“用户可见进度”拆成两个正交配置。在 local runner 的 agent_runner.config.misc 增加例如:
tool_progress_mode = "task" | "silent"
task:仅开始新的任务类型时简短说明,作为默认值,保留长任务的等待反馈;silent:工具调用前不输出操作旁白,最终答复仍自然整合工具结果。
如果维护者确实要保留现有 skills-like 的逐工具播报,也可以使用 "silent" | "task" | "every_tool" 三态;关键是不要再由 tool_schema_mode 隐式决定。
具体接线位置:
- 在
astrbot/core/config/agent_runner.py增加默认值和枚举归一化;在astrbot/core/config/default.py及各语言dashboard/src/i18n/locales/*/features/config-metadata.json增加可见配置说明。 - 在
astrbot/core/pipeline/process_stage/method/agent_sub_stages/internal.py读取该值并传入MainAgentBuildConfig;后台唤醒等直接构造MainAgentBuildConfig的路径也应使用默认值,避免构造点遗漏。 - 在
build_main_agent()中先按tool_schema_mode保留两阶段 schema 相关指令,再独立追加 progress 指令。伪代码可以是:
不要为了 silent 模式删除 skills-like 的“先名称/描述、后参数 schema”和“不要猜参数”等协议要求。req.system_prompt += schema_prompt[tool_schema_mode] req.system_prompt += progress_prompt[tool_progress_mode] silent只禁止“我要查看/让我确认”这类调用前旁白,不应禁止最终回复、必要的错误提示或模型向用户请求缺失参数,否则会把沉浸感问题变成不可诊断的静默失败。
修改后的效果
- 角色扮演配置可选择静默调用工具,用户直接看到自然整合后的结果。
- 长任务/通用助手继续使用 task 模式,开工时有一次可见反馈,不必空等。
- 在 full 与 skills-like 之间切换只影响 token/schema 下发方式,不再意外改变对话体验。
- 默认采用 task(或兼容用的 auto)时,现有用户行为不会突然全部静默;#9966 仍可作为减少逐工具旁白的最小修正,但独立配置才覆盖本 issue 的完整需求。
建议验证
- 在
tests/unit/test_astr_main_agent.py对 full × skills-like × silent/task 做参数化测试:两种 schema 模式保留各自协议,silent 不含调用前播报要求,task 只要求每类任务开始时播报。 - 在
tests/unit/test_agent_runner_config.py覆盖默认值、合法枚举、非法值回退及旧配置迁移。 - 工具集为空时不注入工具提示;有工具时 silent 模式仍要求非空最终响应和自然汇总。
- 用 mock provider 跑一次多工具长任务:task 模式只有任务开始提示,不在每个 tool call 前重复;silent 模式无前置旁白,但工具错误仍对用户可见。
补充另一处来源:技能提示词本身要求模型在调用技能前点名技能。上面讨论的 TOOL_CALL_PROMPT* 覆盖不到这一类播报。
现象
[<T> 16:21:31.155] [Core] [DBUG] [sources.openai_responses_source:363]: response: Response(
model='<模型>',
output=[ResponseOutputMessage(content=[ResponseOutputText(
text='我用<技能名>技能接这份攻略。')]),
ResponseFunctionToolCall(name='astrbot_execute_shell',
arguments={'command': 'cat <astrbot_data>/skills/<skill-name>/SKILL.md', ...})])
[<T> 16:21:43.996] [Core] [INFO] [respond.stage:212]: Prepare to send - <sender>: 我用<技能名>技能接这份攻略。
[<T> 16:21:44.484] [Core] [INFO] [runners.tool_loop_agent_runner:1183]: 使用工具:astrbot_execute_shell,参数:{'command': 'cat <astrbot_data>/skills/<skill-name>/SKILL.md', ...}
[<T> 16:22:09.567] [Core] [INFO] [respond.stage:212]: Prepare to send - <sender>: <实际回复>
播报文本作为一条独立消息先发出去,比技能读取本身还早,然后才是正文。
来源
astrbot/core/skills/skill_manager.py 的 build_skills_prompt(),skill 规则第 5 条(master 73b4fc9 上位于 281 行):
5. **Coordination** — When multiple skills apply, pick the minimal set needed. Announce which skill(s) you are using and why (one short line). Prefer astrbot_* tools when running skill scripts.
由 22bd8d68246942406069c964ff16b933289e23fc(feat: support anthropic skills (#4715),2026-01-28)引入。
这一条不经过 tool_schema_mode,只要请求注入了 skills 块就会被写进系统提示词;而且它要求的不是「说明目的」,是明确点名哪个技能。
建议
把第 5 条的 announce 要求去掉,只保留「选最小技能集」和工具偏好:
5. **Coordination** — When multiple skills apply, pick the minimal set needed. Do not tell the user which skill you are using or that you are using one; just follow it. Prefer astrbot_* tools when running skill scripts.
如果倾向做成配置(即上面提到的 tool_progress_mode 方向),这一条建议跟着该开关走,而不是常开。
@gomico 这个补充成立,我把具体注入点定位了一下,比你描述的还要更"硬"一点:
astrbot/core/skills/skill_manager.py:213 的 build_skills_prompt() 生成的 Skill rules 里,第 5 条直接要求点名:
- Coordination — When multiple skills apply, pick the minimal set needed. Announce which skill(s) you are using and why (one short line).
第 2 条还有配套的半句:
- When to trigger — ... Never silently skip a matching skill — either use it or briefly explain why you chose not to.
这两段都在 skills 自己的 prompt 里,不经过 TOOL_CALL_PROMPT(astr_main_agent_resources.py:27)也不经过 TOOL_CALL_PROMPT_SKILLS_LIKE_MODE(同文件 :37)。所以 @LIghtJUNction 说的"build_main_agent() 按 tool_schema_mode 二选一追加"确实覆盖不到这一类 —— 无论选哪个 prompt,只要 skills 段被注入,点名要求就还在。
由此我觉得这个配置项要成立,至少要同时约束三处注入:两处 TOOL_CALL_PROMPT* + build_skills_prompt 的 rules 2/5。落点跟 @LIghtJUNction 的核对一致:astrbot/core/config/agent_runner.py 的 AGENT_RUNNER_CONFIG_DEFAULTS["local"]["misc"] 目前只有 max_steps、tool_call_timeout 这类字段,没有播报策略位,再经 MainAgentBuildConfig 透传到 skills prompt 构造。
语义上想提一个约束:静默档不应该取消 grounding。build_skills_prompt 第 3 条 Mandatory grounding(执行技能前必须完整读 SKILL.md)是有功能目的的,静默只需要把"点名"从出站消息里去掉 —— 也就是允许进日志/内部推理,但不要产生一条会被发送的 MessageChain。这样 @lq-259 提的长任务进度反馈和角色扮演的静默诉求可以各选各档,不至于互相打架。
验收用例可以直接用 @gomico 这段日志的形态:respond.stage:212 - Prepare to send(播报文本)出现在 tool_loop_agent_runner:1183 - 使用工具 之前,说明播报是作为独立消息发出去的;静默档应该断言这条不产生,而工具照常执行。
两个小问题:
- @LIghtJUNction 提到的 #9966 我在本仓库查
issues/9966和pulls/9966都返回 404,没法确认它当前状态,方便给个链接或说明它是否已废弃吗?如果它只放宽了TOOL_CALL_PROMPT_SKILLS_LIKE_MODE的措辞,上面第三处注入应该还是原样。 - 如果维护者认可"三处注入 + 保留 grounding"这个拆法,我来提 PR。