diff --git a/python/semantic_kernel/contents/function_call_content.py b/python/semantic_kernel/contents/function_call_content.py index e4ca2338111b..b8c60ba43c06 100644 --- a/python/semantic_kernel/contents/function_call_content.py +++ b/python/semantic_kernel/contents/function_call_content.py @@ -13,6 +13,7 @@ from semantic_kernel.const import DEFAULT_FULLY_QUALIFIED_NAME_SEPARATOR from semantic_kernel.contents.const import FUNCTION_CALL_CONTENT_TAG, ContentTypes from semantic_kernel.contents.kernel_content import KernelContent +from semantic_kernel.contents.utils.hashing import make_hashable from semantic_kernel.exceptions import ( ContentAdditionException, ContentInitializationError, @@ -226,7 +227,7 @@ def to_dict(self) -> dict[str, str | Any]: def __hash__(self) -> int: """Return the hash of the function call content.""" - args_hashable = frozenset(self.arguments.items()) if isinstance(self.arguments, Mapping) else None + args_hashable = make_hashable(dict(self.arguments)) if isinstance(self.arguments, Mapping) else self.arguments return hash(( self.tag, self.id, diff --git a/python/tests/unit/contents/test_function_call_content.py b/python/tests/unit/contents/test_function_call_content.py index 6cdfc4557e99..c316cd685afe 100644 --- a/python/tests/unit/contents/test_function_call_content.py +++ b/python/tests/unit/contents/test_function_call_content.py @@ -210,3 +210,20 @@ def test_fc_dump_json(function_call: FunctionCallContent): dumped == """{"metadata":{},"content_type":"function_call","id":"test","name":"Test-Function","function_name":"Function","plugin_name":"Test","arguments":"{\\"input\\": \\"world\\"}"}""" # noqa: E501 ) + + +def test_hash_with_nested_dict_arguments(): + fc = FunctionCallContent( + id="test", + name="Test-Function", + arguments={"cities": ["Paris", "Rome"], "options": {"units": "metric"}}, + ) + same = FunctionCallContent( + id="test", + name="Test-Function", + arguments={"options": {"units": "metric"}, "cities": ["Paris", "Rome"]}, + ) + other = FunctionCallContent(id="test", name="Test-Function", arguments={"cities": ["Oslo"]}) + assert hash(fc) == hash(same) + assert hash(fc) != hash(other) + assert len({fc, same, other}) == 2