diff --git a/src/providers/gemini.rs b/src/providers/gemini.rs index 44ad7231..be094c96 100644 --- a/src/providers/gemini.rs +++ b/src/providers/gemini.rs @@ -927,12 +927,18 @@ impl super::Provider for GeminiProvider { let tool_calls = if deltas.is_empty() { None } else { Some(deltas) }; // Determine finish_reason - let finish_reason = candidate.finish_reason.as_ref().map(|fr| { - match fr.as_str() { - "STOP" => "stop".to_string(), - _ => fr.to_lowercase(), - } - }); + // STRATEGY: If we have tool calls, the finish_reason MUST be "tool_calls" + // to comply with OpenAI-style expectations and ensure the client continues. + let finish_reason = if tool_calls.is_some() { + Some("tool_calls".to_string()) + } else { + candidate.finish_reason.as_ref().map(|fr| { + match fr.as_str() { + "STOP" => "stop".to_string(), + _ => fr.to_lowercase(), + } + }) + }; // Avoid emitting completely empty chunks unless they carry usage. if !content.is_empty() || reasoning_content.is_some() || tool_calls.is_some() || stream_usage.is_some() {