Skip to content

.Net: Fix Gemini function-response message role - #14585

Open
Mikita (lil-kita) wants to merge 1 commit into
microsoft:mainfrom
lil-kita:fix/gemini-function-response-role-upstream
Open

Mikita (lil-kita) wants to merge 1 commit into
microsoft:mainfrom
lil-kita:fix/gemini-function-response-role-upstream

Conversation

@lil-kita

Copy link
Copy Markdown

Motivation and Context

The .NET Google connector serializes AuthorRole.Tool as role: "function" when sending function results back to Gemini. The Gemini generateContent API defines Content.role as "user" or "model"; function results should be carried by a "user" message containing functionResponse parts.

With automatic function invocation, the initial request can succeed and the local function can execute, but the continuation request is rejected with:

Role 'function' is not supported.

This can leave an action completed locally without a final model response. Requests that do not invoke functions do not encounter this tool-result serialization path.

API references:

Minimal reproduction:

  1. Register a synthetic kernel function that returns a simple result.
  2. Enable GeminiToolCallBehavior.AutoInvokeKernelFunctions.
  3. Have the model request that function.
  4. Inspect the continuation request after local execution: the function-response message has role: "function" instead of role: "user".

Description

  • Serialize AuthorRole.Tool as "user" in the shared Gemini role converter.
  • Preserve internal tool roles and functionResponse payloads.
  • Leave user/model mappings and legacy "function" deserialization unchanged.
  • Update generation and streaming request assertions for the corrected wire role.
  • Extend regression coverage for serialized result payloads, batched responses, successive tool rounds, and preservation of thought signatures.

The fix applies to the shared Google AI and Vertex AI Gemini serialization path. It introduces no public API signatures, model-version conditions, retry behavior, dependency changes, or package metadata changes.

Validation

Verified the bug-fix-only patch against upstream main at 1b1f64b98c3828ada434d262c0e3038da6cc3508 on Windows with .NET SDK 10.0.401.

  • Release build of the Google connector unit-test project with warnings treated as errors: 0 warnings, 0 errors.
  • Release build of the Google connector across net10.0, net8.0, and netstandard2.0 with warnings treated as errors: 0 warnings, 0 errors.
  • Complete Google connector unit-test suite: 442 passed, 0 failed.
  • Formatting verification for the connector and its unit-test project: no changes required.
  • git diff --check: passed.
  • Diff limited to the role converter and four affected test files.
  • Repository-wide unit-test suite / upstream CI: not run locally; awaiting PR checks.
  • Live Gemini API verification: not performed. The function round-trip regression tests use mocked HTTP responses.

Commands run from the repository's dotnet directory:

dotnet build src\Connectors\Connectors.Google.UnitTests\Connectors.Google.UnitTests.csproj -c Release --warnaserror -p:TF_BUILD=true
dotnet build src\Connectors\Connectors.Google\Connectors.Google.csproj -c Release --no-restore --warnaserror -p:TF_BUILD=true
dotnet test src\Connectors\Connectors.Google.UnitTests\Connectors.Google.UnitTests.csproj -c Release --no-build --no-restore
dotnet format src\Connectors\Connectors.Google\Connectors.Google.csproj --verify-no-changes --no-restore
dotnet format src\Connectors\Connectors.Google.UnitTests\Connectors.Google.UnitTests.csproj --verify-no-changes --no-restore

TF_BUILD=true disables the repository's automatic formatting-on-Release-build target; formatting was verified separately without modifying files.

Contribution Checklist

  • The changed connector and its test project build clean without any errors or warnings.
  • The PR follows the SK Contribution Guidelines, and formatting verification raises no violations in the affected projects.
  • All repository unit tests pass, and I have added new tests where possible. Regression tests are included and all 442 Google connector tests pass; repository-wide checks remain pending.
  • I didn't break anyone 😄 No public API signatures changed and connector regression tests pass; broader CI and live-provider verification remain outstanding.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@lil-kita
Mikita (lil-kita) requested a review from a team as a code owner October 13, 2026 12:59
Copilot AI balanced review requested due to automatic review settings October 13, 2026 12:59
@semantic-kernel-automation semantic-kernel-automation Bot added .NET Issue or Pull requests regarding .NET code kernel Issues or pull requests impacting the core kernel labels Oct 13, 2026
@lil-kita

Copy link
Copy Markdown
Author

@microsoft-github-policy-service agree

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

The focused protocol correction is consistent across both serialization paths and is adequately covered by regression tests.

0 open findings

What changed in this PR

Corrects Gemini tool-response serialization to use the supported "user" wire role while retaining internal tool semantics.

Changes:

  • Maps AuthorRole.Tool to "user" during serialization.
  • Expands generation and streaming regression coverage.
  • Verifies batched, successive, and thought-signature tool rounds.
File Description
AuthorRoleConverter.cs Corrects tool-role serialization.
GeminiRequestTests.cs Verifies serialized function responses.
GeminiChatStreamingFunctionCallingTests.cs Updates streaming wire-role expectations.
GeminiChatGenerationFunctionCallingTests.cs Covers generation, batching, successive rounds, and signatures.
AuthorRoleConverterTests.cs Updates converter expectations.

🧠 Review effort: Balanced


💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

This branch was previously deployed

1 inactive deployment
github-app-auth — f6bf0bed Deployed Oct 13, 2026 by lil-kita via team_check #613
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.

2 participants