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

  1. added
    pythonUsage: [Issues, PRs], Target: Python
    triageUsage: [Issues], Target: All issues that still need to be triaged
    on Aug 20, 2026
  2. added
    reproducedUsage: [Issues], Target: all issues that can be reproduced by the triage workflow
    on Aug 21, 2026
  3. github-actions commented on Aug 21, 2026

    @github-actions
    Contributor

    🤖 Automated triage reproduction notes (agent-authored — trust but verify)

    Agent analysis

    Repro: python/packages/core/agent_framework/_serialization.py::SerializationMixin.to_dict at lines 345-389 stops traversing when a list or dictionary contains another container, and to_json fails at line 416. Trigger it with a SerializationMixin attribute shaped as dict -> list -> dict -> list -> SerializationMixin; the focused test constructs that shape and observes TypeError: Object of type Item is not JSON serializable.

    • Failing test: python/packages/core/tests/core/test_serializable_mixin.py::TestSerializationMixin::test_to_json_with_serialization_protocol_in_nested_containers
    • Files examined: python/packages/core/agent_framework/_serialization.py, python/packages/core/tests/core/test_serializable_mixin.py, python/packages/core/pyproject.toml, python/pyproject.toml
    • Tests run: test_to_json_with_serialization_protocol_in_nested_containers, test_to_dict_with_list_of_serialization_protocol, test_to_dict_with_dict_containing_serialization_protocol
    • Reported version: 1.14.0
    • Current version: 1.14.0
  4. added
    agentsUsage: [Issues, PRs], Target: Single agent
    and removed
    triageUsage: [Issues], Target: All issues that still need to be triaged
    on Aug 21, 2026
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