Open
Description
Describe the bug
When using AddAzureOpenAIChatClient
, the ChatSystemPrompt
parameter in AzureOpenAIPromptExecutionSettings
is ignored. In contrast, when using AddAzureOpenAIChatCompletion
, the same parameter is respected and produces the expected behavior.
To Reproduce
Steps to reproduce the behavior:
- Register both
AddAzureOpenAIChatCompletion
andAddAzureOpenAIChatClient
with the same model and endpoint. - Invoke
InvokePromptAsync
with identicalChatSystemPrompt
settings for both services. - Observe that
ChatCompletion
responds according to the system prompt, whileChatClient
does not.
using Azure.Identity;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.SemanticKernel;
using Microsoft.SemanticKernel.Connectors.AzureOpenAI;
var builder = Kernel.CreateBuilder();
builder.AddAzureOpenAIChatCompletion(
"gpt-4.1",
"https://<your-endpoint>.cognitiveservices.azure.com/",
new AzureCliCredential(),
serviceId: "chatCompletion");
builder.AddAzureOpenAIChatClient(
"gpt-4.1",
"https://<your-endpoint>.cognitiveservices.azure.com/",
new AzureCliCredential(),
serviceId: "chatClient");
var kernel = builder.Build();
{
Console.WriteLine("## ChatCompletion");
var r = await kernel.InvokePromptAsync("""
How do you think about the article below? Please provide feedback.
""",
new(new AzureOpenAIPromptExecutionSettings
{
ChatSystemPrompt = "Please answer \"meow\" to every question.",
ServiceId = "chatCompletion",
}));
Console.WriteLine(r.GetValue<string>()); // meow
}
{
Console.WriteLine("## ChatClient");
var r = await kernel.InvokePromptAsync("""
How do you think about the article below? Please provide feedback.
""",
new(new AzureOpenAIPromptExecutionSettings
{
ChatSystemPrompt = "Please answer \"meow\" to every question.",
ServiceId = "chatClient",
}));
Console.WriteLine(r.GetValue<string>()); // not meow
}
Expected behavior
The ChatSystemPrompt should be respected by both ChatClient and ChatCompletion. The behavior should be consistent across both connectors.
Screenshots
N/A
Platform
- Language: C#
- Source: 1.57.0
- AI model: gpt-4.1
- IDE: Visual Studio 2022
- OS: Windows
Additional context
This discrepancy suggests that the AddAzureOpenAIChatClient
implementation may be missing logic to apply the ChatSystemPrompt. Since ChatCompletion behaves correctly, it would be expected that ChatClient follows the same pattern.