Skip to content

Python: @kernel_function mutates shared Annotated metadata dicts (description lost after first use) #14441

Description

Description

@kernel_function's _parse_parameter() calls meta.pop("description") on dict metadata inside typing.Annotated, mutating the caller's dict. Reusing one shared metadata dict across kernel functions silently strips the parameter description from every function after the first, and leaves the user's dict empty.

Reproduction

from typing import Annotated
from semantic_kernel.functions.kernel_function_decorator import kernel_function
from semantic_kernel.functions import KernelFunctionFromMethod

shared = {"description": "the answer count"}

@kernel_function
def a(x: Annotated[int, shared]) -> int: ...

@kernel_function
def b(y: Annotated[int, shared]) -> int: ...

KernelFunctionFromMethod(a, "a").metadata.parameters[0].description  # 'the answer count'
KernelFunctionFromMethod(b, "b").metadata.parameters[0].description  # None  <-- lost
shared  # {}  <-- caller's dict mutated

Expected behavior

Decoration never mutates caller-owned metadata; both functions see the description.

Environment

semantic-kernel python main (ca40aa72), Python 3.12

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    pythonPull requests for the Python Semantic Kerneltriage

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions