Skip to content

Some agents do not deserialize model_context (set to None or Do not serialize too) #6336

@SongChiYoung

Description

@SongChiYoung

What happened?

Describe the bug
Some agent classes, including AssistantAgent and SocietyOfMindAgent and CodeExecutorAgent fail to properly deserialize the model_context field when reconstructing from their declarative config. Even though the model_context is correctly serialized via dump_component(), it is explicitly set to None during deserialization.

This leads to the silent loss of critical context configuration, especially when using model-specific conditional transformers or inference-time metadata handlers.

To Reproduce

# at AssistantAgent
# to_config: correct serialization
model_context=self._model_context.dump_component(),

# from_config: incorrect deserialization
model_context=None,  # <-- should be ChatCompletionContext.load_component(config.model_context)

Same omission is present in SocietyOfMindAgent, where model_context is neither serialized nor deserialized.

Expected behavior
Agent reconstruction via from_config() should faithfully restore all components, including model_context, to support complete behavioral parity with the original instance.

Additional context
🧩 Affected classes:

  • AssistantAgent: model_context is serialized but not deserialized.
  • SocietyOfMindAgent: model_context is completely ignored (neither serialized nor deserialized).
  • CodeExecutorAgent: model_context is completely ignored (neither serialized nor deserialized).

🧪 Missing test coverage:

  • Round-trip serialization/deserialization test for agents with non-null model_context
  • Negative test for unsupported ChatCompletionContext types

Which packages was the bug in?

Python AgentChat (autogen-agentchat>=0.4.0)

AutoGen library version.

Python dev (main branch)

Other library version.

No response

Model used

No response

Model provider

None

Other model provider

No response

Python version

None

.NET version

None

Operating system

None

Metadata

Metadata

Assignees

No one assigned

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions