feat(agent): 在每个 LLM 请求前进行不完整工具调用序列的清理

This commit is contained in:
oudecheng 2026-06-16 16:51:40 +08:00
parent edc1a50d1c
commit 416ac047e3

View File

@ -933,6 +933,21 @@ impl AgentLoop {
Some(tool_defs)
};
// Defense-in-depth: sanitize incomplete tool call sequences
// before EVERY LLM request, not just once at process() entry.
// This catches edge cases where compression, persistence races,
// or delta message merging may have introduced orphaned sequences
// that survived the initial sanitization.
let mid_loop_removed =
crate::bus::message::sanitize_incomplete_tool_call_sequences(&mut messages);
if mid_loop_removed > 0 {
tracing::warn!(
iteration = iteration,
removed_count = mid_loop_removed,
"Mid-loop sanitize removed incomplete tool call sequences before LLM request"
);
}
// 过滤超出轮次和数量限制的图片
let filtered_messages = filter_images_by_age_and_count(
&messages,