Conversation
There was a problem hiding this comment.
Hey - I've left some high level feedback:
- In
_save_to_history, whensave_failed_historyis true and the response is otherwise empty, consider adding an explicit debug/info log (e.g., including run status or error reason) to make it clear that a failed/empty run is being intentionally persisted. - The UI config for
provider_settings.save_failed_agent_historyis currently conditioned onagent_runner_type == 'local'; if other runner types also support this behavior, you may want to relax or extend this condition to avoid the option silently not appearing for them.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- In `_save_to_history`, when `save_failed_history` is true and the response is otherwise empty, consider adding an explicit debug/info log (e.g., including run status or error reason) to make it clear that a failed/empty run is being intentionally persisted.
- The UI config for `provider_settings.save_failed_agent_history` is currently conditioned on `agent_runner_type == 'local'`; if other runner types also support this behavior, you may want to relax or extend this condition to avoid the option silently not appearing for them.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 introduces a new configuration option, save_failed_agent_history, which allows the system to save session history even when an agent fails or returns an empty response. The changes include updates to the default configuration, schema definitions, and the internal agent processing logic. However, the current implementation has two significant issues: the new parameter is not passed to _save_to_history in non-Live mode, and existing early-return logic within _save_to_history prevents the function from reaching the new logic when the LLM response is null or the message role is not 'assistant'.
| not llm_response.completion_text | ||
| and not req.tool_calls_result | ||
| and not user_aborted | ||
| and not save_failed_history |
There was a problem hiding this comment.
感谢您的review!您担心的问题确实存在。
当 save_failed_history=True 且 response 为空时,我们之前只是创建了一个空的 LLMResponse 但没有添加到 messages 中保存。
现已修改:在保存失败历史时,会在 messages 中添加一条带有失败标记的 assistant message [Agent run failed. History saved for debugging.],确保下一轮 messages 格式正确。
faf411f to
0068960
Compare
问题描述
目前 Agent 运行失败时(例如 EmptyModelOutputError),本轮记录通常不会写入正式会话历史。这在排查问题和长流程任务失败后希望从断点继续的场景下带来不便。
修复方案
添加
save_failed_agent_history配置项(默认 false),启用后即使 Agent 本轮运行失败,也会将本轮记录保存到会话历史中,包括用户输入、工具调用记录和失败提示。修改内容
internal.py:读取配置并传递给_save_to_history方法_save_to_history方法:添加save_failed_history参数控制空响应时是否保存default.py:添加配置项定义和 UI 元数据Related Issue
Fixes #7620
Summary by Sourcery
Add configurable support for saving the current agent run to conversation history even when the run fails.
New Features:
Enhancements: