-
Notifications
You must be signed in to change notification settings - Fork 667
fix: handle mixed text and function call responses in shim #437
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
fix: handle mixed text and function call responses in shim #437
Conversation
- 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
noahlwest
left a comment
There was a problem hiding this 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?
noahlwest
left a comment
There was a problem hiding this 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!
|
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) |
There was a problem hiding this comment.
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.
@Vinay-Khanagavi I don't think the original issue involved |
There was a problem hiding this 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.") |
Copilot
AI
Aug 1, 2025
There was a problem hiding this comment.
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.
| 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.") |
| } 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.") |
Copilot
AI
Aug 1, 2025
There was a problem hiding this comment.
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.
| 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.") |
| // 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) |
Copilot
AI
Aug 1, 2025
There was a problem hiding this comment.
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.

Fixes #427