Skip to content

fix(devui): Fix serialization of dataclass events in workflow mapper#3711

Open
moti-malka wants to merge 1 commit intomicrosoft:mainfrom
moti-malka:fix/devui-serialization-and-chatmessage
Open

fix(devui): Fix serialization of dataclass events in workflow mapper#3711
moti-malka wants to merge 1 commit intomicrosoft:mainfrom
moti-malka:fix/devui-serialization-and-chatmessage

Conversation

@moti-malka
Copy link

@moti-malka moti-malka commented Feb 5, 2026

Summary

This PR fixes a serialization bug in the devui package that causes PydanticSerializationError when using workflows with group chat orchestrators.

Problem

When running devui with a workflow that uses AgentBasedGroupChatOrchestrator, users encounter:

PydanticSerializationError: Unable to serialize unknown type: <class 'agent_framework._types.AgentResponse'>

Root Cause

The _convert_workflow_event method in _mapper.py handles legacy workflow events by serializing their data field. The original implementation only checked for to_dict() method:

if raw_event_data is not None and hasattr(raw_event_data, "to_dict"):
    serialized_event_data = raw_event_data.to_dict()

However, GroupChatResponseReceivedEvent.data contains AgentExecutorResponse, which is a dataclass (not a SerializationMixin). This dataclass contains nested AgentResponse objects that Pydantic cannot serialize directly.

Solution

The MessageMapper class already has a _serialize_value() method that properly handles:

  • SerializationMixin objects (via to_dict())
  • Dataclasses (via recursive field serialization)
  • Nested structures
  • Primitive types

Changed to use this existing method instead of the limited to_dict() check.

Testing

  • Tested with devui . --log-level DEBUG running a workflow with AgentBasedGroupChatOrchestrator
  • Verified GroupChatResponseReceivedEvent serializes correctly without errors

Changes

File Change
python/packages/devui/agent_framework_devui/_mapper.py Use _serialize_value() for legacy event serialization

Backwards Compatibility

Fully backwards compatible - This change:

  • Uses an existing internal method already used elsewhere in the class
  • Doesn't change any public APIs
  • Objects with to_dict() still serialize correctly via _serialize_value()
  • Adds support for dataclasses that were previously failing

Copilot AI review requested due to automatic review settings February 5, 2026 21:47
@github-actions github-actions bot changed the title fix(devui): Fix serialization of dataclass events and ChatMessage constructor Python: fix(devui): Fix serialization of dataclass events and ChatMessage constructor Feb 5, 2026
…structor

This PR addresses two bugs in the devui package:

1. **PydanticSerializationError with AgentResponse** (_mapper.py)
   - The _convert_workflow_event method failed to serialize GroupChatResponseReceivedEvent
     because its data field contains AgentExecutorResponse (a dataclass) which holds
     AgentResponse (a SerializationMixin object)
   - The original code only checked for to_dict() method, missing dataclass objects
   - Fixed by using _serialize_value() which already handles all types: dataclasses,
     SerializationMixin, nested objects, and primitives

2. **ChatMessage constructor TypeError** (_executor.py)
   - ChatMessage.__init__() requires 'contents' as a keyword argument, not positional
   - Fixed by changing ChatMessage("user", contents) to ChatMessage("user", contents=contents)

T_EDITOR=true git rebase --continue
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes two runtime bugs in the devui package that occur when running workflows with AgentBasedGroupChatOrchestrator:

  1. Serialization error: The mapper was using to_dict() to serialize event data, but GroupChatResponseReceivedEvent.data contains AgentExecutorResponse, a dataclass that doesn't have to_dict(). The fix switches to the existing _serialize_value() method which properly handles dataclasses, SerializationMixin objects, and nested structures.

  2. ChatMessage constructor: Changed from positional to keyword argument for contents parameter, making the code more explicit and resilient to API changes.

Changes:

  • Fixed serialization of dataclass events in mapper by using _serialize_value() instead of to_dict()
  • Fixed ChatMessage constructor call to use keyword argument for contents

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
python/packages/devui/agent_framework_devui/_mapper.py Use _serialize_value() for legacy event serialization to handle dataclasses like AgentExecutorResponse
python/packages/devui/agent_framework_devui/_executor.py Use keyword argument for ChatMessage contents parameter for clarity

@moti-malka moti-malka force-pushed the fix/devui-serialization-and-chatmessage branch from e745ba4 to 41c4aef Compare February 5, 2026 21:51
@moti-malka moti-malka changed the title Python: fix(devui): Fix serialization of dataclass events and ChatMessage constructor fix(devui): Fix serialization of dataclass events in workflow mapper Feb 5, 2026
@moti-malka
Copy link
Author

@microsoft-github-policy-service agree

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants