Skip to content

Commit e50fbd0

Browse files
nimanikooCopilot
andauthored
Update python/semantic_kernel/functions/kernel_function.py
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
1 parent 7e062b6 commit e50fbd0

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

python/semantic_kernel/functions/kernel_function.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -388,11 +388,12 @@ def function_copy(self, plugin_name: str | None = None) -> "KernelFunction":
388388
KernelFunction: The copied function.
389389
"""
390390
cop: KernelFunction = copy(self)
391-
cop.metadata = self.metadata.model_copy(update={"plugin_name": plugin_name}, deep=True)
392-
cop.metadata.plugin_name = plugin_name
393-
else:
394-
# Reuse reference when no modification needed (safe as metadata is immutable in practice)
395-
cop.metadata = self.metadata
391+
# Always deep-copy metadata to avoid shared mutable state between function copies.
392+
new_plugin_name = plugin_name if plugin_name is not None else self.metadata.plugin_name
393+
cop.metadata = self.metadata.model_copy(
394+
update={"plugin_name": new_plugin_name},
395+
deep=True,
396+
)
396397
return cop
397398

398399
def _handle_exception(self, current_span: trace.Span, exception: Exception, attributes: dict[str, str]) -> None:

0 commit comments

Comments
 (0)