You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Python: unhashable type exception for custom return type in kernel function #10299
Add an agent to the group chat with a kernel function that returns a custom type such as AccountBalance
Invoke the agent through the group chat and let the agent invoke the kernel function that returns a list
See error
Expected behavior
Custom types in kernel function should work
Screenshots
If applicable, add screenshots to help explain your problem.
Platform
Language: Python
Source: 1.19.0
IDE: VS Code]
OS: Mac
Additional context
File "/demo/.venv/lib/python3.12/site-packages/semantic_kernel/agents/group_chat/agent_group_chat.py", line 144, in invoke
async for message in super().invoke_agent(selected_agent):
File "/demo/.venv/lib/python3.12/site-packages/semantic_kernel/agents/group_chat/agent_chat.py", line 144, in invoke_agent
async for is_visible, message in channel.invoke(agent):
File "/demo/.venv/lib/python3.12/site-packages/semantic_kernel/agents/channels/chat_history_channel.py", line 75, in invoke
mutated_history.add(mutated_message)
File "/demo/.venv/lib/python3.12/site-packages/semantic_kernel/contents/chat_message_content.py", line 318, in __hash__
return hash((self.tag, self.role, self.content, self.encoding, self.finish_reason, *self.items))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/demo/.venv/lib/python3.12/site-packages/semantic_kernel/contents/function_result_content.py", line 197, in __hash__
return hash((
^^^^^^
TypeError: unhashable type: 'AccountBalance'
Hi Abhishek Gupta (@abhirockzz), we'll improve the handling for types so the hash doesn't error. To unblock you right now, I'd advise that you make you freeze your BaseModel like:
classAccountBalance(BaseModel):
# Make the model frozen so it's hashablebalance: int=Field(..., alias="account_balance")
model_config=ConfigDict(frozen=True)
I tested this with:
deftest_hash_with_frozen_account_balance():
balance=AccountBalance(account_balance=100)
content=FunctionResultContent(
id="test_id",
result=balance,
function_name="TestFunction",
)
# Verify we can call hash without error_=hash(content)
assertTrue, "Hashing FunctionResultContent with frozen model should not raise errors."
and this passes. That would be the quickest way to handle it now while we make some improvements. Thanks for filing the issue.
Activity
moonbox3 commentedon Jan 28, 2025
Hi Abhishek Gupta (@abhirockzz), we'll improve the handling for types so the hash doesn't error. To unblock you right now, I'd advise that you make you freeze your BaseModel like:
I tested this with:
and this passes. That would be the quickest way to handle it now while we make some improvements. Thanks for filing the issue.
Python: Allow enums to be passed in to on_function_result. Improve ha…
Python: Allow enums to be passed in to on_function_result. Improve ha…