Skip to content

[Bug]: Agent 陷入工具死循环并丢失上下文变量,导致 NameError 反复出现且忽略用户追问 #7705

@lifein2

Description

@lifein2

What happened / 发生了什么

在使用 WebChat 适配器进行数据分析任务(生成 OLS/GARCH/AR 回归 Excel)时,观察到 Agent 出现严重的逻辑故障,具体表现为以下三点:

高频 NameError 异常:
Agent 在调用 astrbot_execute_python 工具时,将本应完整执行的 Python 脚本错误地拆分为了 20 余个孤立的代码片段。由于该工具每次调用均运行在独立的无状态进程中,后续片段因缺少 import 语句和前期定义的变量(如 wb, np),连续抛出 NameError: name 'wb' is not defined 和 NameError: name 'np' is not defined。

工具调用死循环且无视系统警告:
尽管系统日志反复发出 [SYSTEM NOTICE] Important: you have executed the same tool ... times consecutively 的警告(最高达 23 次),Agent 仍坚持重试相同的策略,未能修正代码片段的完整性,也未切换为直接向用户说明困难的交互模式。

追问消息被静默消费(Follow-up message lost):
在任务执行期间,用户发送了追问消息 “为什么你的python代码迟迟没有结果”。系统日志显示 Captured follow-up message,但随后立即标记为 Follow-up ticket already consumed, stopping processing。Agent 完成最后的代码执行后并未针对该追问生成任何文本回复,导致用户长时间等待后仅看到任务结束。

Reproduce / 如何复现?

向 Bot 发送一个复杂的 Python 开发任务请求,例如:

“请使用 Python 生成 OLS 回归、GARCH(1,1) 模型和 AR(2) 自回归模型的模拟数据,计算回归结果,并生成一个包含三个 Sheet 且带格式的 Excel 文件。”

观察 Agent 调用 astrbot_execute_python 工具的日志。

在 Agent 连续调用该工具 3-5 次仍未完成任务时,作为用户发送追问消息:

“为什么你的代码迟迟没有结果?”

等待 Agent 执行完毕。

AstrBot version, deployment method (e.g., Windows Docker Desktop deployment), provider used, and messaging platform used. / AstrBot 版本、部署方式(如 Windows Docker Desktop 部署)、使用的提供商、使用的消息平台适配器

AstrBot 版本:v4.23.2
部署方式:astrbot launcher
llm:kimi-k2.5
消息平台适配器:webchat (WebChat Adapter)

OS

Windows

Logs / 报错日志

pingtairizhi.txt

Are you willing to submit a PR? / 你愿意提交 PR 吗?

  • Yes!

Code of Conduct

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:coreThe bug / feature is about astrbot's core, backendbugSomething isn't workingfeature:chatuiThe bug / feature is about astrbot's chatui, webchat

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions