Skip to content

.Net: Bug: KernelFunction with complex arguments #12605

Open
@SGStino

Description

@SGStino

Describe the bug
When the Semantic Kernel needs to call a method with a complex arguments, the argument is passed along as a Json representation string of that object when using the OpenAI client.
While using the Ollama client with a local mistral-small, it was a JsonElement object sometimes, but I don't have access to that for the moment.

To Reproduce

  1. Make a KernelFunction for the delegate
(TodoListItems values, string scope) => "success"
public record TodoListItems(string[] Items);
  1. Ask an AzureOpenAI GPT4 model to call it.

  2. Inspect the parameters passed to the KernelFunction (KernelFunction is internal, so i couldn't derive a class from it to troubleshoot. But via AIFunction i could see the arguments passed along.

Actual behavior
the values argument is

"{\"items\":[\"todo1\", \"todo2\"]}"

(or sometimes a JsonElement)
Expected behavior
I'm not sure if I expect it to pass the object (object[], Dictionary<string, object>, ..) or a json element/node. Since it won't always know the final object. (only the jsonschema is technically known at that point.)

But I do expect it to be consistent between KernelFunction and AIFunction: dotnet/extensions#6544

** Additional context**

This causes issues upstream as modelcontextprotocol/csharp-sdk#558, which passes the string along as a json string instead of raw json.
I suspect that a passed JsonElement would have the correct behaviour there, as a serialized JsonElement is the raw json again.

Metadata

Metadata

Assignees

Labels

.NETIssue or Pull requests regarding .NET codeai connectorAnything related to AI connectorsbugSomething isn't working

Type

Projects

Status

Bug

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions