Skip to content

.Net: Honor FunctionChoiceBehavior function list in Gemini connector#1

Closed
giles17 wants to merge 1 commit into
mainfrom
giles17/fix-gemini-function-choice-behavior-functions
Closed

.Net: Honor FunctionChoiceBehavior function list in Gemini connector#1
giles17 wants to merge 1 commit into
mainfrom
giles17/fix-gemini-function-choice-behavior-functions

Conversation

@giles17

@giles17 giles17 commented Jul 24, 2026

Copy link
Copy Markdown
Owner

Motivation and Context

The Gemini connector converts a FunctionChoiceBehavior (FCB) into the connector-internal GeminiToolCallBehavior in GeminiPromptExecutionSettings. That conversion only inspected the AutoInvoke flag and evaluated the behavior against an empty kernel, so the configured function list and choice were dropped:

  • FunctionChoiceBehavior.Auto() / Auto([subset]) always provided all kernel functions to the model, regardless of the list supplied.
  • FunctionChoiceBehavior.Auto([]), which is documented as equivalent to disabling function calling, still provided all kernel functions.
  • Explicit function lists failed to convert because the behavior was evaluated against an empty kernel.

This diverges from the other connectors, which resolve the behavior against the request kernel and provide exactly the functions it specifies.

Description

  • Resolve the FunctionChoiceBehavior against the request's kernel and provide exactly the functions it declares (all, an explicit subset, or none), matching the shared function-calling semantics used by the other connectors.
  • An empty function list now correctly disables function calling.
  • Perform the conversion on a clone so shared or frozen settings instances are not mutated and the resolved result is not cached across different kernels.
  • Add a kernel-aware FromExecutionSettings(settings, kernel) overload and use it from GeminiChatCompletionClient.

Contribution Checklist

  • The code builds clean without any errors or warnings
  • Unit tests added/updated and passing (439/439 in Connectors.Google.UnitTests)
  • Behavior aligned with the other connectors

The Gemini connector converted a FunctionChoiceBehavior into a
GeminiToolCallBehavior by inspecting only the AutoInvoke flag and
evaluating the behavior against an empty kernel. As a result the
configured function list and choice were ignored: every conversion
provided all kernel functions to the model, and an explicit function
list produced an incorrect result.

Resolve the behavior against the request's kernel and provide exactly
the functions it specifies, consistent with the other connectors. An
empty function list now correctly disables function calling. The
conversion is performed on a clone so shared or frozen settings are not
mutated and the result is not cached across different kernels.

Also add a kernel-aware FromExecutionSettings overload and update the
chat completion client to use it.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: c0e4edcd-4d36-486f-950b-9c0c36fa68e8
@giles17
giles17 deployed to integration July 24, 2026 00:49 — with GitHub Actions Active
@giles17 giles17 closed this Jul 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant