-
Notifications
You must be signed in to change notification settings - Fork 3.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Python: unhashable type exception for custom return type in kernel function #10299
Comments
markwallace-microsoft
added
python
Pull requests for the Python Semantic Kernel
triage
labels
Jan 27, 2025
Hi @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: class AccountBalance(BaseModel):
# Make the model frozen so it's hashable
balance: int = Field(..., alias="account_balance")
model_config = ConfigDict(frozen=True) I tested this with: def test_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)
assert True, "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. |
4 tasks
github-merge-queue bot
pushed a commit
that referenced
this issue
Jan 28, 2025
…ndling FRC result so it can be hashed. (#10316) ### Motivation and Context Two topics in this PR: - A request to be able to pass in Enums to the Python process `on_function_result`, instead of just strings. - There were some custom types (Pydantic models) that were unable to hash during an agent group chat. One could mark the model `frozen` so that it is hashable; however, we should add better handling in our code, in case a dev doesn't want to do that. <!-- Thank you for your contribution to the semantic-kernel repo! Please help reviewers and future users, providing the following information: 1. Why is this change required? 2. What problem does it solve? 3. What scenario does it contribute to? 4. If it fixes an open issue, please link to the issue here. --> ### Description This PR: - checks if the function name in `on_function_result` in our process framework is an enum, if so, convert to a string. - improves the parsing of the `result` in `FunctionResultContent` so that it can be included in the hash function during an agent group chat. Adding tests to handle multiple different scenarios. - Closes #10299 - Closes #10305 <!-- Describe your changes, the overall approach, the underlying design. These notes will help understanding how your code works. Thanks! --> ### Contribution Checklist <!-- Before submitting this PR, please make sure: --> - [X] The code builds clean without any errors or warnings - [X] The PR follows the [SK Contribution Guidelines](https://github.com/microsoft/semantic-kernel/blob/main/CONTRIBUTING.md) and the [pre-submission formatting script](https://github.com/microsoft/semantic-kernel/blob/main/CONTRIBUTING.md#development-scripts) raises no violations - [X] All unit tests pass, and I have added new tests where possible - [X] I didn't break anyone 😄
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Describe the bug
TypeError: unhashable type: 'AccountBalance'
I am using a kernel function that returns a custom type:
To Reproduce
Steps to reproduce the behavior:
AccountBalance
Expected behavior
Custom types in kernel function should work
Screenshots
If applicable, add screenshots to help explain your problem.
Platform
Additional context
The text was updated successfully, but these errors were encountered: