[Bug] Agent 执行期间的插话只在「工具结果边界」生效:单次长生成、后处理/发送阶段收不到,且被会话锁排队到整轮结束
Maintainers usually reply within 1 day
Nobody has claimed this yet.
Assessment
- Difficulty
- 5/5
- Estimated time
- Over a week
- Newbie friendliness
- 15/100
- Issue type
- Bug
- Clarity
- Mostly clear
- Activity status
- Active
- Tech stack
- python
- Domain
- ai-infra-agents
Research direction
The turn lock is taken in pipeline/process_stage/method/agent_sub_stages/internal.py around line 239, and follow-up capture sits in pipeline/process_stage/follow_up.py. Injection only happens in agent/runners/tool_loop_agent_runner.py at the tool-result merge points. Reading these shows where a mid-generation message could enter context and how the lock spans post-processing. The issue asks for several design decisions (step-boundary injection, lock scope, group policy), so a maintainer should settle the scope before anyone implements it.
Written by the indexing model from the issue text.
Description
现象
私聊中让 Agent 执行多步任务(连续调用工具,单轮 40–120s)。这期间用户再发消息,会出现以下情况:
-
模型看不到插话:消息已被适配器立刻收到(日志
18:29:52.165),但当前这一轮完全不体现它。实测某次 LLM 调用upstream;dur=48675(48.7s),整个生成期间插话无法进入上下文。 -
插话被静默排队到整轮结束:新消息卡在
InternalAgentSubStage的会话锁session_lock_manager.acquire_lock(event.unified_msg_origin),直到上一条 turn 把 TTS、渲染、分段发送、落库全部做完才拿到锁。实测:18:28:41.417 用户消息 A 到达 18:29:23.535 A 的 agent 循环结束(finish_reason=stop) 18:29:52.227 用户消息 B 到达(A 仍在后处理) 18:29:56.261 B 进入 internal stage("ready to request llm provider") 18:30:03.774 A 的 TTS 超时,降级为文字 18:30:04.025 A 的 pipeline 结束 18:30:04.026 B 才 "acquired session lock for llm request" ← 等待 7.77sA 的 agent 循环在 18:29:23 已结束,B 仍要等到 18:30:04。
-
没有反馈:被捕获或被阻塞的消息不发 typing,也没有「已收到,本轮结束后处理」的回执;核心侧没有日志(本机全量日志中
Captured follow-up出现 0 次),用户无法区分消息丢失和消息在等待。
复现
- 私聊,本地 Agent(
agent_runner.runner_type: local),开启工具,max_steps默认。 - 发一条会触发多步工具调用、单轮 40s 以上的指令(例如「查一下 X,再根据结果写个脚本跑一遍」)。
- 分别尝试:
- (a) 工具循环仍在跑时插话;
- (b) 模型正在单次长生成时插话;
- (c) 工具循环已结束、机器人正在 TTS 或分段发送时插话。
- 观察:(a) 有时有效,插话出现在下一个工具结果后面;(b) 永远无效;(c) 永远无效,且要等整轮结束。
源码证据(v4.29.4 6133541)
-
事件层是并发的,不是收不到 ——
astrbot/core/event_bus.py:73:task = asyncio.create_task(scheduler.execute(event)),无全局队列,也没有按 UMO 入队。 -
排队来自核心会话锁 ——
pipeline/process_stage/method/agent_sub_stages/internal.py:239:async with session_lock_manager.acquire_lock(event.unified_msg_origin):锁覆盖
build_main_agent、agent 循环和_save_to_history,包含后处理与发送,所以释放时间是「整轮结束」而不是「LLM 结束」。 -
插话只注入到工具结果 ——
agent/runners/tool_loop_agent_runner.py:737-741, 1187-1192:content=self._merge_follow_up_notice(content),只拼在ToolCallMessageSegment上;没有在 step 边界追加 user 消息的路径。 -
agent 循环 DONE 后拒绝插话,但 turn 仍持锁 ——
tool_loop_agent_runner.py:704:if self.done() or self._is_stop_requested(): return None -
跨发送者(群聊)不捕获 ——
pipeline/process_stage/follow_up.py:186-188:active_sender_id != sender_id → return None。 -
捕获等待期无反馈 ——
internal.py:203-225:顺序是try_capture_follow_up()→prepare_follow_up_capture()(await ticket.resolved.wait())→ 之后才send_typing()。 -
/stop只停输出,不携带新消息 ——tool_loop_agent_runner.py:117-118, 1560-1600:写死USER_INTERRUPTION_REQUEST="Stop output."/USER_INTERRUPTION_MESSAGE="Output stopped."。
期望行为
- 生成期间的插话应能被模型看到:即使当前没有工具调用,也应在下一个 step 边界(必要时中止当前生成并重跑该 step)把新输入并入上下文,而不是只能等 tool result。
- 插话窗口应覆盖整个 turn:从进入 agent 阶段到 turn 真正结束(含渲染、TTS、发送);或把 TTS 和发送移出会话锁,让锁释放时间接近 LLM 结束时间。
- 用户应能感知:被接纳的插话给出 typing 或简短回执;未被接纳(跨发送者、turn 已结束)应有明确日志或回执,而不是静默排队。
- 群聊多发送者策略要明确:提供「按发送者排队 / 允许 steer 当前 turn」的选项。
- 连发多条可合并:现在按严格序号把 N 条变成 N 个后续 turn,建议支持合并成一条补充输入。
与已有实现 / issue 的关系
- master
630d5cee已有AgentTurn.steer()/AgentSession.steer_turn()(agent/runtime.py:286-311、astr_agent_runtime/session.py:231-252),但注入点仍是 tool result(tool_loop_agent_runner.py:1418-1424)、done后仍拒绝、会话锁仍在(astr_agent_runtime/session.py:60-66)。本 issue 是在已有 steer 上补边界与可观测性,不是从零做功能。 - #9257(closed)曾以「插话功能本身正常」关闭;本 issue 区分「工具循环内的插话」与「长生成、后处理期间的插话」。
- #10722(open)是在途分段不可打断;#8430(open)是会话锁内插件钩子超时。两者与本 issue 不同层。
版本 / 环境
- AstrBot v4.29.4(
6133541,2026-10-31);已核对 master630d5cee(2026-11-14) - Linux systemd,aiocqhttp(QQ),
agent_runner.runner_type: local,streaming_response=true,max_steps=128 - 第三方插件
astrbot_plugin_private_companion仅做 2.2–8s 有界防抖合并,不是排队原因;其private_reply_followup.py注释也复现了「core 只在 tool result 捕获插话」这一限制。
- Dominant language
- Python
- Stars
- 46.9k
- Forks
- 3.6k
- Avg merge
- 1d 6h
- Merged PRs (30d)
- 136
Getting set up
- Ships a Dockerfile or Docker Compose file
- Has a pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from AstrBotDevs/AstrBot
-
[Bug] Sending a Telegram message chain twice duplicates mentionsPossibly taken @123XieC claimed this 5 days ago. Open
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
AstrBotDevs/AstrBot#11125 ·
Maintainers usually reply within 1 day
-
[Bug] Telegram album debounce exceeds the maximum waitPossibly taken @123XieC claimed this 5 days ago. Open
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
AstrBotDevs/AstrBot#11123 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
AstrBotDevs/AstrBot#11034 · 1 comment ·
Maintainers usually reply within 1 day
-
[Bug] OpenAI-compatible Gemini 工具 schema const 导致 400Possibly taken @arccat-114 claimed this 26 days ago. Openbug
Difficulty 2/5 1-3 hours Newbie friendliness 77/100
AstrBotDevs/AstrBot#10720 · 1 comment ·
Maintainers usually reply within 1 day
-
[Bug] Discord slash command sync aborts with KeyError when a plugin handler is defined in a submodulePossibly taken @yuexia5 claimed this 31 days ago. Open
Difficulty 2/5 1-3 hours Newbie friendliness 77/100
AstrBotDevs/AstrBot#10626 · 1 comment ·
Maintainers usually reply within 1 day
All issues in AstrBotDevs/AstrBot
Similar issues
-
ready-for-agent
Difficulty 1/5 1-3 hours Newbie friendliness 79/100
gregwebs/agent-vm-images#216 ·
Maintainers usually reply within 1 day
-
Layout accepts a step threshold of 0 or less, then in-toto-verify crashes with StopIterationPossibly taken @BahaaMattar claimed this today. Open
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
gcivil-nyu-org/team5-mon-fall26#145 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
gcivil-nyu-org/team3-mon-fall26#156 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
antlr/grammars-v4#5220 ·
Maintainers usually reply within 1 day