[FEAT] Added GraphWorkflow topology serialization and deserialization support#1497
Open
adichaudhary wants to merge 3 commits intokyegomez:masterfrom
Open
[FEAT] Added GraphWorkflow topology serialization and deserialization support#1497adichaudhary wants to merge 3 commits intokyegomez:masterfrom
adichaudhary wants to merge 3 commits intokyegomez:masterfrom
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
Adds a lightweight, topology-only serialization format for GraphWorkflow so users can persist/share workflow structure (nodes/edges/entry/end points) without serializing full Agent state, plus an end-to-end example.
Changes:
- Added
GraphWorkflow.to_spec()to export a plain-dict topology spec (agent names, node ids, edges, entry/end points). - Added
GraphWorkflow.save_spec(path)to write the topology spec to JSON. - Added
GraphWorkflow.from_topology_spec(spec, agent_registry)to reconstruct a workflow from a spec and an agent registry, plus a runnable round-trip example.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 5 comments.
| File | Description |
|---|---|
swarms/structs/graph_workflow.py |
Introduces topology-only serialization/deserialization APIs (to_spec, save_spec, from_topology_spec). |
examples/multi_agent/graphworkflow_examples/graph_workflow_serialization.py |
Demonstrates saving a topology spec, reconstructing a workflow from it, and running both. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
…or, test coverage
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.
Description
This PR adds serialization and deserialization support to GraphWorkflow. Previously, users had no way to persist a workflow's topology — they always had to build it programmatically. Three new methods address this:
to_spec() — serializes the graph structure to a plain dict (node IDs, agent names, edges, entry/end points) without requiring Agent objects to be serializable
save_spec(path) — writes that dict to a JSON file for version control and sharing
from_topology_spec(spec, agent_registry) — reconstructs a fully initialized workflow from a spec dict plus a Dict[str, Agent] registry
This complements the existing to_json() / from_json() methods (which serialize full agent state) with a lighter-weight topology-only format suitable for diffing in PRs, storing in databases, and sharing across teams without exposing agent implementation details. A runnable example demonstrating the full round-trip is included.
Files Changed
swarms/structs/graph_workflow.py— addedto_spec(),save_spec(),from_topology_spec()examples/multi_agent/graphworkflow_examples/graph_workflow_serialization.pyIssue
#1483
Dependencies
No extra dependencies required.
Maintainer
@kyegomez
Twitter
@akc__2025
📚 Documentation preview 📚: https://swarms--1451.org.readthedocs.build/en/1451/