fix(agent): count repeated tool calls by arguments#7786
fix(agent): count repeated tool calls by arguments#7786RhoninSeiei wants to merge 2 commits intoAstrBotDevs:masterfrom
Conversation
There was a problem hiding this comment.
Hey - I've left some high level feedback:
- The new
tool_args: dict[str, T.Any]assumption in_tool_call_streak_key/_track_tool_call_streakmay be too strict forfunc_tool_args; if callers can pass non-dict structures (e.g., lists orNone), consider typing and handling a broader input type to avoid runtime errors. - The JSON-based fingerprint can become very large for tools with big argument payloads; consider truncating or hashing the serialized args (e.g., using a stable hash of the JSON string) to keep the streak key small and avoid storing or comparing huge strings repeatedly.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- The new `tool_args: dict[str, T.Any]` assumption in `_tool_call_streak_key` / `_track_tool_call_streak` may be too strict for `func_tool_args`; if callers can pass non-dict structures (e.g., lists or `None`), consider typing and handling a broader input type to avoid runtime errors.
- The JSON-based fingerprint can become very large for tools with big argument payloads; consider truncating or hashing the serialized args (e.g., using a stable hash of the JSON string) to keep the streak key small and avoid storing or comparing huge strings repeatedly.Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
There was a problem hiding this comment.
Code Review
This pull request updates the tool call streak tracking logic in tool_loop_agent_runner.py. The tracking mechanism has been refined to consider both the tool name and its arguments by introducing a fingerprinting method, _tool_call_streak_key, which uses JSON serialization to create a unique key for each call. Consequently, the _track_tool_call_streak method and its call sites have been updated to handle these argument-aware keys. I have no feedback to provide.
|
补充更新:根据首轮 Unit Tests 失败结果,已补充测试提交 测试调整内容:保留“同名且同参数连续调用会触发递进提示”的断言,并新增“同名但参数变化时重置连续计数”的断言。当前 head 的 Code Format Check、Unit Tests、CodeQL、Smoke Test、AstrBot Dashboard CI 均已通过。 |
背景
修复 #7784 中提到的问题:连续工具调用提示目前只按工具名称累计。在浏览器批量操作等场景中,连续调用同一个工具但参数持续变化时,系统仍会提示“重复调用过高”,容易干扰正常任务。
修改内容
本次修改将连续调用计数依据从单一工具名扩展为“工具名 + 参数指纹”:
json.dumps(..., sort_keys=True)生成稳定的参数指纹。repr(),避免统计逻辑影响工具执行。验证
astrbot/core/agent/runners/tool_loop_agent_runner.py。Fixes #7784
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 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
Bug Fixes: