fix(core): restore MemoryMimeType enum on mime_type after component roundtrip - #8295
Open
JingHao-Leon wants to merge 1 commit into
Open
JingHao-Leon wants to merge 1 commit into
JingHao-Leon wants to merge 1 commit into
Conversation
…oundtrip MemoryContent serializes mime_type enum values to their string form (added in microsoft#5688 to fix JSON serialization), but nothing restored the enum on the way back in. After a dump_component()/load_component() roundtrip (e.g. saving and restoring a ListMemory), mime_type degenerated from MemoryMimeType.MARKDOWN to the plain string 'text/markdown', so equality comparisons against the enum flipped to False and any code dispatching on mime_type silently changed behavior after a save/load. Add a before-validator that coerces strings matching a MemoryMimeType value back to the enum member, leaving custom MIME-type strings as str. Regression test included. Fixes microsoft#8293
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What happened?
MemoryContent.mime_typeacceptsMemoryMimeType | strand serializes enum values to their string form viafield_serializer(added in #5688 to fix "Object of type MemoryMimeType is not JSON serializable"). Nothing restored the enum on the way back in, so after adump_component()/load_component()roundtrip (e.g. saving and restoring aListMemory),mime_typedegenerated to a plainstr:Any code that dispatches on
content.mime_type == MemoryMimeType.TEXT(user code, orautogen_extmemory implementations) works before a save/load and silently changes behavior after it.Fixes #8293 (which has the full repro and version details).
Are you a new contributor?
How did you test it?
test_list_memory_mime_type_roundtrip_restores_enuminpython/packages/autogen-core/tests/test_memory.py: dumps aListMemoryholding aMemoryMimeType.MARKDOWNitem, loads it back, asserts the enum member is restored and that a custom MIME string staysstr.pytest tests/test_memory.py→ 11 passed (10 existing + 1 new) with the fix; the new test fails onmainwithout it.MemoryMimeTypewith equalityTrue.