Skip to content

.Net: Bug: FunctionChoiceBehavior.None() does not prevent function call with AddAzureOpenAIChatClient #12209

Closed

Description

@runceel

Description

Describe the bug
When specifying FunctionChoiceBehavior.None(), functions should not be called. However, when using AddAzureOpenAIChatClient, the function is still invoked. This issue does not occur when using AddAzureOpenAIChatCompletion, where the function is not called as expected. This only happens with AddAzureOpenAIChatClient.

To Reproduce
Steps to reproduce the behavior:

  1. Create a new Console App project.
  2. Add the following NuGet packages to your project:
    • Azure.Identity
    • Microsoft.SemanticKernel
  3. Run the following code snippet:
using Azure.Identity;
using Microsoft.SemanticKernel;
using System.ComponentModel;

var builder = Kernel.CreateBuilder();
builder.AddAzureOpenAIChatClient(
    "<<Your model deployment name>>",
    "https://<<Your AOAI resource name>>.openai.azure.com/",
    new AzureCliCredential());

builder.Plugins.AddFromType<TimePlugin>();

var kernel = builder.Build();

var result = await kernel.InvokePromptAsync("What is the current date and time?",
    arguments:new(new PromptExecutionSettings
    {
        FunctionChoiceBehavior = FunctionChoiceBehavior.None(),
    }));
Console.WriteLine(result.GetValue<string>());

public class TimePlugin
{
    [KernelFunction, Description("Returns the current local date and time as a formatted string (yyyy/MM/dd HH:mm:ss).")]
    public string GetCurrentDateTime() => 
        TimeProvider.System.GetLocalNow().ToString("yyyy/MM/dd HH:mm:ss");
}
  1. AI answers the prompt and calls the function, returning the current date and time like this:
The current date and time is 2025/05/21 13:35:05.

Expected behavior
The function should not be called, and the AI should respond based only on its own knowledge, without using any registered functions.

Platform

  • Language: C#
  • Source: Microsoft.SemanticKernel v1.53.0
  • AI model: gpt-4.1
  • IDE: Visual Studio 2022
  • OS: Windows

Additional context
N/A

Activity

  1. changed the title [-]Bug: FunctionChoiceBehavior.None() does not prevent function call with AddAzureOpenAIChatClient[/-] [+].Net: Bug: FunctionChoiceBehavior.None() does not prevent function call with AddAzureOpenAIChatClient[/+] on May 21, 2025
  2. moved this from Sprint: Planned to Sprint: In Review in Semantic Kernelon May 21, 2025
  3. added a commit that references this issue on May 22, 2025
    cecee4c
  4. added a commit that references this issue on May 26, 2025
    2ad196e
  5. moved this from Sprint: In Review to Sprint: Done in Semantic Kernelon May 28, 2025
  6. added a commit that references this issue on Sep 15, 2025
    51b1515
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

.NETIssue or Pull requests regarding .NET codeai connectorAnything related to AI connectorsbugSomething isn't working

Type

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions