.Net: Bug: Gemini - 2 parallel plugin call exception: number of function response parts is equal to the number of function call parts of the function call turn
Describe the bug
When two tools calls are invoked by Gemini 2.0-flash using GoogleAIGeminiChatCompletionService, the following Gemini request fails with the status code 400 and this message:
{
"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"
}
}
The request:
{
"contents": [
{
"parts": [
{
"text": "[REDACTED USER QUESTION]"
}
],
"role": "user"
},
{
"parts": [
{
"functionCall": {
"name": "function1",
"args": {
}
}
},
{
"functionCall": {
"name": "function2",
"args": {
}
}
}
],
"role": "model"
},
{
"parts": [
{
"functionResponse": {
"name": "function1",
"response": {
"content": {
"content": [
{
"type": "text",
"text": "[REDACTED RESPONSE]"
}
],
"isError": false
}
}
}
}
],
"role": "function"
},
{
"parts": [
{
"functionResponse": {
"name": "function2",
"response": {
"content": {
"content": [
{
"type": "text",
"text": "[REDACTED RESPONSE]"
}
],
"isError": false
}
}
}
}
],
"role": "function"
}
],
"generationConfig": {
"temperature": 0,
"topP": 0
},
"tools": [
{
"functionDeclarations": [
// functions objects...
]
}
],
"systemInstruction": {
"parts": [
{
"text": "[REDACTED PROMPT]"
}
]
}
}
This seems similar to this issue in Python SDK: https://github.com/microsoft/semantic-kernel/issues/10597
To Reproduce Steps to reproduce the behavior:
- Using GoogleAIGeminiChatCompletionService, set ToolCallBehavior to auto call functions
- Register multiple tools
- Send a user prompt that will request to auto-call multiple tools in a single response
- The next gemini request will fail with a bad request response.
Expected behavior
Parts with functionResponse should be in a single array with all the functions responses.
For example:
{
"contents": [
{
"parts": [
{
"text": "[REDACTED USER QUESTION]"
}
],
"role": "user"
},
{
"parts": [
{
"functionCall": {
"name": "function1",
"args": {
}
}
},
{
"functionCall": {
"name": "function2",
"args": {
}
}
}
],
"role": "model"
},
{
"parts": [
{
"functionResponse": {
"name": "function1",
"response": {
"content": {
"content": [
{
"type": "text",
"text": "[REDACTED RESPONSE]"
}
],
"isError": false
}
}
}
},
{
"functionResponse": {
"name": "function2",
"response": {
"content": {
"content": [
{
"type": "text",
"text": "[REDACTED RESPONSE]"
}
],
"isError": false
}
}
}
}
],
"role": "function"
}
],
"generationConfig": {
"temperature": 0,
"topP": 0
},
"tools": [
{
"functionDeclarations": [
// functions objects...
]
}
],
"systemInstruction": {
"parts": [
{
"text": "[REDACTED PROMPT]"
}
]
}
}
Platform
- Language: C#
- Source: NuGet package version 1.51.0
- AI model: Gemini 2.0-flash
- IDE: Rider
- OS: Mac
Also +1 on this - and I think it's similar to the Parallel bug that's referenced on the linked Python issue here: https://github.com/microsoft/semantic-kernel/issues/10597
It seems that if I add > 1 allowed tool, this error is thrown, but with a single tool, the error does not appear.
This issue is stale because it has been open for 90 days with no activity.