Open
Description
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:
- 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
Metadata
Metadata
Assignees
Type
Projects
Status
Bug