Python: fix(ag-ui): properly handle json serialize with handoff workflows as agent#3275
Merged
moonbox3 merged 3 commits intomicrosoft:mainfrom Jan 21, 2026
Merged
Python: fix(ag-ui): properly handle json serialize with handoff workflows as agent#3275moonbox3 merged 3 commits intomicrosoft:mainfrom
moonbox3 merged 3 commits intomicrosoft:mainfrom
Conversation
Member
Python Test Coverage Report •
Python Unit Test Overview
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Contributor
There was a problem hiding this comment.
Pull request overview
This PR fixes a JSON serialization crash in AG-UI when using handoff workflows as agents. The server previously crashed with TypeError: Object of type HandoffAgentUserRequest is not JSON serializable when attempting to serialize dataclass objects containing nested SerializationMixin objects (which use to_dict() methods).
Changes:
- Enhanced
make_json_safe()to supportto_dict()method and recursively process all serialization method outputs - Updated three locations in
_events.pyto usemake_json_safe()before JSON encoding function call arguments - Added comprehensive test coverage for dataclasses with nested objects and SerializationMixin patterns
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| python/packages/ag-ui/agent_framework_ag_ui/_utils.py | Added support for to_dict() method in make_json_safe() and made all serialization methods recursive |
| python/packages/ag-ui/agent_framework_ag_ui/_events.py | Applied make_json_safe() to function call arguments in three locations before JSON encoding |
| python/packages/ag-ui/tests/test_utils.py | Added unit tests for to_dict() method handling and nested dataclass serialization |
| python/packages/ag-ui/tests/test_events_comprehensive.py | Added integration tests for dataclass and nested dataclass arguments in function calls |
eavanvalkenburg
approved these changes
Jan 19, 2026
dmytrostruk
approved these changes
Jan 21, 2026
arisng
pushed a commit
to arisng/agent-framework
that referenced
this pull request
Feb 2, 2026
…lows as agent (microsoft#3275) * fix(ag-ui): properly handle json serialize with handoff workflows as agent * Other improvements around handling non-serializable objects
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Motivation and Context
When using AG-UI with a Handoff workflow (as an agent), the server crashes with
TypeError: Object of type HandoffAgentUserRequest is not JSON serializablethe first time a handoff agent requests user input. This occurs becauseHandoffAgentUserRequestis a dataclass containing anAgentResponse(which usesSerializationMixin), and the AG-UI event bridge callsjson.dumps()directly on these objects without converting them to serializable dictionaries first.The fix updates make
_json_safe()in_utils.pyto handleto_dict()methods (used bySerializationMixin) and to recursively process results fromas_dict(),model_dump(),to_dict(), anddict()calls to make sure nested non-serializable objects are also converted. The three locations in_events.pythat serialize function call arguments now usemake_json_safe()to properly handle dataclasses and SerializationMixin objects before JSON encoding.Description
Contribution Checklist