mirror of
https://github.com/microsoft/semantic-kernel.git
synced 2026-10-12 11:19:56 +00:00
### Motivation and Context While parsing the kernel function's arguments, we recurse to the type's base origin and then set that as the `type_object`. For a type like `list[MyCustomClass]` only setting the `type_object` as `list` has us lose out on the other valuable information of the list's type, which is `MyCustomClass` and what attributes it contains within. This then leads us to build an incomplete schema when creating the kernel function parameters and ultimately when we send the JSON schema to the model during tool calls. <!-- Thank you for your contribution to the semantic-kernel repo! Please help reviewers and future users, providing the following information: 1. Why is this change required? 2. What problem does it solve? 3. What scenario does it contribute to? 4. If it fixes an open issue, please link to the issue here. --> ### Description This PR: - Closes #6466 - Refactors the kernel function decorator code to parse arguments/parameters. We now grab the `type_object` of the parameter/argument in question, which is used to build the JSON schema. - Fixes the schema building for the types we build. We were missing `required` parameters as well. - Attempts to handle as many edge cases as possible, although there are probably more that we aren't handling right now -- for example properly handling all schemas for Unions is tricky. - Adds unit tests to make sure we are building the JSON schema as expected. All unit, integration and sample tests are passing. - Handles a `TypeError` exception during auto function calling where the model sends back an argument like `2`, which doesn't cause JSON parsing to fail, but will fail when trying to update the argument dictionary. <!-- Describe your changes, the overall approach, the underlying design. These notes will help understanding how your code works. Thanks! --> ### Contribution Checklist <!-- Before submitting this PR, please make sure: --> - [X] The code builds clean without any errors or warnings - [X] The PR follows the [SK Contribution Guidelines](https://github.com/microsoft/semantic-kernel/blob/main/CONTRIBUTING.md) and the [pre-submission formatting script](https://github.com/microsoft/semantic-kernel/blob/main/CONTRIBUTING.md#development-scripts) raises no violations - [X] All unit tests pass, and I have added new tests where possible - [X] I didn't break anyone 😄