-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Retry instead of error when Google response is empty with MALFORMED_FUNCTION_CALL or other recoverable finish reason
#3300
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
Conversation
Updated GoogleModel to handle 'MALFORMED_FUNCTION_CALL' finish reason by initializing parts as an empty list. Added and extended tests to cover retry logic for both streaming and non-streaming responses when a malformed function call is encountered.
168bc8d to
2997f66
Compare
Refactored Gemini response handling in GoogleModel and GeminiStreamedResponse to treat missing or malformed function call content uniformly, avoiding unnecessary exceptions. Removed obsolete or redundant test helpers and tests related to malformed function call streaming and retry logic.
Removed a redundant PartDeltaEvent assertion and updated the expected identifier in the BinaryImage snapshot assertion to 'b037a4' in the image generation test.
| ) | ||
| continue | ||
|
|
||
| parts = candidate.content.parts |
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.
Note that we could get here if candidate.content is None
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.
Wouldn't that call continue and thus let us proceed with the next chunk? I am not sure I can follow you right now.
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.
You're quite right, I think I had been at my desk for too long when I reviewed this :)
| parts = candidate.content.parts or [] | ||
| parts = [] | ||
| else: | ||
| parts = candidate.content.parts or [] |
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.
Note that we could get here if candidate.content is None
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 candidate.content is None, parts would be [] and we would continue with that, no?
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.
Ah, you're totally right, I wasn't reading right
Marked the assignment of an empty list to 'parts' with 'pragma: no cover' to exclude it from test coverage analysis, as this branch is likely not expected to be covered.
| parts = candidate.content.parts or [] | ||
| parts = [] | ||
| else: | ||
| parts = candidate.content.parts or [] |
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.
Ah, you're totally right, I wasn't reading right
| ) | ||
| continue | ||
|
|
||
| parts = candidate.content.parts |
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.
You're quite right, I think I had been at my desk for too long when I reviewed this :)
MALFORMED_FUNCTION_CALL or other recoverable finish reason
MALFORMED_FUNCTION_CALL or other recoverable finish reasonMALFORMED_FUNCTION_CALL or other recoverable finish reason
Reopening #3095
Original Description
Using Gemini, we are frequently running into the MALFORMED_FUNCTION_CALL as the finish reason.
Google seemingly does not provide any context in the response for the reason of the MALFORMED_FUNCTION_CALL.
In these cases, the agent can continue retrying which I why I suggest to simply
continuein the case of a MALFORMED_FUNCTION_CALL.Closes #631
The issue is most prevalent when using Gemini 2.5 Flash (compared to Gemini 2.5 Pro where it also happens but less frequently).
Example
chunk:Newly added changes
Refactored Gemini response handling in GoogleModel and GeminiStreamedResponse to treat missing or malformed function call content uniformly, avoiding unnecessary exceptions.