kubectl-ai icon indicating copy to clipboard operation
kubectl-ai copied to clipboard

Handle mixed text + function_call; execute tool calls reliably

Open cnaples79 opened this issue 4 months ago • 0 comments

Summary

Execute tool calls even when a model response includes both text and function_call parts, or when function calls appear on non-primary candidates.

Problem

In some cases (e.g., Gemini 2.5 Pro), the assistant can return:

  • Partial text (e.g., "I'll start by checking the logs...")
  • A valid function call (e.g., oc4 logs ...)

But the function call was not executed and the run ended with:

No function calls were made, so most likely the task is completed

Root Cause

The streaming handler only inspected the first candidate (response.Candidates()[0]). If a provider returned function calls in another candidate or mixed content, those calls could be missed.

Fix

  • Aggregate parts across all candidates during streaming and collect both text and function calls.
  • This ensures function calls are not ignored when present alongside text, or when not in the first candidate.

Files Changed

  • pkg/agent/conversation.go: Iterate over all candidates and parts when collecting streamedText and functionCalls.

Test Plan

  • Manual: Reproduce with a prompt that triggers a tool call and some text; verify the tool call executes instead of exiting early.
  • Existing logic already handles permission prompts and tool execution paths once functionCalls is populated.

Fixes #427

cnaples79 avatar Sep 12 '25 17:09 cnaples79