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

.Net: Bug: .Net, Since package version 1.63.0, when using Ollama + gpt-oss:20b, the function calling feature does not work properly in streaming mode.

Open bauann opened this issue 1 year ago • 9 comments

Describe the bug Since package version 1.63.0, when using Ollama + gpt-oss:20b, the function calling feature does not work properly in streaming mode. Instead of being invoked as expected, it directly terminates.

To Reproduce Steps to reproduce the behavior:

  1. Target the semantick kernel version to 1.63.0
  2. Add a plugin to kernel, e.g: builder.Plugins.AddFromType<YOUR_PLUGIN_TYPE>();
  3. Add OllamaChatCompletion with model gpt-oss:20b
  4. Start a async chat (GetStreamingChatMessageContentsAsync) that should trigger the function call added above.
  5. The entire chat session end immediately after a tool call request appears, without executing the tool call.

Expected behavior The tool should be invoked properly, and the response should be generated based on the results returned from the tool call.

Platform

  • Language: C#
  • Source: nuget package (1.63.0)
  • AI model: ollama 0.11.7 + gpt-oss:20b
  • IDE: Rider
  • OS: Mac

Additional context I tested both versions 1.63.0 and 1.64.0, and the same issue occurs in both. However, in versions 1.62.0 and 1.61.0, the tool calls work correctly as expected.

bauann avatar Aug 28 '25 08:08 bauann

I'm testing GPT-5 and i'm having same issue. it's only returning empty object when calling any plugins. I can see the plugin return response to the AI.

Cobra86 avatar Aug 28 '25 11:08 Cobra86

This seems to be related to a bug in the OllamaSharp library specificaly to the OpenAI OSS model, the fix below may solve the issue.

As soon they have an update we will upgrade our dependency.

  • https://github.com/awaescher/OllamaSharp/issues/305

Running our Demo with older models like llama3.1+ worked for both streaming and non-streaming.

Image

rogerbarreto avatar Sep 01 '25 16:09 rogerbarreto

@rogerbarreto any news?

Expecho avatar Sep 28 '25 10:09 Expecho

I have same issue on tool calls with Semantic Kernel 1.65 + Ollama or Vllm with GPT-OSS:lates models. With other models like Qween works correctly, buth with GPT-OSS doesn't work correctly. I've tested function calls by curl and works correctly both in vllm and ollama, seems that semantic kernel can't handle it. Please help!!!

lukyluciano avatar Oct 02 '25 06:10 lukyluciano

The current release (1.65.0) references OllamaSharp package version >= 5.3.5, which contains an issue when running ollama with gpt-oss models (reference) .

OllamaSharp fixed this issue in version 5.3.12 and later. It is anticipated that SK will update the OllamaSharp dependency in the next release. I have tested manually upgrading the OllamaSharp dependency, and it works as expected. For urgent needs, the workaround is to manually add the OllamaSharp dependency to your project and target version 5.3.12.

Hope this helped.

bauann avatar Oct 03 '25 01:10 bauann

@rogerbarreto Hi, I saw that version 1.66.0 of Semantic Kernel has been released, but the dependency of OllamaSharp still targets 5.3.5. Will it be changed in the next release ?

bauann avatar Oct 13 '25 10:10 bauann

Hi, I've tried @bauann solution, and it doesn't work on my computer. The problem isn't limited to gpt-oss:20b, either. I've also tried mistral-nemo:12b-instruct-2407-q4_K_M and jacob-ebey/phi4-tools:latest. However, it does work correctly with LLM llama3.1 and the OllamaSharp 5.3.5 nuget package.

jesusSerranoCarballido avatar Oct 17 '25 08:10 jesusSerranoCarballido

Hi @jesusSerranoCarballido , this issue likely occurs in the context of gpt-oss + ollama. I conducted a test with my current setup, which uses llama3.1 + ollama (0.12.6) + SK (1.66.0). Even with OllamaSharp remaining at the default version of 5.3.5, the function calling works as expected.

I recommend checking the following:

  • ollama version (upgrade to the latest version)
  • Check your code for the promptExecutionSetting configuration, for example:
return new OllamaPromptExecutionSettings()
{
    Temperature = 0.1f,
    FunctionChoiceBehavior = isEnableToolUse ? FunctionChoiceBehavior.Auto() : null,
};

bauann avatar Oct 17 '25 09:10 bauann

Since the latest version of SK (1.68.0) has changed the dependency of OllamaSharp to version 5.4.11, this issue no longer exists.

bauann avatar Jan 16 '26 07:01 bauann