Skip to content

Conversation

@abbottdev
Copy link

@abbottdev abbottdev commented Oct 17, 2025

Motivation and Context

  1. Why is this change required?
    It appears that there's a quirk to how Gemini handles tool call results in it's API. The tool responses need to be present in the same chat item as the tool requests - rather than adding them individually as separate chat history items.
  2. What problem does it solve?
    This appears to fix (at least in my use case) the error whereby you receive:
{
  "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"
  }
}
  1. Which appears to happen when an SK response auto invokes > 1 tool. When it's a single tool result the API appears to handle the response gracefully.
  2. .Net: Bug: Google Gemini plugin call fails after SK version > 1.0.55 : "Error: Ensure number of function response parts is equal to the number of function call parts of the function call turn." #12823
  3. .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
    -->

Description

Google Gemini expects the function responses to be grouped together in a single message rather than split across multiple separate messages with role "function". By adding a batch tool result overload to the GeminiChatMessage we can correctly parse the multiple parts of the function call into their respective function parts.

Contribution Checklist

FYI @stephentoub (As I see you're working in the Gemini connector recently)

@abbottdev abbottdev requested a review from a team as a code owner October 17, 2025 15:36
@markwallace-microsoft markwallace-microsoft added .NET Issue or Pull requests regarding .NET code kernel Issues or pull requests impacting the core kernel labels Oct 17, 2025
@github-actions github-actions bot changed the title Feature/gemini function parts format .Net: Feature/gemini function parts format Oct 17, 2025
@abbottdev
Copy link
Author

@microsoft-github-policy-service agree company="Kroll"

@rogerbarreto
Copy link
Member

@abbottdev Thank you for the contribution!

Can as part of this change you also add an Manual Integration test that covers one of the reproduction code in the issue?

A simple example similar to the ones we have in the GettingStarted using Time and Weather could suffice to validate the double function calling updates do work directly with API calls.

Thanks!

@rogerbarreto rogerbarreto self-assigned this Oct 22, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

kernel Issues or pull requests impacting the core kernel .NET Issue or Pull requests regarding .NET code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants