Skip to content

.Net: Bug: ChatSystemPrompt not applied in AddAzureOpenAIChatClient #12546

Open
@runceel

Description

@runceel

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:

  1. Register both AddAzureOpenAIChatCompletion and AddAzureOpenAIChatClient with the same model and endpoint.
  2. Invoke InvokePromptAsync with identical ChatSystemPrompt settings for both services.
  3. Observe that ChatCompletion responds according to the system prompt, while ChatClient 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    .NETIssue or Pull requests regarding .NET codebugSomething isn't workingtriage

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions