Repository navigation
Conversation
📄 Knowledge review✏️ Suggested updates1 page suggestion needs review.
📝 pr4697的改动@@ -1020,7 +1020,7 @@
**重试前回退逻辑**
-修复前,当提供商返回空响应时,系统会立即切换到备用提供商(fallback provider)。修复后,系统会先对同一提供商进行重试,重试失败后再切换备用提供商:
+在主 step 循环中,修复前,当提供商返回空响应时,系统会立即切换到备用提供商(fallback provider)。修复后,系统会先对同一提供商进行重试,重试失败后再切换备用提供商。`skills_like` 参数补全 re-query 的空输出重试采用不同的耗尽处理,见下文「空 completion 异常重试」:
- **重试参数**:
- `EMPTY_OUTPUT_RETRY_ATTEMPTS = 3`:最多重试 3 次
@@ -2039,6 +2039,15 @@
修复前,如果 LLM 在参数补全阶段返回空响应(既无工具调用也无有意义的文本回复),系统会直接失败,导致工具执行流程中断。
+##### 空 completion 异常重试
+初始参数补全 re-query 和强化指令 repair 请求均通过 `_requery_text_chat()` 调用 LLM:
+
+- 仅对 `EmptyModelOutputError` 进行重试,复用 `EMPTY_OUTPUT_RETRY_ATTEMPTS`、`EMPTY_OUTPUT_RETRY_WAIT_MIN_S` 和 `EMPTY_OUTPUT_RETRY_WAIT_MAX_S`,采用指数退避,每次请求最多尝试 3 次(包含首次调用)。
+- 全部尝试均为空输出时,记录警告并返回 `None`,不在此处切换备用提供商,也不因该异常中断整轮 Agent。
+- 初始 re-query 耗尽尝试后,沿用本轮已解析的工具调用及其参数继续执行工具;repair 请求耗尽尝试后,保留 repair 前的响应继续后续处理。
+
+该异常重试与下述针对“无工具调用且无有意义的 assistant 回复”的响应检查不同。
+
##### 两阶段重试机制
PR #7101 在 `tool_loop_agent_runner.py` 的 `_resolve_tool_exec()` 方法中引入了两阶段重试机制:
@@ -2120,10 +2129,10 @@
#### 技术实现要点
##### 重试逻辑集成
-重试逻辑完全集成在 `_resolve_tool_exec()` 方法中,避免影响其他工具模式:
+响应检查逻辑位于 `_resolve_tool_exec()` 方法中,空 completion 异常重试由 `_requery_text_chat()` 处理,避免影响其他工具模式:
- 仅在 `tool_schema_mode == "skills_like"` 时激活
-- 重试条件:无工具调用且无有意义的 assistant 回复
-- 重试次数:最多两次(第一阶段 + 第二阶段)
+- 响应检查条件:无工具调用且无有意义的 assistant 回复
+- 上述两阶段响应检查与 `EmptyModelOutputError` 重试分别处理;初始 re-query 和 repair 请求各自最多尝试 `EMPTY_OUTPUT_RETRY_ATTEMPTS` 次
##### 上下文构建优化
`_build_tool_requery_context()` 方法的增强确保额外指令正确注入: |
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="1579-1582" />
<code_context>
- abort_signal=self._abort_signal,
- request_max_retries=self.request_max_retries,
- )
+ repair_resp = await self._requery_text_chat(
+ repair_contexts, param_subset
)
if repair_resp:
llm_resp = repair_resp
</code_context>
<issue_to_address>
**Original tool call is skipped**
When the initial re-query has no tool call or meaningful reply and every repair attempt returns an empty completion, `_requery_text_chat()` returns `None`, so the guarded assignment leaves `llm_resp` as the no-tool response; `_resolve_tool_exec()` returns it and `step()` completes with an assistant response instead of executing the original parsed tool call.
When repair returns `None`, preserve and return the original tool-call response instead of the earlier no-tool response.
</issue_to_address>Linked issues
#10924 [Bug] skills_like 模式下工具重查询返回空输出会直接中断整轮 Agent,未复用主循环的空输出重试 · 1 of 2 met
| # | Requirement | Status | Notes |
|---|---|---|---|
| 1 | 给两次 requery 调用复用主循环的空输出重试策略 | ✅ Met | Both the initial re-query and the stronger-instruction repair call use _requery_text_chat(), which retries EmptyModelOutputError with the configured attempt count and exponential backoff. |
| 2 | 重试仍全部为空时,沿用上一轮已解析出的工具调用继续执行 | 🟡 Partly met | Exhaustion of the initial re-query preserves the original tool call, but exhaustion of the stronger-instruction repair does not: llm_resp remains the earlier no-tool re-query response, so the caller falls back to an assistant response instead of executing the original tool call. |
Sourcery assessment
Approval pending. 1 finding to address first.
Blocking findings: astrbot/core/agent/runners/tool_loop_agent_runner.py:1582
|
Good catch — addressed in 63179b4. You are right about the root cause. The repair re-query only runs when the first re-query produced neither a tool call nor any reply, and by that point
Added With the fix in place: |
|
The reported failure path looks valid: an However, I don't think we should execute the original tool call when the re-query exhausts its attempts. The first request uses Could we instead report the parameter-generation failure back to the agent so it can decide whether to retry or explain the failure? The exhaustion tests should also cover an original call with empty arguments; the current fixtures supply |
There was a problem hiding this comment.
Linked issues
#10924 [Bug] skills_like 模式下工具重查询返回空输出会直接中断整轮 Agent,未复用主循环的空输出重试 · 1 of 2 met
| # | Requirement | Status | Notes |
|---|---|---|---|
| 1 | Retry empty completions in both skills_like tool re-query calls. | ✅ Met | Both the initial re-query and the repair re-query use _requery_text_chat(), which retries EmptyModelOutputError using the configured attempt count and exponential wait. |
| 2 | When retries are exhausted, continue with the tool call already parsed in the current step. | 🟡 Partly met | Exhaustion no longer propagates an exception, but the parsed tool call is not executed; the runner instead adds a message asking the agent to retry or explain the failure. |
|
Thanks for the schema clarification. Updated in cd9eaaa:
Verification: This remains a current-provider retry fix; fallback-provider switching is outside this patch. |
The skills_like re-query issued its provider request outside the main step loop's EmptyModelOutputError retry/fallback wrapper, so a single empty completion raised out of the runner and aborted the whole Agent run. Route both the parameter re-query and the repair re-query through a helper that retries empty completions with the main loop's timing. When every attempt returns no usable output, return to the step loop with an explicit notice instead of executing the light-schema arguments, which do not carry the real parameter values.
cd9eaaa to
f7b0335
Compare
There was a problem hiding this comment.
Linked issues
#10924 [Bug] skills_like 模式下工具重查询返回空输出会直接中断整轮 Agent,未复用主循环的空输出重试 · 2 of 3 met
| # | Requirement | Status | Notes |
|---|---|---|---|
| 1 | Retry EmptyModelOutputError for both the initial and repair skills_like re-queries using the main loop's retry timing. | ✅ Met | Both re-query call sites use _requery_tool_params(), which applies the configured attempt count and exponential backoff. |
| 2 | Avoid aborting the Agent run when all re-query attempts return empty output. | ✅ Met | On exhaustion, the step appends a failure notice and returns instead of letting EmptyModelOutputError escape. |
| 3 | When retries are exhausted, continue by using the already parsed tool call. | 🟡 Partly met | The runner lets the Agent continue, but skips executing the prior tool call so it can reconsider with complete parameters. |
| ), | ||
| ) | ||
| ) | ||
| return |
There was a problem hiding this comment.
🟡 Medium · Exhaustion skips prior tool call
The issue recommends continuing with the already parsed tool call when all re-query attempts are empty. This change instead appends a notice that no tool was executed and returns, allowing the Agent to reconsider on a later step but not performing the requested fallback.
Prompt for AI agents
In `astrbot/core/agent/runners/tool_loop_agent_runner.py` at line 1217:
**Exhaustion skips prior tool call**
The issue recommends continuing with the already parsed tool call when all re-query attempts are empty. This change instead appends a notice that no tool was executed and returns, allowing the Agent to reconsider on a later step but not performing the requested fallback.From #10924:
When retries are exhausted, continue by using the already parsed tool call.|
Rebased onto On the three requirements above:
Also per that review, the re-query still retries only the current provider and does not switch to a fallback provider mid re-query (the main loop keeps owning provider fallback). Verification on this head (Windows 11 x64, Python 3.12): With the source change reverted, the four new regression tests fail on |
Upstream AstrBotDevs#10077 replaced the standalone re-query request helper with inline loops over _recorded_responses(), so the retry wrapper now wraps that generator and receives the re-query contexts explicitly.
|
Re-fitted onto current #10077 removed the standalone re-query request and inlined both re-queries as loops over
Verified on Windows 11 x64 / Python 3.12: The workflows on this branch are still |
Linked issuesChecked at commit 0361c8a #10924 [Bug] skills_like 模式下工具重查询返回空输出会直接中断整轮 Agent,未复用主循环的空输出重试 · 1 of 2 met
|
…ls-like-requery-empty-output
The skills_like re-query failure notice was appended to run_context.messages directly, so the host conversation record never saw it: every other framework-injected message goes through _append_context_messages, which also emits context.appended. Route it through the helper and assert the event carries the notice.
|
Merged The failure notice was appended with a raw
|
A non-raising empty reply leaves its message.appended staged in _pending_assistant_event. Appending the failure notice first meant the transcript could hold the notice with the reply it explains missing entirely (never flushed in that turn). Flush the pending reply before the notice; it is marked _no_save so it still never enters future context.
|
Second fix pushed ( A non-raising empty reply only stages its
|
Fixes #10924
Modifications / 改动点
astrbot/core/agent/runners/tool_loop_agent_runner.py_requery_tool_params(), which runs a skills_like tool re-query (through_recorded_responses, so request events are still emitted) with the sameEmptyModelOutputErrorretry policy the main step loop already uses (EMPTY_OUTPUT_RETRY_ATTEMPTS+wait_exponential)._resolve_tool_exec()returnsNoneand the step loop appends an explicit notice to the run context. The light-schema tool call is not executed, because those arguments never carried the real parameter values._append_context_messages(), not a rawrun_context.messages.append(...), so it is also emitted ascontext.appendedlike every other framework-injected message — otherwise the host conversation record would never learn that no tool ran._flush_pending_response()). A non-raising empty reply only stages itsmessage.appended, so appending the notice first left the transcript holding an explanation whose reply it explains was missing entirely; the flushed reply keeps_no_save, so it still never enters future context.tests/test_tool_loop_agent_runner.pytest_skills_like_requery_retries_empty_completion— two empty completions, then a valid re-query: the tool runs with the re-queried arguments.test_skills_like_requery_reports_failure_without_executing_light_call— exhaustion reports the failure, executes nothing, and the agent can continue in the next step.test_skills_like_requery_reports_failure_after_empty_repair— the repair attempt also exhausting retries keeps the unvalidated light call out.test_skills_like_requery_reports_failure_after_semantically_empty_repair— an empty non-exception repair reply is still unusable output.test_skills_like_requery_failure_notice_reaches_conversation_sink— the failure notice reaches the conversation sink ascontext.appended, not just the runner'srun_context.messages.test_skills_like_requery_failure_notice_follows_every_recorded_reply— every settled reply reaches the transcript (_no_savefor the unusable one) and the notice lands after it.Why
With
tool_schema_mode = "skills_like"every tool call goes through an extra provider request that re-queries the model for tool parameters. That request had no retry: provider-level retries (request_retry.retry_provider_request) only cover connection errors and HTTP 408/409/429/5xx, soEmptyModelOutputErrorbubbled straight out ofagent_runner.step()intoastr_agent_run_util.run_agent(). A single intermittent empty completion from an OpenAI-compatible provider therefore ended a multi-step task with no reply to the user.Observed completion (SiliconFlow +
deepseek-ai/DeepSeek-V4.1-Flash), notecompletion_tokens=151with every content field empty:The main step loop already retries this and then switches to a fallback provider; the re-query path simply never got the same treatment.
fullschema mode is unaffected because it does no re-query.Related: #7409 reports the same "no usable output" symptom on the main loop path, which already has the retry + fallback that this PR mirrors for the re-query path.
Screenshots or Test Results / 运行截图或测试结果
Merged current
master(2d3384f1d) into the branch. #10077 replaced the standalone re-query request helper with inline loops over_recorded_responses(), so this revision wraps that generator and passes the re-query contexts through it. The later_flush_pending_response()/context.appendedrework is why the failure notice is routed through_append_context_messages()here. Windows 11 x64, Python 3.12.Regression check — with only the retry policy removed (single attempt, everything else unchanged), the three cases that depend on retry fail and the non-exception case still passes, which is the expected split; restoring the retry makes all four pass:
Both transcript regressions fail on their own, one defect reverted at a time:
Reproducing the original failure in a live deployment is timing dependent (it needs the provider to return an empty completion), so the tests drive
ToolLoopAgentRunnerwith a scripted provider that raisesEmptyModelOutputErroron the re-query.Checklist / 检查清单
😊 If there are new features added in the PR, I have discussed it with the authors through issues/emails, etc.
/ 如果 PR 中有新加入的功能,已经通过 Issue / 邮件等方式和作者讨论过。
👀 My changes have been well-tested, and "Verification Steps" and "Screenshots" have been provided above.
/ 我的更改经过了良好的测试,并已在上方提供了“验证步骤”和“运行截图”。
📚 I checked the affected WebUI instructions and screenshots in
docs/zhanddocs/enagainst the changed navigation, page structure, and labels, and updated them in this PR (or explained why no documentation update is needed). For renamed, moved, or merged entry points, I included an old entry → new entry mapping in the documentation and changelog./ 我已对照变化后的 WebUI 入口、页面结构和术语,核对并在本 PR 中更新
docs/zh和docs/en的相关操作说明与截图(或说明无需更新文档的原因)。入口改名、移动或合并时,已在文档和 changelog 中补充 旧入口 → 新入口 对照。🤓 I have ensured that no new dependencies are introduced, OR if new dependencies are introduced, they have been added to the appropriate locations in
requirements.txtandpyproject.toml./ 我确保没有引入新依赖库,或者引入了新依赖库的同时将其添加到
requirements.txt和pyproject.toml文件相应位置。😮 My changes do not introduce malicious code.
/ 我的更改没有引入恶意代码。
Summary by Sourcery
Make skills_like tool parameter re-queries resilient to empty model completions while safely reporting failures without executing incomplete tool calls.
Bug Fixes:
Enhancements:
Tests: