Skip to content

Conversation

@Vinay-Khanagavi
Copy link
Contributor

@Vinay-Khanagavi Vinay-Khanagavi commented Jul 24, 2025

  • Fix candidateToShimCandidate to detect function calls in mixed responses
  • Pass through original response when function calls are present
  • Prevent premature conversation termination

Fixes #427

- Fix candidateToShimCandidate to detect function calls in mixed responses
- Pass through original response when function calls are present
- Prevent premature conversation termination
- Add comprehensive tests for mixed response handling

Fixes GoogleCloudPlatform#427
Copy link
Collaborator

@noahlwest noahlwest left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems like a good change to me, though I have a couple of questions:

Description says "Add comprehensive tests for mixed response handling", is this something you intended to add or was it accidentally left in the description?

Also, were you able to verify this by recreating the issue from #427?

@Vinay-Khanagavi
Copy link
Contributor Author

ohh sorry, I created some test files but I didn't add tests when committing, You're right, that description was misleading. I should remove it.

Yes, I verified it the candidateToShimCandidate function was erroring out on function calls (non-text parts), causing mixed responses to fail with "no text part found in candidate" and skip tool execution.
Screenshot 2025-08-01 at 12 45 49 AM

Copy link
Collaborator

@noahlwest noahlwest left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good to me!

@Vinay-Khanagavi
Copy link
Contributor Author

The change fixes the bug where function calls were not executed when combined with text responses.

Screen.Recording.2025-08-01.at.12.53.05.AM.mov

// Instead, pass through the original response
klog.Infof("Warning: there are non-text parts FunctionCall in the response, returning concatenation of all text parts.")
// Return the original response without shim conversion
yield(response, nil)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I understand correctly,
in case of tool-use-shim, the API does not return toolCalls, so we accumulate all the text and then parse the text to convert into toolcall. So the change here will simply return text response to the layer above.

@droot
Copy link
Member

droot commented Aug 1, 2025

Yes, I verified it the candidateToShimCandidate function was erroring out on function calls (non-text parts), causing mixed responses to fail with "no text part found in candidate" and skip tool execution.

@Vinay-Khanagavi I don't think the original issue involved tool-use-shim, so I don't think this actually fixes the issue. Also the warning about mixed text and tool call is just a warning, I don't think it affects the tool calling. I think something else is going on in that issue and my guess is ... it might be related to custom tool support.

@mikebz mikebz requested a review from Copilot August 1, 2025 17:43
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR fixes the handling of mixed text and function call responses in the conversation shim by preventing premature error termination when function calls are present alongside text.

  • Replaces error throwing with function call detection and original response passthrough
  • Adds logging to warn about non-text parts in responses
  • Ensures function calls don't cause conversation failures

} else if calls, ok := part.AsFunctionCalls(); ok && len(calls) > 0 {
// If we encounter function calls, we should not use the shim
// Instead, pass through the original response
klog.Infof("Warning: there are non-text parts FunctionCall in the response, returning concatenation of all text parts.")
Copy link

Copilot AI Aug 1, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The log message is misleading. It states 'returning concatenation of all text parts' but the code actually returns the original response without concatenation.

Suggested change
klog.Infof("Warning: there are non-text parts FunctionCall in the response, returning concatenation of all text parts.")
klog.Infof("Warning: there are non-text parts FunctionCall in the response, returning the original response without concatenation.")

Copilot uses AI. Check for mistakes.
} else if calls, ok := part.AsFunctionCalls(); ok && len(calls) > 0 {
// If we encounter function calls, we should not use the shim
// Instead, pass through the original response
klog.Infof("Warning: there are non-text parts FunctionCall in the response, returning concatenation of all text parts.")
Copy link

Copilot AI Aug 1, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Grammar issue: 'FunctionCall' should be 'function calls' for better readability.

Suggested change
klog.Infof("Warning: there are non-text parts FunctionCall in the response, returning concatenation of all text parts.")
klog.Infof("Warning: there are non-text parts (function calls) in the response, returning concatenation of all text parts.")

Copilot uses AI. Check for mistakes.
// Instead, pass through the original response
klog.Infof("Warning: there are non-text parts FunctionCall in the response, returning concatenation of all text parts.")
// Return the original response without shim conversion
yield(response, nil)
Copy link

Copilot AI Aug 1, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The accumulated text buffer is discarded when function calls are detected. Consider whether any accumulated text should be preserved or if this is the intended behavior.

Copilot uses AI. Check for mistakes.
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)

3 participants