Skip to content

Handle mixed text + function_call; execute tool calls reliably#536

Open
cnaples79 wants to merge 1 commit intoGoogleCloudPlatform:mainfrom
cnaples79:fix-execute-tool-when-text-and-function
Open

Handle mixed text + function_call; execute tool calls reliably#536
cnaples79 wants to merge 1 commit intoGoogleCloudPlatform:mainfrom
cnaples79:fix-execute-tool-when-text-and-function

Conversation

@cnaples79
Copy link

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

…gate parts across all candidates during streaming so function calls are not missed when models return mixed content or tool calls in non-primary candidates.\n\nFixes GoogleCloudPlatform#427
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug: Tool not executed when assistant response includes both text and function call (partial handling)

1 participant