Skip to content

Python: Workflow Edge Groups - #393

Merged
Tao Chen (TaoChenOSU) merged 13 commits into
mainfrom
taochen/python-workflow-edge-groups
Aug 15, 2025
Merged

Python: Workflow Edge Groups#393
Tao Chen (TaoChenOSU) merged 13 commits into
mainfrom
taochen/python-workflow-edge-groups

Conversation

@TaoChenOSU

@TaoChenOSUTao Chen (TaoChenOSU) commented Aug 11, 2025

Copy link
Copy Markdown
Contributor

Motivation and Context

Addresses: #357
Related comment: #271 (comment)

Description

  1. Introducing Edge groups
  2. Adding the following edge groups:
    • SingleEdgeGroup
    • FanOutEdgeGroup
    • FanInEdgeGroup
    • SwitchCaseEdgeGroup
  3. Adding tests and samples

Contribution Checklist

  • The code builds clean without any errors or warnings
  • The PR follows the Contribution Guidelines
  • All unit tests pass, and I have added new tests where possible
  • I didn't break anyone 😄

CopilotAI review requested due to automatic review settings August 11, 2025 19:01
@TaoChenOSUTao Chen (TaoChenOSU) added python Usage: [Issues, PRs], Target: Python workflow labels Aug 11, 2025
@github-actionsgithub-actionsBot changed the title Workflow Edge GroupsPython: Workflow Edge GroupsAug 11, 2025

CopilotAI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull Request Overview

This pull request introduces the concept of "Edge Groups" to the workflow framework, providing a more organized and flexible way to handle connections between workflow executors. The PR implements several types of edge groups to support different connection patterns, moving away from individual edge management to group-based edge management.

  • Introduces the abstract EdgeGroup base class and five concrete implementations: SingleEdgeGroup, SourceEdgeGroup, TargetEdgeGroup, ConditionalEdgeGroup, and PartitioningEdgeGroup
  • Updates the workflow builder to use edge groups instead of individual edges, providing new methods for conditional and partitioning fan-out patterns
  • Refactors the validation system and runner to work with edge groups while maintaining backward compatibility

Reviewed Changes

Copilot reviewed 12 out of 12 changed files in this pull request and generated 3 comments.

Show a summary per file
FileDescription
step_06_map_reduce.pyCleanup of unused imports and code formatting improvements
step_00_foundation_patterns.pyNew comprehensive sample demonstrating all edge group patterns with simple arithmetic operations
test_workflow_builder.pyUpdated test assertion to check edge groups count instead of individual edges
test_validation.pyUpdated validation tests to use SingleEdgeGroup instead of raw Edge objects
test_runner.pyUpdated runner tests to use SingleEdgeGroup for consistency
test_edge.pyAdded extensive test coverage for all new edge group implementations
_workflow.pyMajor refactor to use edge groups, added new builder methods for conditional and partitioning patterns
_validation.pyUpdated validation logic to work with edge groups while maintaining type compatibility checks
_typing_utils.pyAdded handling for Any type in type checking utility
_runner.pyRefactored to work with edge groups instead of individual edges
_executor.pyEnhanced executor ID generation to include class name for better debugging
_edge.pyMajor expansion adding the EdgeGroup hierarchy and all concrete implementations

Comment threadpython/packages/workflow/agent_framework_workflow/_edge.py
Comment threadpython/packages/workflow/agent_framework_workflow/_edge.py
Comment threadpython/packages/workflow/agent_framework_workflow/_edge.py Outdated
@lokitoth

Jacob Alber (lokitoth) commented Aug 11, 2025

Copy link
Copy Markdown
Contributor

Something to consider here is that keeping the low-level set of edge types the minimal needed to implement all of the conceptual edges we want to support makes the toolkit more portable acros platforms. To that end, SourceEdgeGroup and ConditionalEdgeGroup become specializations of PartitionerEdgeGroup (if you allow the partitioner to be None, and interpret that as SourceEdgeGroup, and a partition function which always returns only a single index is equivalent to a conditional edge group).

At the same time, having a richer set of types could make tooling easier, as it would allow tools to better understand the intent of an edge-group (conditional vs. partitioner). (Maybe we should support some kind of metadata through which higher-level toolkits could include information for tooling/visualization?)

Comment threadpython/packages/workflow/agent_framework_workflow/_edge.py Outdated
Comment threadpython/packages/workflow/agent_framework_workflow/_edge.py
Comment threadpython/packages/workflow/agent_framework_workflow/_edge.py
Comment threadpython/packages/workflow/agent_framework_workflow/_edge.py Outdated
Comment threadpython/packages/workflow/agent_framework_workflow/_edge.py Outdated
@TaoChenOSU

Copy link
Copy Markdown
ContributorAuthor

Something to consider here is that keeping the low-level set of edge types the minimal needed to implement all of the conceptual edges we want to support makes the toolkit more portable acros platforms. To that end, SourceEdgeGroup and ConditionalEdgeGroup become specializations of PartitionerEdgeGroup (if you allow the partitioner to be None, and interpret that as SourceEdgeGroup, and a partition function which always returns only a single index is equivalent to a conditional edge group).

At the same time, having a richer set of types could make tooling easier, as it would allow tools to better understand the intent of an edge-group (conditional vs. partitioner). (Maybe we should support some kind of metadata through which higher-level toolkits could include information for tooling/visualization?)

Good point!

  1. I think the SourceEdgeGroup is indeed a specialized version of the PartitioningEdgeGroup with a None partitioner. Currently, it's the opposite. The PartitioningEdgeGroup is a specialized version of the SourceEdgeGroup. But I don't think the ConditionalEdgeGroup can be a special case of partitioning unless we have a way to restrict the partitioner function to always return a single index, which would require a different signture.
  2. Are you proposing some metadata for the type of the group?
    For example,
@propertydeftype(self) ->str:
returnself.__class__.__name__

@lokitoth

Jacob Alber (lokitoth) commented Aug 11, 2025

Copy link
Copy Markdown
Contributor

The reason I think ConditionalEdgeGroup is a "special case" is that you can implement it on top of PartitionerEdgeGroup. So when someone calls .add_conditional_fan_out_edges, rather than create a new type, create a partitioner function that returns the index of the first condition that passes (or the index of the "else" edge, if any).

Are you proposing some metadata for the type of the group?

No, I do not really have a concrete proposal. Just if we do what I suggest above, we want some way for tooling to be able to go back to the higher-level concept. Like the [DesignerXYZAttribute] in .NET. Probably need to be talking to the tooling teams to really understand the requirements here, if any.

Comment threadpython/packages/workflow/agent_framework_workflow/_workflow.py Outdated

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I have some big disagreements here, mostly with the terminology, and I think the code can be much simpler!

Comment threadpython/packages/workflow/agent_framework_workflow/_edge.py
Comment threadpython/packages/workflow/agent_framework_workflow/_edge.py
Comment threadpython/packages/workflow/agent_framework_workflow/_workflow.py Outdated
Comment threadpython/packages/workflow/agent_framework_workflow/_edge.py Outdated
Comment threadpython/samples/getting_started/workflow/step_00_foundation_patterns.py Outdated
Comment threadpython/samples/getting_started/workflow/step_00_foundation_patterns.py Outdated
Comment threadpython/samples/getting_started/workflow/step_00_foundation_patterns.py Outdated
Comment threadpython/packages/workflow/agent_framework_workflow/_edge.py Outdated
@eavanvalkenburg

Eduard van Valkenburg (eavanvalkenburg) commented Aug 12, 2025

Copy link
Copy Markdown
Member

Python Test Coverage

Python Test Coverage Report •
FileStmtsMissCoverMissing
packages/workflow/agent_framework_workflow
_edge.py168994%74, 86, 99, 118, 123, 128, 133, 138, 417
_executor.py1092081%62, 80, 236–240, 245, 247–250, 254–256, 258, 262, 264–265, 330
_runner.py1702883%84–86, 88, 166–168, 189–193, 197, 201–202, 223–224, 236–237, 248–250, 254, 261–263, 268–269
_typing_utils.py19952%18, 30, 37–40, 47–48, 54
_validation.py2112190%197, 315, 318, 376, 380, 467, 469, 472–473, 475–477, 479–481, 484–488, 493
_workflow.py1813381%52, 118, 140, 190, 198–200, 212, 226, 344, 364–365, 367–369, 384–386, 394–395, 404–410, 415, 417, 489, 491, 513, 515
TOTAL4441100277%

Python Unit Test Overview

TestsSkippedFailuresErrorsTime
51131 💤0 ❌0 🔥8.689s ⏱️

Comment threadpython/samples/getting_started/workflow/step_00_foundation_patterns.py Outdated

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

small comment on the naming, but looking much better!

Comment threadpython/packages/workflow/agent_framework_workflow/_edge.py Outdated
Comment threadpython/packages/workflow/agent_framework_workflow/_edge.py Outdated
@ekzhu
Eric Zhu (ekzhu) added this pull request to the merge queueAug 14, 2025
@github-merge-queue
github-merge-queueBot removed this pull request from the merge queue due to failed status checks Aug 15, 2025
@TaoChenOSU
Tao Chen (TaoChenOSU) added this pull request to the merge queueAug 15, 2025
@github-merge-queue
github-merge-queueBot removed this pull request from the merge queue due to failed status checks Aug 15, 2025
@ekzhu
Eric Zhu (ekzhu) added this pull request to the merge queueAug 15, 2025
@github-merge-queue
github-merge-queueBot removed this pull request from the merge queue due to failed status checks Aug 15, 2025
@TaoChenOSU
Tao Chen (TaoChenOSU) added this pull request to the merge queueAug 15, 2025
@github-merge-queue
github-merge-queueBot removed this pull request from the merge queue due to failed status checks Aug 15, 2025
@github-merge-queue
github-merge-queueBot removed this pull request from the merge queue due to failed status checks Aug 15, 2025
@github-merge-queue
github-merge-queueBot removed this pull request from the merge queue due to failed status checks Aug 15, 2025
@TaoChenOSU
Tao Chen (TaoChenOSU) added this pull request to the merge queueAug 15, 2025
@github-merge-queue
github-merge-queueBot removed this pull request from the merge queue due to failed status checks Aug 15, 2025
@TaoChenOSU
Tao Chen (TaoChenOSU) added this pull request to the merge queueAug 15, 2025
Merged via the queue into main with commit ed86baaAug 15, 2025
22 checks passed
@github-project-automationgithub-project-automationBot moved this from In Review to Done in Agent FrameworkAug 15, 2025
@crickman
Chris (crickman) deleted the taochen/python-workflow-edge-groups branch August 19, 2025 17:06
@ekzhuEric Zhu (ekzhu) linked an issue Aug 19, 2025 that may be closed by this pull request
Reuben Bond (ReubenBond) pushed a commit to ReubenBond/agent-framework that referenced this pull request Oct 28, 2025
* Introducing edge groups
* Add conditional and partitioning edge groups; next add samples and tests
* Add unit tests
* Add samples
* Address comments 1
* Address comments 2
* Update conditional edge group to take in cases and default
* Minor updates to sample
* Collapsing Paritioning Edge group and Conditional Edge group to source edge group
* Improve sample clarity
* Name consolidation
---------
Co-authored-by: Eric Zhu <ekzhu@users.noreply.github.com>
AQ-1970 (Arturo-Quiroga-MSFT) pushed a commit to Arturo-Quiroga-MSFT/agent-framework-public that referenced this pull request Nov 23, 2025
* Introducing edge groups
* Add conditional and partitioning edge groups; next add samples and tests
* Add unit tests
* Add samples
* Address comments 1
* Address comments 2
* Update conditional edge group to take in cases and default
* Minor updates to sample
* Collapsing Paritioning Edge group and Conditional Edge group to source edge group
* Improve sample clarity
* Name consolidation
---------
Co-authored-by: Eric Zhu <ekzhu@users.noreply.github.com>
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pythonUsage: [Issues, PRs], Target: Python

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

Conditional edge group

7 participants

@TaoChenOSU@lokitoth@eavanvalkenburg@ekzhu@alliscode@moonbox3