fix: resolve EmptyModelOutputError and enhance tool fallback robustness#7375
Open
xmbhjQAQ wants to merge 2 commits intoAstrBotDevs:masterfrom
Open
fix: resolve EmptyModelOutputError and enhance tool fallback robustness#7375xmbhjQAQ wants to merge 2 commits intoAstrBotDevs:masterfrom
xmbhjQAQ wants to merge 2 commits intoAstrBotDevs:masterfrom
Conversation
Log available tools when a specified tool is not found.
Contributor
There was a problem hiding this comment.
Hey - I've left some high level feedback:
- When catching
json.JSONDecodeErrorin_parse_openai_completion, consider logging the tool name and (possibly truncated) arguments in addition to the exception message to make debugging malformed tool arguments easier. - In the tool-not-found branch where you build the error string with all
available_tools, you may want to cap or sort the list to avoid excessively long or unstable error messages in environments with many tools.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- When catching `json.JSONDecodeError` in `_parse_openai_completion`, consider logging the tool name and (possibly truncated) arguments in addition to the exception message to make debugging malformed tool arguments easier.
- In the tool-not-found branch where you build the error string with all `available_tools`, you may want to cap or sort the list to avoid excessively long or unstable error messages in environments with many tools.Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
Contributor
There was a problem hiding this comment.
Code Review
This pull request improves tool error reporting by listing available tools when a requested tool is missing and refactors OpenAI tool call parsing to include JSON decoding error handling. A review comment suggests providing a default empty dictionary for tool arguments to prevent potential crashes if the provider returns null.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Motivation / 改动动机
openai_source.py对工具名进行严格本地校验而导致的EmptyModelOutputError。当本地工具列表与 LLM 状态存在微小同步偏差时,原来的代码会静默丢弃工具调用,导致系统因响应为空而崩溃。 (Fixes [Bug] 执行多步 Function Calling 任务时,经常因 EmptyModelOutputError 导致工作流中断 #7365)Modifications / 改动点
astrbot/core/provider/sources/openai_source.py:_parse_openai_completion中对tools.func_list的强制名称匹配逻辑。解析层现在只负责如实解析响应,将验证工作交给执行层,避免了静默拦截。try...except保护,防止模型输出畸形 JSON 导致程序闪退。astrbot/core/agent/runners/tool_loop_agent_runner.py:Available tools are: ...)。This is NOT a breaking change. / 这不是一个破坏性变更。
Screenshots or Test Results / 运行截图或测试结果
测试验证:
通过诱导 LLM 调用不存在的工具
search_news_online,验证了系统不再崩溃,并且能准确返回可用工具列表:Checklist / 检查清单
/ 如果 PR 中有新加入的功能,已经通过 Issue / 邮件等方式和作者讨论过。
/ 我的更改经过了良好的测试,并已在上方提供了“验证步骤”和“运行截图”。
/ 我确保没有引入新依赖库,或者引入了新依赖库的同时将其添加到
requirements.txt和pyproject.toml文件相应位置。/ 我的更改没有引入恶意代码。
Summary by Sourcery
Improve robustness of tool call handling in OpenAI completions and agent tool loop by avoiding premature filtering and surfacing clearer errors when tools are missing.
Bug Fixes:
Enhancements: