Skip to content

fix(memory): restore MemoryMimeType enum on load instead of degrading to str - #8294

Open
JingHao-Leon wants to merge 1 commit into
microsoft:mainfrom
JingHao-Leon:fix/memory-mime-type-roundtrip
Open

JingHao-Leon wants to merge 1 commit into
microsoft:mainfrom
JingHao-Leon:fix/memory-mime-type-roundtrip

Conversation

@JingHao-Leon

Copy link
Copy Markdown

Description

MemoryContent serializes mime_type to its string value (field_serializer) but had no inverse step, so a dump_component()/load_component() roundtrip (e.g. saving and restoring a ListMemory) degraded a MemoryMimeType into a plain str. Any dispatch on mime_type == MemoryMimeType.X — user code and autogen_ext memory implementations that filter by MIME type — silently changed behavior after a save/load.

Changes

  • MemoryContent: add a before-mode field_validator that coerces known MIME strings back to their MemoryMimeType members; unrecognized custom strings pass through unchanged (preserving the MemoryMimeType | str contract)
  • Tests: enum survives the roundtrip (is MemoryMimeType.MARKDOWN); custom unrecognized strings keep passing through

Related issue

Fixes #8293

Verification

pytest python/packages/autogen-core/tests/test_memory.py
-> 12 passed (10 existing + 2 new)

Same class of roundtrip type-degeneration as #8283 / PR #8292 (FunctionTool strict); this one needed the inverse direction — a validator on the way in rather than persisting the field.

… to str

MemoryContent serializes mime_type to its string value but had no inverse
step, so a dump_component/load_component roundtrip degraded a MemoryMimeType
into a plain str. Any dispatch on mime_type == MemoryMimeType.X (user code
and autogen_ext memory implementations filtering by MIME type) silently
changed behavior after a save/load.

Add a before-mode field_validator that coerces known MIME strings back to
their enum members, keeping unrecognized custom strings unchanged, and cover
both the roundtrip and the pass-through in tests.

Fixes microsoft#8293

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: MemoryContent.mime_type enum degenerates to str after dump/load roundtrip (ListMemory)

1 participant