Skip to content

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

@runceel

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

Metadata

Metadata

Assignees

Labels

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

Type

Projects

Status

Sprint: Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions