Baike.dev
All toolsOnline toolsAI codingTrendingOpen sourceNewsSubmit
Log in
Back to tool/Back to issues
#10239·AstrBot

[Feature] 后台任务失败时补充错误日志,并区分结果摘要的成功/失败措辞

Author: silvalingCreated Sep 26, 2026Updated Sep 27, 2026

功能描述

后台任务(background_task)与子代理(transfer_to_*)执行失败时,目前只有一条被降级成字符串的结果,缺少日志与语义区分。希望补齐以下三点:

  1. 失败时记录日志

    astrbot/core/astr_agent_tool_exec.py:456-459 与 :497-500 两处都是:

    python
    except Exception as e:
        result_text = f"error: Background task execution failed, internal error: {e!s}"

    只赋值给 result_text,没有 logger.error / logger.exception,异常堆栈不落盘。同文件其它失败分支(:610 的 Failed to build main agent for background task、:640 的 background task agent got no response)都有日志,这两处欠缺。

  2. 结果摘要区分成功与失败

    astr_agent_tool_exec.py:627-636 把两句直接相连:

    [BackgroundTask] {summary_name} (task_id=…) finished. Result: {result_text}
    I finished the task, here is the result: {llm_resp.completion_text}

    当任务失败时,第一句是 Result: error: …,第二句仍是子代理的「完成」话术,拼接后中间没有分隔符,读起来是「失败原因 + 一切完成」。建议失败时改用明确的失败措辞,并加换行/分隔。

  3. 失败路径补单测

    tests/unit/test_astr_agent_tool_exec.py 中未覆盖 error: Background task execution failed 这条分支。

使用场景

  • 子代理 provider 未配置:任务在启动阶段即失败,用户侧收不到任何提示。同时日志里查不到该失败的异常记录,只能从对话历史里翻那条被降级的字符串。实际观测到的形态:

    [BackgroundTask] Dedicated to subagent `xxx` (task_id=…) finished.
    Result: error: Background task execution failed, internal error: Provider xxx not found
    I finished the task, here is the result: 本轮无新任务,仅汇总当前状态…

    (provider 名已脱敏)

  • 排障:由于失败分支不打日志,无法用日志确认「任务有没有跑、为什么失败」,只能依赖主 agent 是否主动汇报。

检查清单

  • 我已在 Issue 列表中搜索过相关功能,确认该功能想法从未被提出过。
  • 我建议的功能与 AstrBot 本体相关,而非在建议某一插件的功能。
  • 我已阅读并同意本项目的贡献者行为准则。
  • (可选)我愿意提交 PR 以帮助实现该功能。

以上为 AI 生成内容。

Source: AstrBotDevs/AstrBot

View original on GitHubView discussion on GitHub