Skip to content

.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 #12528

Open
@JanainaLudwig

Description

@JanainaLudwig

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: #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

Metadata

Metadata

Assignees

Labels

.NETIssue or Pull requests regarding .NET codebugSomething isn't working

Type

Projects

Status

Bug

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions