From 416ac047e3b9c132ab3c83b2f9e76759e6c666bd Mon Sep 17 00:00:00 2001 From: oudecheng <13802883547@139.com> Date: Tue, 16 Jun 2026 16:51:40 +0800 Subject: [PATCH] =?UTF-8?q?feat(agent):=20=E5=9C=A8=E6=AF=8F=E4=B8=AA=20LL?= =?UTF-8?q?M=20=E8=AF=B7=E6=B1=82=E5=89=8D=E8=BF=9B=E8=A1=8C=E4=B8=8D?= =?UTF-8?q?=E5=AE=8C=E6=95=B4=E5=B7=A5=E5=85=B7=E8=B0=83=E7=94=A8=E5=BA=8F?= =?UTF-8?q?=E5=88=97=E7=9A=84=E6=B8=85=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/agent/agent_loop.rs | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/agent/agent_loop.rs b/src/agent/agent_loop.rs index 1ef5bf5..8f2069a 100644 --- a/src/agent/agent_loop.rs +++ b/src/agent/agent_loop.rs @@ -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,