From 666be4ff4034decc8356fb9b2bf722ab5f4577f7 Mon Sep 17 00:00:00 2001 From: "Dhanji R. Prasanna" Date: Fri, 26 Dec 2025 11:55:57 +1100 Subject: [PATCH] Fix duplicate tool call handling: move tool_executed flag and reset parser - Move tool_executed = true after duplicate check to prevent auto-continue from triggering when only duplicate tools were detected - Reset parser state when duplicate detected to clear any partial/polluted state from LLM stuttering or example tool calls in markdown blocks --- crates/g3-core/src/lib.rs | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/crates/g3-core/src/lib.rs b/crates/g3-core/src/lib.rs index 6a5d4d0..4a7adf3 100644 --- a/crates/g3-core/src/lib.rs +++ b/crates/g3-core/src/lib.rs @@ -3831,12 +3831,9 @@ impl Agent { for (tool_call, duplicate_type) in deduplicated_tools { debug!("Processing completed tool call: {:?}", tool_call); - // Mark that we detected a tool call - this prevents content from being printed - // even if the tool is skipped as a duplicate - tool_executed = true; - - - // If it's a duplicate, log it and return a warning + // If it's a duplicate, log it and skip - don't set tool_executed! + // Setting tool_executed for duplicates would trigger auto-continue + // even when no actual tool execution occurred. if let Some(dup_type) = &duplicate_type { // Log the duplicate with red prefix let prefixed_tool_name = @@ -3852,9 +3849,18 @@ impl Agent { let mut modified_tool_call = tool_call.clone(); modified_tool_call.tool = prefixed_tool_name; debug!("{}", warning_msg); + + // Reset the parser to clear any partial/polluted state. + // This prevents "example" tool calls in markdown or LLM stuttering + // from polluting subsequent parsing. + parser.reset(); + continue; // Skip execution of duplicate } + // Mark that we're executing a tool (only for non-duplicates) + tool_executed = true; + // Check if we should auto-compact at 90% BEFORE executing the tool // We need to do this before any borrows of self if self.auto_compact && self.context_window.percentage_used() >= 90.0 {