Repository navigation
Conversation
There was a problem hiding this comment.
Hey - I've found 3 issues
Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments
### Comment 1
<location path="astrbot/core/agent/runners/tool_loop_agent_runner.py" line_range="951-954" />
<code_context>
+ logger.warning(
+ "LLM finished with an empty final response; asking for the answer once more."
+ )
+ self.run_context.messages.append(
+ Message(role="user", content=self.EMPTY_FINAL_REPAIR_PROMPT)
+ )
+ return
await self._complete_with_assistant_response(llm_resp)
</code_context>
<issue_to_address>
**issue (bug_risk):** When the first empty final occurs during the forced final step after `step_until_done` exhausts its budget, this branch appends the repair prompt and returns, but `step_until_done` performs no subsequent step, leaving the runner in `RUNNING` rather than `DONE` and yielding no final answer.
**Triggers:** When the run reaches `max_step` immediately before producing an empty final.
**Suggested fix:** Let the forced-final path execute the one allowed empty-final repair step and, if needed, its retry, or finalize the run after the forced step when the repair cannot be scheduled.
</issue_to_address>
### Comment 2
<location path="astrbot/core/agent/runners/tool_loop_agent_runner.py" line_range="938-941" />
<code_context>
+ # delivered its reply through send_message_to_user in this run.
+ # Otherwise (empty completion, or reasoning with no answer text) the
+ # user would see silence, so ask for the answer once before finishing.
+ has_media = bool(llm_resp.result_chain) and any(
+ not isinstance(comp, Plain) for comp in llm_resp.result_chain.chain
+ )
+ if (
+ not (llm_resp.completion_text or "").strip()
+ and not has_media
</code_context>
<issue_to_address>
**issue (broader_impact):** The new media/empty-final guard does not cover the `skills_like` re-query path, whose `_has_meaningful_assistant_reply` check considers only text; a media-only re-query response is therefore treated as unusable and triggers an unnecessary repair request instead of being accepted as the final answer.
**Triggers:** When `tool_schema_mode` is `skills_like` and the re-query returns a final containing media but no text.
**Suggested fix:** Make `_has_meaningful_assistant_reply` recognize non-empty media result chains, or route the re-query result through the same media-aware final-response predicate.
</issue_to_address>
### Comment 3
<location path="astrbot/core/agent/runners/tool_loop_agent_runner.py" line_range="1456-1460" />
<code_context>
+ has_media = bool(llm_resp.result_chain) and any(
+ not isinstance(comp, Plain) for comp in llm_resp.result_chain.chain
+ )
+ if (
+ not (llm_resp.completion_text or "").strip()
+ and not has_media
</code_context>
<issue_to_address>
**issue (bug_risk):** A successful `send_message_to_user` call targeting another session sets `_delivered_via_message_tool` and suppresses the repair for the current run, even though the current user received no message and still sees silence.
**Triggers:** When `send_message_to_user` is invoked with a `session` argument for a different session.
**Suggested fix:** Set the guard only when the tool successfully sends to the current run's session, using the tool arguments and the current session identity.
</issue_to_address>Sourcery assessment
Approval pending. 3 findings to address first.
Blocking findings: astrbot/core/agent/runners/tool_loop_agent_runner.py:954, astrbot/core/agent/runners/tool_loop_agent_runner.py:941, astrbot/core/agent/runners/tool_loop_agent_runner.py:1460
|
All three findings checked out against the code; fixed in d318356.
Regression tests added for each: forced-final repair completes the run (5 calls, one repair prompt, final answer delivered), cross-session send still repairs, media-only re-query stops at the second call.
|
When a run ends with no tool calls and no user-visible content (an empty completion, or reasoning with no answer text), the runner marked the run DONE and yielded nothing, so the respond stage skipped delivery and the user saw silence. Tool-dense runs hit this whenever the model answers empty right after the last tool result (AstrBotDevs#10298). The provider layer only raises EmptyModelOutputError when a response has no text, no reasoning, and no tool calls, so a reasoning-only final slips through; and the plain tool-loop path had no guard for the shape (the skills_like re-query path already repairs exactly this). Append an EMPTY_FINAL_REPAIR_PROMPT user message and run one more step before completing. Guards: at most one repair per run; no repair when the model already delivered through send_message_to_user this run; a final carrying media but no text still counts as a real answer. Refs AstrBotDevs#10298
…-session sends Three follow-ups from review: - An empty final on the forced last step (after max_step) scheduled the one-shot repair and returned, but no further step was driven, leaving the run in RUNNING with no answer. step_until_done now drives that single repair step. - A successful send_message_to_user aimed at another session no longer suppresses the empty-final repair for the current run; only sends to the run's own session count as delivered, and an unverifiable target counts as elsewhere so the repair still fires. - The skills_like re-query check now treats a media-only reply as a real answer, matching the main final path, instead of firing the stronger-instruction retry.
d318356 to
92fbbb6
Compare
The only conflict was in tests/test_tool_loop_agent_runner.py, and both sides were purely additive where the base was empty: this branch's empty-final repair tests and master's test_context_token_limit_is_isolated_per_run. Kept both. Master's copy of that test was not ruff-format clean, and CI runs `ruff format --check .` over the whole tree, so the block is formatted here. Nothing else in the file moved. Verification on this merge: tests/test_tool_loop_agent_runner.py 68/68, ruff check and ruff format clean. Full tests/ is 5311 passed, 14 skipped, with 2 failures in test_fastapi_v1_dashboard.py::test_config_update_revokes_only_affected_shell_sessions. Those two fail identically on pristine origin/master (a6c2b31) in a detached baseline worktree, so they are pre-existing and outside this change.
|
Merged The only conflict was in One thing worth flagging: master's copy of that test was not Verification on this merge,
Pushing re-requested review, so the earlier approval needs to be re-stamped. |
…0261110 # Conflicts: # astrbot/core/agent/runners/tool_loop_agent_runner.py
|
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
|
Merged current The import conflict now keeps both Local Ruff check, production Ruff format, |
|
@Soulter @RC-CHN Could you review A run that would otherwise end with no user-visible answer should ask once for a final response, not repeatedly re-enter the tool loop or fabricate a completion. Could you check the single-request boundary and what happens if that follow-up also returns no answer? The intended behavior is one bounded recovery attempt while preserving the original run state. |
What
When a run ends with no tool calls and no user-visible content (an empty completion, or reasoning with no answer text), the runner marked the run DONE and yielded nothing, so the respond stage skipped delivery and the user saw silence. Tool-dense runs hit this whenever the model answers empty right after the last tool result; #10298 reports it on every
transfer_to_*delegation with kimi-k3.Two layers let the shape through today:
EmptyModelOutputErrorwhen a response has no text, no reasoning, and no tool calls, so a reasoning-only final is parsed as a valid response with emptycompletion_text;_complete_with_assistant_response+ nollm_resultyielded), while the skills_like re-query path already has a repair retry for exactly this "no tool calls and no usable reply" shape.Fix
Before finalizing an empty, tool-less response, ask for the answer once: append an
EMPTY_FINAL_REPAIR_PROMPTuser message and run one more step. Guards that keep intentional silences intact:send_message_to_userthis run (its empty final is deliberate);Tests
Four new cases in
tests/test_tool_loop_agent_runner.py: empty final after tool work is repaired once and the repaired answer reachesllm_result; a second empty answer finishes quietly with exactly one repair attempt; empty final aftersend_message_to_useris left silent; media-only final is left alone. Red-green checked: the repair tests fail without the runner change.Local run:
pytest tests/, 3635 passed, 2 failed intest_config_update_revokes_only_affected_shell_sessions, which fail identically on clean master (pre-existing, unrelated).ruff formatandruff checkclean.Refs #10298
Summary by Sourcery
Prevent tool-loop runs from ending silently by requesting one final answer when no user-visible response was delivered.
Bug Fixes:
Enhancements:
Tests: