Skip to content
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 'list' exception in function_result_content __hash__ function #9977

Closed
berndku opened this issue Dec 15, 2024 · 1 comment · Fixed by #9978
Closed
Assignees
Labels
bug Something isn't working PR: ready for review All feedback addressed, ready for reviews python Pull requests for the Python Semantic Kernel

Comments

@berndku
Copy link

berndku commented Dec 15, 2024

Describe the bug
A TypeError: unhashable type: 'list' exception is raised when invoking the hash function of function_result_content.

To Reproduce
Steps to reproduce the behavior:

  1. Create an agent group chat
  2. Add an agent to the group chat with a kernel function that returns a list
  3. Invoke the agent through the group chat and let the agent invoke the kernel function that returns a list
  4. See error

Expected behavior
no exception if result of function_result_content is of an unhashable type

Platform

  • OS: [Windows]
  • IDE: [VS Code]
  • Language: [Python]
  • Source: [Python SDK 1.17.0]

Additional context

TypeError: unhashable type: 'list'
Traceback (most recent call last):
    async for content in group_chat.invoke():
  File "C:\Source\...\evaluation\.venv\Lib\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 "C:\Source\....\evaluation\.venv\Lib\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 "C:\Source\....\evaluation\.venv\Lib\site-packages\semantic_kernel\agents\channels\chat_history_channel.py", line 75, in invoke
    mutated_history.add(mutated_message)
  File "C:\Source\....\evaluation\.venv\Lib\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 "C:\Source\....\evaluation\.venv\Lib\site-packages\semantic_kernel\contents\function_result_content.py", line 190, in __hash__
    return hash((self.tag, self.id, self.result, self.name, self.function_name, self.plugin_name, self.encoding))
TypeError: unhashable type: 'list'
@berndku berndku added the bug Something isn't working label Dec 15, 2024
@markwallace-microsoft markwallace-microsoft added python Pull requests for the Python Semantic Kernel triage labels Dec 15, 2024
@moonbox3 moonbox3 self-assigned this Dec 16, 2024
@moonbox3 moonbox3 removed the triage label Dec 16, 2024
@moonbox3
Copy link
Contributor

Thanks for filing, @berndku. A PR with a fix will be out shortly.

@moonbox3 moonbox3 added the PR: ready for review All feedback addressed, ready for reviews label Dec 16, 2024
github-merge-queue bot pushed a commit that referenced this issue Dec 16, 2024
### Motivation and Context

Currently, the hash function in `FunctionResultContent` does not
properly handle types of list or set. Adding the proper handling to turn
these into a tuple, and then the hash function works properly.

<!-- 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:
- Makes sure the FunctionResultContent `__hash__` method can properly
handle mutable types like lists or sets
- Adds tests to ensure the new behavior works as expected
- Ensures the create message content method can handle lists or sets
when generating the content and the model can only accept a string.
- Fixes #9977

<!-- 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 😄

---------

Co-authored-by: Eduard van Valkenburg <eavanvalkenburg@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working PR: ready for review All feedback addressed, ready for reviews python Pull requests for the Python Semantic Kernel
Projects
Status: No status
Development

Successfully merging a pull request may close this issue.

3 participants