Skip to content

Python: [Bug]: SerializationMixin does not recursively serialize nested containers #7788

Description

Description

SerializationMixin.to_dict() serializes framework objects when they are direct list items or dictionary values, but it stops after one container level. A SerializationProtocol object nested inside a combination such as dict -> list -> dict remains in the returned mapping. As a result, SerializationMixin.to_json() raises TypeError for otherwise supported nested state.

Expected: supported objects are recursively converted at any list/dictionary depth, while unsupported values keep the existing behavior of being skipped.

Actual: nested supported objects are returned unchanged and cannot be JSON encoded.

Code Sample

from agent_framework._serialization import SerializationMixin


class Item(SerializationMixin):
    def __init__(self, value: str):
        self.value = value


class Container(SerializationMixin):
    def __init__(self, payload: dict):
        self.payload = payload


container = Container({"groups": [{"items": [Item("example")]}]})
container.to_json()

Error Messages / Stack Traces

TypeError: Object of type Item is not JSON serializable

Package Versions

agent-framework-core: 1.14.0 and current main (ab6c4d2dc8573071d7f73fd8c94a8cb15a2c78a2)

Python Version

Python 3.12.14

Additional Context

The same behavior occurs for list -> dict and deeper nested dictionaries. Direct list items and direct dictionary values already serialize correctly.

Activity

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

Metadata

Metadata

Labels

agentsUsage: [Issues, PRs], Target: Single agentpythonUsage: [Issues, PRs], Target: PythonreproducedUsage: [Issues], Target: all issues that can be reproduced by the triage workflow

Type

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions