Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion python/semantic_kernel/contents/function_call_content.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
17 changes: 17 additions & 0 deletions python/tests/unit/contents/test_function_call_content.py
Original file line number Diff line number Diff line change
Expand Up @@ -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