microsoft/semantic-kernel

Python: Ignore certain parameters when using `get_tool_call_object`

Opened this issue · 0 comments

When using get_tool_call_object, it would be good if it were possible to exclude certain parameters from being included in the responding tool object, namely the parameters that are automatically passed in by the kernel (e.g. kernel, service, etc.)

Consider the following example:

import asyncio
import json
from typing import Annotated

from semantic_kernel import Kernel
from semantic_kernel.connectors.ai.open_ai.utils import get_tool_call_object
from semantic_kernel.functions import kernel_function


class MyPlugin:
    @kernel_function(description="My function")
    def my_func(
        self,
        param: Annotated[str, "The parameter"],
        kernel: Kernel,
    ): ...


async def main():
    kernel = Kernel()

    kernel.add_plugin(plugin=MyPlugin(), plugin_name="MyPlugin")

    print(json.dumps(get_tool_call_object(kernel, filter={}), indent=2))


asyncio.run(main())

The function includes kernel, which will automatically be passed in when the function is called, however it also appears in the tool object:

[
  {
    "type": "function",
    "function": {
      "name": "MyPlugin-my_func",
      "description": "My function",
      "parameters": {
        "type": "object",
        "properties": {
          "param": {
            "description": "The parameter",
            "type": "string"
          },
          "kernel": {
            "description": "",
            "type": "string"
          }
        },
        "required": [
          "param",
          "kernel"
        ]
      }
    }
  }
]

This could mean that the LLM attempts to pass a value for kernel, when it shouldn't be coming from the LLM.