Repository navigation
Conversation
|
Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). View this failed invocation of the CLA check for more information. For the most up to date status, view the checks section at the bottom of the pull request. |
|
Looks like this is very similar to #1582 |
|
I just noticed that the MR description above is a word for word copy of the description in my PR #1582, with. the only differences being some formatting (capitalisation and bold / italics changed). What is particularly odd is that the actual code implementation does not follow the description of the proposed solution - there is no |
What Happens
Currently, when a function call receives multiple responses across different events in parallel with uncorrelated function responses, the event re-writing logic can incorrectly include too many function responses. This leads to an error like:
{ "error": { "code": 400, "message": "Please ensure that the number of function response parts is equal to the number of function call parts of the function call turn.", "status": "INVALID_ARGUMENT" } }What Should Happen
The ideal solution for this scenario is somewhat intricate, but several key principles should hold true:
Note: Points 6 and 7 might suggest that models must support parallel function calling, which could break compatibility with models that don't. However, this isn't a requirement. The only way these re-writing rules would bring multiple responses together is if a series of function responses were ordered without any interleaved model parts—meaning parallel function responses must already be present. For parallel calls, the logic ensures a matching number of calls and responses in the preceding turn, so parallel function calling also requires parallel responses to already exist. The only other situation for parallel calls is when they are unmatched, which typically only happens at the end of a conversation, and in these cases, they would also need to be present as such.
Solution
A new method,
_extract_latest_function_parts, will directly create thecontentsaccording to these rules. Function calls and responses are specially handled and manipulated, while all other parts remain unchanged. This preserves all existing authentication and invalid event filtering logic, as well as foreign agent part re-writing.Code Source
All tests and the proposed implementation were developed without AI. Therefore, the likelihood of these code snippets existing in copyrighted source code is negligible.
Update - Added Validation
An additional validator has been added to the mock model and tests to catch future occurrences of this problem....