Skip to content

[FEAT] Added GraphWorkflow topology serialization and deserialization support#1497

Open
adichaudhary wants to merge 3 commits intokyegomez:masterfrom
adichaudhary:feat/graph-workflow-serialization
Open

[FEAT] Added GraphWorkflow topology serialization and deserialization support#1497
adichaudhary wants to merge 3 commits intokyegomez:masterfrom
adichaudhary:feat/graph-workflow-serialization

Conversation

@adichaudhary
Copy link
Copy Markdown
Contributor

@adichaudhary adichaudhary commented Mar 23, 2026

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 — added to_spec(), save_spec(), from_topology_spec()
  • examples/multi_agent/graphworkflow_examples/graph_workflow_serialization.py

Issue

#1483

Dependencies

No extra dependencies required.

Maintainer

@kyegomez

Twitter

@akc__2025

📚 Documentation preview 📚: https://swarms--1451.org.readthedocs.build/en/1451/

Copilot AI review requested due to automatic review settings March 23, 2026 23:00
Copy link
Copy Markdown
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

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.

adichaudhary and others added 2 commits March 23, 2026 19:08
@github-actions github-actions bot added the tests label Mar 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants