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

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

Open runceel opened this issue 7 months ago • 0 comments

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

runceel avatar May 21 '25 04:05 runceel