fix(devui): Fix serialization of dataclass events in workflow mapper#3711
fix(devui): Fix serialization of dataclass events in workflow mapper#3711moti-malka wants to merge 1 commit intomicrosoft:mainfrom
Conversation
…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
There was a problem hiding this comment.
Pull request overview
This PR fixes two runtime bugs in the devui package that occur when running workflows with AgentBasedGroupChatOrchestrator:
-
Serialization error: The mapper was using
to_dict()to serialize event data, butGroupChatResponseReceivedEvent.datacontainsAgentExecutorResponse, a dataclass that doesn't haveto_dict(). The fix switches to the existing_serialize_value()method which properly handles dataclasses, SerializationMixin objects, and nested structures. -
ChatMessage constructor: Changed from positional to keyword argument for
contentsparameter, making the code more explicit and resilient to API changes.
Changes:
- Fixed serialization of dataclass events in mapper by using
_serialize_value()instead ofto_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 |
e745ba4 to
41c4aef
Compare
|
@microsoft-github-policy-service agree |
Summary
This PR fixes a serialization bug in the devui package that causes
PydanticSerializationErrorwhen using workflows with group chat orchestrators.Problem
When running
devuiwith a workflow that usesAgentBasedGroupChatOrchestrator, users encounter:Root Cause
The
_convert_workflow_eventmethod in_mapper.pyhandles legacy workflow events by serializing theirdatafield. The original implementation only checked forto_dict()method:However,
GroupChatResponseReceivedEvent.datacontainsAgentExecutorResponse, which is a dataclass (not aSerializationMixin). This dataclass contains nestedAgentResponseobjects that Pydantic cannot serialize directly.Solution
The
MessageMapperclass already has a_serialize_value()method that properly handles:SerializationMixinobjects (viato_dict())Changed to use this existing method instead of the limited
to_dict()check.Testing
devui . --log-level DEBUGrunning a workflow withAgentBasedGroupChatOrchestratorGroupChatResponseReceivedEventserializes correctly without errorsChanges
python/packages/devui/agent_framework_devui/_mapper.py_serialize_value()for legacy event serializationBackwards Compatibility
✅ Fully backwards compatible - This change:
to_dict()still serialize correctly via_serialize_value()