Skip to content

FIX: GraphFlow serialize/deserialize and adding test#6434

Merged
ekzhu merged 1 commit into
microsoft:mainfrom
SongChiYoung:FIX/graph_serialized
Apr 30, 2025
Merged

FIX: GraphFlow serialize/deserialize and adding test#6434
ekzhu merged 1 commit into
microsoft:mainfrom
SongChiYoung:FIX/graph_serialized

Conversation

@SongChiYoung
Copy link
Copy Markdown
Contributor

@SongChiYoung SongChiYoung commented Apr 29, 2025

Why are these changes needed?

❗ Before

Previously, GraphFlow.init() modified the inner_chats and termination_condition for internal execution logic (e.g., constructing _StopAgent or composing OrTerminationCondition).
However, these modified values were also used during dump_component(), meaning the serialized config no longer matched the original inputs.

As a result:
1. dump_component() → load_component() → dump_component() produced non-idempotent configs.
2. Internal-only constructs like _StopAgent were mistakenly serialized, even though they should only exist in runtime.

✅ After

This patch changes the behavior to:
• Store original inner_chats and termination_condition as-is at initialization.
• During to_config(), serialize only the original unmodified versions.
• Avoid serializing _StopAgent or other dynamically built agents.
• Ensure deserialization (from_config) produces a logically equivalent object without additional nesting or duplication.

This ensures that:
• GraphFlow.dump_component() → load_component() round-trip produces consistent, minimal configs.
• Internal execution logic and serialized component structure are properly separated.

Related issue number

Closes #6431

Checks

@ekzhu
Copy link
Copy Markdown
Contributor

ekzhu commented Apr 30, 2025

@abhinav-aegis for awareness

Copy link
Copy Markdown
Contributor

@ekzhu ekzhu left a comment

Choose a reason for hiding this comment

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

Thanks for the fix!

@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 30, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 78.55%. Comparing base (8efa1f1) to head (cbdbeb0).
Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #6434      +/-   ##
==========================================
+ Coverage   78.51%   78.55%   +0.03%     
==========================================
  Files         225      225              
  Lines       16521    16523       +2     
==========================================
+ Hits        12971    12979       +8     
+ Misses       3550     3544       -6     
Flag Coverage Δ
unittests 78.55% <100.00%> (+0.03%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@abhinav-aegis
Copy link
Copy Markdown
Contributor

Thx!

@ekzhu ekzhu merged commit c7757de into microsoft:main Apr 30, 2025
62 checks passed
ChrisBlaa pushed a commit to ChrisBlaa/autogen that referenced this pull request May 8, 2025
## Why are these changes needed?
❗ Before

Previously, GraphFlow.__init__() modified the inner_chats and
termination_condition for internal execution logic (e.g., constructing
_StopAgent or composing OrTerminationCondition).
However, these modified values were also used during dump_component(),
meaning the serialized config no longer matched the original inputs.

As a result:
1. dump_component() → load_component() → dump_component() produced
non-idempotent configs.
2. Internal-only constructs like _StopAgent were mistakenly serialized,
even though they should only exist in runtime.

⸻

✅ After

This patch changes the behavior to:
• Store original inner_chats and termination_condition as-is at
initialization.
	•	During to_config(), serialize only the original unmodified versions.
	•	Avoid serializing _StopAgent or other dynamically built agents.
• Ensure deserialization (from_config) produces a logically equivalent
object without additional nesting or duplication.

This ensures that:
• GraphFlow.dump_component() → load_component() round-trip produces
consistent, minimal configs.
• Internal execution logic and serialized component structure are
properly separated.
<!-- Please give a short summary of the change and the problem this
solves. -->

## Related issue number

<!-- For example: "Closes microsoft#1234" -->
Closes microsoft#6431 

## Checks

- [ ] I've included any doc changes needed for
<https://microsoft.github.io/autogen/>. See
<https://github.com/microsoft/autogen/blob/main/CONTRIBUTING.md> to
build and test documentation locally.
- [x] I've added tests (if relevant) corresponding to the changes
introduced in this PR.
- [x] I've made sure all auto checks have passed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug: GraphFlow cannot be serialized or deserialized

3 participants