Repository navigation
Fix MemoryContent.mime_type degenerating to str after dump/load roundtrip - #8379
Closed
zhouh (OUAO-FRANK) wants to merge 1 commit into
Closed
zhouh (OUAO-FRANK) wants to merge 1 commit into
zhouh (OUAO-FRANK) wants to merge 1 commit into
Conversation
…trip MemoryContent serializes an enum mime_type to its string value, but had no inverse validator, so a ListMemory dump_component()/load_component() roundtrip left mime_type as a plain str. Code that dispatches on `content.mime_type is MemoryMimeType.X` silently changed behaviour after a save/load. Coerce a string matching an enum value back to MemoryMimeType on validation; other custom MIME-type strings stay strings.
Author
|
Closing this myself: I opened it before noticing the project is archived and no longer maintained (README points to microsoft/agent-framework as the successor). No point adding to an unmaintained repo. Sorry for the noise. |
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.
Why are these changes needed?
MemoryContent.mime_typeacceptsMemoryMimeType | str, and afield_serializerwrites an enum member as its string value. There was no matching validator on the way back in, so after adump_component()/load_component()roundtrip (e.g. saving and restoring aListMemory) the enum degenerated into a plainstr. Any code that dispatches oncontent.mime_type is MemoryMimeType.Xsilently changed behaviour after a save/load.This adds a
field_validator(mode="before")that coerces a string matching an enum value back toMemoryMimeType, while leaving arbitrary custom MIME-type strings asstr.Related issue number
Closes #8293
Checks
Testing
Added
test_memory_mime_type_roundtripandtest_memory_mime_type_custom_string_stays_strtopython/packages/autogen-core/tests/test_memory.py. The roundtrip test fails on the previous code ('text/markdown'vs the enum) and passes now; the custom-string test guards against over-coercing unknown MIME types.ruff checkandruff format --check(v0.4.8) are clean on the two changed files.