semantic-kernel icon indicating copy to clipboard operation
semantic-kernel copied to clipboard

.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

Open JanainaLudwig opened this issue 7 months ago • 2 comments

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:

  1. Using GoogleAIGeminiChatCompletionService, set ToolCallBehavior to auto call functions
  2. Register multiple tools
  3. Send a user prompt that will request to auto-call multiple tools in a single response
  4. 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

JanainaLudwig avatar Jun 18 '25 18:06 JanainaLudwig

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.

abbottdev avatar Jul 24 '25 14:07 abbottdev

This issue is stale because it has been open for 90 days with no activity.

github-actions[bot] avatar Oct 25 '25 02:10 github-actions[bot]