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

.Net: Fix Gemini Auto Invoke when returned function is non-first part

Open ionite34 opened this issue 7 months ago • 0 comments

Motivation and Context

Fixes #11651

  • Currently Gemini Connectors will not Auto invoke functions when tool calls are returned in the same message with text parts, which is common with 2.5 Flash and Pro models:
"content": {
  "parts": [
    {
      "text": "Running the TimePlugin.Now function..."
    },
    {
      "functionCall": {
        "name": "TimePlugin.Now",
        "args": {
          "param1": "hello"
        }
      }
    }
  ],
  "role": "model"
}

This fixes this to now support auto kernel functions with this behavior and adds unit tests with this data.

Description

  • Added unit test data for streaming responses with text & tool parts
  • Changed GetChatMessageContentFromCandidate to return tools from all candidate parts instead of only the first part
  • Added extra check in GenerateChatMessageAsync for empty Tool results
  • Fixed stream responses in auto invoke mode with texts & tool parts not returned to the caller, added unit test

Contribution Checklist

ionite34 avatar May 19 '25 19:05 ionite34