From 4193ad00a770875625a8ac0dc3e3b537fb8fd28f Mon Sep 17 00:00:00 2001 From: NS Agent <233628060+nslabhwan@users.noreply.github.com> Date: Wed, 16 Sep 2026 23:36:52 +0000 Subject: [PATCH] Python: preserve shared Annotated parameter metadata --- .../functions/kernel_function_decorator.py | 1 + .../functions/test_kernel_function_decorators.py | 16 ++++++++++++++++ 2 files changed, 17 insertions(+) diff --git a/python/semantic_kernel/functions/kernel_function_decorator.py b/python/semantic_kernel/functions/kernel_function_decorator.py index 4d103a1a9093..3dae8b6ed424 100644 --- a/python/semantic_kernel/functions/kernel_function_decorator.py +++ b/python/semantic_kernel/functions/kernel_function_decorator.py @@ -151,6 +151,7 @@ def _parse_parameter(name: str, param: Any, default: Any) -> dict[str, Any]: if isinstance(meta, str): ret["description"] = meta elif isinstance(meta, dict): + meta = meta.copy() # only override from the metadata if it is not already set if "description" not in ret and (description := meta.pop("description", None)): ret["description"] = description diff --git a/python/tests/unit/functions/test_kernel_function_decorators.py b/python/tests/unit/functions/test_kernel_function_decorators.py index 803e0d2ffc7a..511d10055bc0 100644 --- a/python/tests/unit/functions/test_kernel_function_decorators.py +++ b/python/tests/unit/functions/test_kernel_function_decorators.py @@ -131,6 +131,22 @@ def test_kernel_function_param_annotated(): assert my_func.__kernel_function_parameters__[0]["name"] == "input" +def test_kernel_function_does_not_mutate_shared_annotated_metadata(): + shared = {"description": "the answer count"} + + @kernel_function + def first(value: Annotated[int, shared]) -> int: + return value + + @kernel_function + def second(value: Annotated[int, shared]) -> int: + return value + + assert shared == {"description": "the answer count"} + assert first.__kernel_function_parameters__[0]["description"] == "the answer count" + assert second.__kernel_function_parameters__[0]["description"] == "the answer count" + + def test_kernel_function_param_optional(): decorator_test = MiscClass() my_func = getattr(decorator_test, "func_input_optional")