.Net: Bug: Service ID selection not working properly when invoking plugins with multiple registered services
When multiple chat completion services are registered in the kernel with different service IDs, the ExecutionSettings dictionary with a specific service ID is not being respected during plugin invocation. The kernel appears to be selecting a different service (or default service) instead of the explicitly specified one.
Expected Behavior
When providing ExecutionSettings with a specific service ID in KernelArguments, that service should be used for the plugin invocation.
Actual Behavior
The kernel ignores the specified service ID and uses a different registered service (appears to be either the default service or another registered service).
Environment
Semantic Kernel Version: 1.59.0 Target Framework: .Net 9.0
Service Registration:
// Multiple services registered with different service IDs in app settings
switch (model.Type)
{
case ChatCompletionModelType.OpenAI:
builder.AddOpenAIChatCompletion(
model.ModelId,
model.ApiKey,
serviceId: model.ServiceId, // e.g., "openai-gpt-4"
httpClient: httpClientFactory.CreateClient());
break;
case ChatCompletionModelType.AzureOpenAI:
builder.AddAzureOpenAIChatCompletion(
model.ModelId,
model.Endpoint,
model.ApiKey,
serviceId: model.ServiceId, // e.g., "azure-gpt-4o"
httpClient: httpClientFactory.CreateClient());
break;
case ChatCompletionModelType.Anthropic:
var skChatService = new ChatClientBuilder(new AnthropicClient(model.ApiKey).Messages)
.ConfigureOptions(opt => { /* config */ })
.UseFunctionInvocation().Build().AsChatCompletionService();
builder.Services.AddKeyedSingleton(model.ServiceId, skChatService); // e.g., "anthropic-claude"
break;
}
var kernel = builder.Build();
Plugin config.json
{
"schema": 1,
"description": "Create a short title for the conversation",
"execution_settings": {
"default": {
"max_tokens": 100,
"temperature": 0.9,
"top_p": 0.0,
"presence_penalty": 0.0,
"frequency_penalty": 1.0,
"stop_sequence": [ "\n[END]", "[END]", "\n" ]
}
},
"input_variables": [
{
"name": "input",
"description": "The input text to generate from",
"defaultValue": ""
}
]
}
Invocation Code
Despite specifying "azure-gpt-4o", the Anthropic service is always used
private async Task<FunctionResult> InvokePlugin(
KernelFunction function,
KernelArguments arguments,
string serviceId, // e.g., "azure-gpt-4o"
CancellationToken cancellationToken)
{
var settings = new OpenAIPromptExecutionSettings
{
MaxTokens = 100,
Temperature = 0.9,
ServiceId = serviceId // Explicitly set to "azure-gpt-4o"
};
// ExecutionSettings dictionary with specific service ID
arguments.ExecutionSettings = new Dictionary<string, PromptExecutionSettings>
{
{ serviceId, settings } // Key: "azure-gpt-4o", Value: settings with ServiceId = "azure-gpt-4o"
};
// This should use the Azure OpenAI service, but uses Anthropic instead
return await _kernel.InvokeAsync(function, arguments, cancellationToken);
}
If I change "default" to "azure-gpt-4o" in the config.json file it works as expected! but I don't want to hard code it in every single plugin as they might get changed and they are dynamic!
The same issue for me.
This issue is stale because it has been open for 90 days with no activity.
This issue was closed because it has been inactive for 14 days since being marked as stale.