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

Bug: The function call plugin name printed is empty

Open williamlzw opened this issue 9 months ago • 6 comments

The function call plugin name printed is empty

Image

using Microsoft.SemanticKernel;

using Microsoft.SemanticKernel.ChatCompletion;
using Microsoft.SemanticKernel.Connectors.Ollama;
using System.ComponentModel;
using System.Text;

#pragma warning disable SKEXP0110
public class TimePlugin
{
    [KernelFunction, Description("读取指定路径文件的内容,跨平台兼容~目录")]
    public string ReadFile(
        string filePath)
    {
        var ret = File.ReadAllText(filePath, Encoding.UTF8);
        return ret;

    }
    [KernelFunction, Description("This method is used to query the current system time and return it in the format yyyy-MM-dd HH:mm:ss")]
    public string QueryDateTime()
    {
        return DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
    }

    [KernelFunction, Description("The purpose of this method is to write the text content to the local computer's target path")]
    public void SaveFile(string filePath, string fileContent)
    {
        System.IO.File.WriteAllText(filePath, fileContent);
    }
}

class Program3
{
    public static async Task Main()
    {
        Console.OutputEncoding = System.Text.Encoding.UTF8;
        var builder = Kernel.CreateBuilder();
        var modelId = "qwen3:4b-instruct-2507-q4_K_M";
        var endpoint = new Uri("http://localhost:11434");

        builder.Services.AddOllamaChatCompletion(modelId, endpoint);

        var kernel = builder.Build();
        //KernelPlugin plugin = kernel.ImportPluginFromType<TimePlugin>();
        var plugin1 = new TimePlugin();
        kernel.Plugins.AddFromObject(plugin1, pluginName:"time");
        var chatCompletionService = kernel.GetRequiredService<IChatCompletionService>();

        string prompt = "读取一下d:\\test123.txt的内容";
        var executionSettings = new OllamaPromptExecutionSettings
        {
            FunctionChoiceBehavior = FunctionChoiceBehavior.Auto(autoInvoke: false)
        };

        var t0 = DateTime.Now;
        var response = await chatCompletionService.GetChatMessageContentAsync(prompt, kernel: kernel, executionSettings: executionSettings);
        var functionCalls = Microsoft.SemanticKernel.FunctionCallContent.GetFunctionCalls(response).ToArray();
        foreach (var functionCall in functionCalls)
        {
            Console.WriteLine($" {functionCall.PluginName}, {functionCall.FunctionName}");//error  have no PluginName
            var functionResult = await functionCall.InvokeAsync(kernel);
            Console.WriteLine($"{functionResult.Result}");
       
        }
        Console.WriteLine($"工具调用数 {functionCalls.Length}");
        Console.Write(response.Content);
    }
}


williamlzw avatar Feb 06 '26 15:02 williamlzw

output: , time_ReadFile Is the plugin name empty and the function name changed to pluginName_functionName format?

williamlzw avatar Feb 06 '26 15:02 williamlzw

Opened a fix PR for this: #13585

What it changes:

  • Preserves PluginName when converting Microsoft.Extensions.AI.FunctionCallContent into SK FunctionCallContent (instead of always leaving plugin empty).
  • Parses fully-qualified tool names using ., -, and a safe _ fallback for Ollama-style names like time_ReadFile.
  • Applies the same parsing for FunctionResultContent by matching the original call ID.
  • Adds regression tests for underscore-qualified names and snake_case non-splitting behavior.

Local verification:

  • /Users/liweiguang/.dotnet/dotnet test dotnet/src/SemanticKernel.UnitTests/SemanticKernel.UnitTests.csproj --filter ChatMessageExtensionsTests --nologo
  • Same test set with coverage collection enabled.

weiguangli-io avatar Feb 23 '26 15:02 weiguangli-io

This issue is stale because it has been open for 90 days with no activity.

github-actions[bot] avatar May 26 '26 02:05 github-actions[bot]

One practical way to make this easier to evaluate is to turn the report into a small contract test around the runtime boundary, not only the user-facing symptom.

For function call plugin name printed empty, I would check three things: first, the failing input is preserved as a minimal fixture; second, the SDK emits the same observable event/result shape before and after the fix except for the intended change; third, the trace or serialized session contains enough metadata to explain what happened after a resume or retry.

The part that matters for agent systems is durability: if a tool call, memory write, handoff, or structured-output step fails, downstream code should not have to infer state from natural-language output. A focused regression test around that boundary would make the issue much easier to close with confidence.

norika1207-lab avatar Jun 02 '26 03:06 norika1207-lab

This issue is stale because it has been open for 90 days with no activity.

github-actions[bot] avatar Oct 02 '26 01:10 github-actions[bot]

I am going to take this bug.

ToChatMessageContent still drops PluginName when converting Microsoft.Extensions.AI FunctionCallContent (reproduced on current main). Earlier PRs #13585 / #13672 / #14101 closed unmerged.

Local approach (not pushed yet): parse with FunctionName.Parse using - first, then _ only when the function part is PascalCase so snake_case names like my_function are not split. Happy to open a PR if that direction is still welcome.

FOWEPJF255 avatar Oct 04 '26 06:10 FOWEPJF255