Repository navigation
Conversation
There was a problem hiding this comment.
Hey - I've found 1 issue
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="941-943" />
<code_context>
data=AgentResponseData(chain=llm_resp.result_chain),
)
- elif llm_resp.completion_text:
+ elif llm_resp.completion_text and (
+ not llm_resp.tools_call_name or llm_resp.completion_text.strip()
+ ):
+ # A whitespace-only preamble carries no information. When tool
+ # calls follow, skip it so no empty message reaches the respond
</code_context>
<issue_to_address>
**issue (broader_impact):** The whitespace-only preamble is still yielded when the provider stores the response in `result_chain`, because the preceding `if llm_resp.result_chain` branch bypasses this new `completion_text` condition. Providers such as OpenAI populate `result_chain` for text responses, so the regression remains on those adapters and the new tests do not cover their representation.
**Triggers:** When a tool-calling response contains whitespace-only text in a non-empty `result_chain`.
**Suggested fix:** Apply the whitespace check to the `result_chain` path as well, while retaining chains that contain meaningful non-text content.
</issue_to_address>Sourcery assessment
Approval pending. 1 finding to address first.
Blocking findings: astrbot/core/agent/runners/tool_loop_agent_runner.py:943
|
Confirmed and fixed in 613a098. The non-streaming OpenAI path wraps the reply into Two regression tests added: a blank-text-only chain with tool calls produces no intermediate
|
When a model returns a response that is only whitespace plus tool calls, the runner yielded it as an intermediate llm_result, and the respond stage then logged "Prepare to send" followed by "The message is empty; skipping" for a message that was never worth sending. Treat the preamble as empty in that case so nothing reaches the respond stage; a real preamble and a whitespace final reply are both untouched. Refs AstrBotDevs#10236
Providers that wrap the reply text in result_chain (e.g. OpenAI's non-streaming path builds MessageChain from completion_text) bypassed the completion_text guard, so the whitespace-only preamble still reached the respond stage on those adapters. A chain of only blank Plain components now gets the same skip; chains carrying any non-Plain component are untouched.
613a098 to
d315d17
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 whitespace-preamble rows and master's test_context_token_limit_is_isolated_per_run. Kept both, and restored the @pytest.mark.asyncio decorator that the conflict split had taken off master's test. Master's copy of that test is not ruff format clean and CI runs `ruff format --check .` over the tree, so the block is formatted here. Nothing else in the file moved. Verification on this merge: tests/test_tool_loop_agent_runner.py 65/65, ruff check, ruff format and pyupgrade clean on the file. Full tests/ is 5308 passed, 14 skipped, with the same 2 failures in test_fastapi_v1_dashboard.py::test_config_update_revokes_only_affected_shell_sessions that fail identically on pristine origin/master (a6c2b31).
|
Merged Same shape as #10303: the only conflict was in Master's copy of that test is not Verification on this merge,
Pushing re-requested review, so the earlier approval needs re-stamping. |
…0261110 # Conflicts: # astrbot/core/agent/runners/tool_loop_agent_runner.py # tests/test_tool_loop_agent_runner.py
Signed-off-by: Yufeng He <40085740+he-yufeng@users.noreply.github.com>
Signed-off-by: Yufeng He <40085740+he-yufeng@users.noreply.github.com>
|
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
|
Merged current The main branch now assembles typed output components rather than yielding the old native fragments. The whitespace guard is preserved in that flow for both Ruff check, production Ruff format, |
|
@Soulter @RC-CHN Could you review A whitespace-only tool preamble should not be emitted as visible assistant content before the tool call. The patch skips that empty preamble while preserving meaningful text and the tool call itself. Could you check both foreground and background tool execution so the runner does not produce an empty user-visible turn or suppress a real explanation? |
Refs #10236. Whitespace-only text before tool calls should not produce an empty intermediate message. Meaningful preambles, non-text content, and final replies remain intact.
Modifications / 改动点
completion_textand text-onlyresult_chain, preserving chains with non-text components.MessageCompleted,PlainOutput, andExtensionOutput. The media control verifies the platform namespace and retainedqqvalue, not just the existence of an event.The latest test-only update is
eec158e94984. The production whitespace behavior is unchanged by these updates. The original four CI failures came from tests still filtering the retiredllm_resultevent after the native-event migration. After that adaptation, all three Python 3.12 CI jobs exposed one additional assertion mismatch: numeric-string mentions are coerced to integers by the Pydantic v1 component model used on Python <3.14, whereas Python 3.14 uses Pydantic v2 and preserves the string. The media fixture now uses integer123explicitly and checks the exactAtname and retained integer value on both paths.Screenshots or Test Results / 运行截图或测试结果
On the original PR head
5ead047ea012, all four preamble tests fail locally with the same empty-event assertions as hosted CI. With the event assertions updated:Ruff check, Ruff format check, and
git diff --checkpass for the touched file. Validation used Python 3.14 with the worktree's source and an existing same-project environment; no dependencies were installed.The complete local
tests/run returned5454 passed, 38 skipped, 11 failed. All 11 failures were rerun with the original PR test file restored and failed identically. They concern existing dashboard session revocation, dependency-version behavior, Python 3.14 file-URI handling, and filesystem fixtures; this update does not alter those paths. The fixed test file was restored byte-for-byte afterward. This is not a claim that the full local suite passed. Fresh hosted checks remain the cross-platform gate.Checklist / 检查清单
Summary by Sourcery
Prevent whitespace-only tool-call preambles from producing empty intermediate messages while preserving meaningful and non-text content.
Bug Fixes:
Tests: