Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

.Net: Document behaviour whereby KernelArguments contains arguments with incorrect types #10153

Open
markwallace-microsoft opened this issue Jan 10, 2025 · 0 comments
Assignees
Labels
documentation .NET Issue or Pull requests regarding .NET code sk team issue A tag to denote issues that where created by the Semantic Kernel team (i.e., not the community)

Comments

@markwallace-microsoft
Copy link
Member

This issue is reproducible if a KernelFunction delegate takes KernelArguments as a parameter

Consider the following request and response:

    === REQUEST ===
{
  "messages": [
    {
      "role": "user",
      "content": "What is the Semantic Kernel? Search for 5 references."
    }
  ],
  "model": "gpt-4o",
  "tools": [
    {
      "type": "function",
      "function": {
        "description": "Perform a search for content related to the specified query and return string results",
        "name": "SearchPlugin-Search",
        "parameters": {
          "type": "object",
          "required": [
            "query"
          ],
          "properties": {
            "query": {
              "description": "What to search for",
              "type": "string"
            },
            "count": {
              "description": "Number of results (default value: 2)",
              "type": "integer"
            },
            "skip": {
              "description": "Number of results to skip (default value: 0)",
              "type": "integer"
            }
          }
        },
        "strict": false
      }
    }
  ],
  "tool_choice": "auto"
}

=== RESPONSE ===
{
  "id": "chatcmpl-Ao7MjE5CzHc6gKEV204lXHLGnJG3w",
  "object": "chat.completion",
  "created": 1736508077,
  "model": "gpt-4o-2024-08-06",
  "choices": [
    {
      "index": 0,
      "message": {
        "role": "assistant",
        "content": null,
        "tool_calls": [
          {
            "id": "call_FPeTqiealR6ANFmoNFb9G0iY",
            "type": "function",
            "function": {
              "name": "SearchPlugin-Search",
              "arguments": "{\"query\":\"Semantic Kernel\",\"count\":5}"
            }
          }
        ],
        "refusal": null
      },
      "logprobs": null,
      "finish_reason": "tool_calls"
    }
  ],
  "usage": {
    "prompt_tokens": 102,
    "completion_tokens": 22,
    "total_tokens": 124,
    "prompt_tokens_details": {
      "cached_tokens": 0,
      "audio_tokens": 0
    },
    "completion_tokens_details": {
      "reasoning_tokens": 0,
      "audio_tokens": 0,
      "accepted_prediction_tokens": 0,
      "rejected_prediction_tokens": 0
    }
  },
  "service_tier": "default",
  "system_fingerprint": "fp_703d4ff298"
}

Note that the tool_call.function.arguments in the response form the LLM correctly have count as an integer

The KernelFunction delegate takes KernelArguments are an input parameter e.g..

async Task<IEnumerable<string>> SearchAsync(Kernel kernel, KernelFunction function, KernelArguments arguments, CancellationToken cancellationToken)

When the delegate gets called the count argument is of type string because of this code:

// Iterate over copy of the names to avoid mutating the dictionary while enumerating it
var names = arguments.Names.ToArray();
foreach (var name in names)
{
    arguments[name] = arguments[name]?.ToString();
}

If I change the KernelFunction delegate as follows i.e.

async Task<IEnumerable<string>> SearchAsync(Kernel kernel, KernelFunction function, KernelArguments arguments, CancellationToken cancellationToken, int count = 2, int skip = 0)

The count argument is set correctly but the count argument is still in KernelArguments with the incorrect type.

Purpose of this task is to document this behaviour

@markwallace-microsoft markwallace-microsoft added documentation sk team issue A tag to denote issues that where created by the Semantic Kernel team (i.e., not the community) labels Jan 10, 2025
@markwallace-microsoft markwallace-microsoft moved this to Sprint: Planned in Semantic Kernel Jan 10, 2025
@markwallace-microsoft markwallace-microsoft added .NET Issue or Pull requests regarding .NET code triage labels Jan 10, 2025
@github-actions github-actions bot changed the title Document behaviour whereby KernelArguments contains arguments with incorrect types .Net: Document behaviour whereby KernelArguments contains arguments with incorrect types Jan 10, 2025
@markwallace-microsoft markwallace-microsoft self-assigned this Jan 10, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation .NET Issue or Pull requests regarding .NET code sk team issue A tag to denote issues that where created by the Semantic Kernel team (i.e., not the community)
Projects
Status: Sprint: Planned
Development

No branches or pull requests

1 participant