Skip to content

Python: Workflow Edge Groups#393

Merged
TaoChenOSU merged 13 commits intomainfrom
taochen/python-workflow-edge-groups
Aug 15, 2025
Merged

Python: Workflow Edge Groups#393
TaoChenOSU merged 13 commits intomainfrom
taochen/python-workflow-edge-groups

Conversation

@TaoChenOSU
Copy link
Copy Markdown
Contributor

@TaoChenOSU TaoChenOSU commented Aug 11, 2025

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 😄

@TaoChenOSU TaoChenOSU self-assigned this Aug 11, 2025
Copilot AI review requested due to automatic review settings August 11, 2025 19:01
@github-actions github-actions Bot changed the title Workflow Edge Groups Python: Workflow Edge Groups Aug 11, 2025
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

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
File Description
step_06_map_reduce.py Cleanup of unused imports and code formatting improvements
step_00_foundation_patterns.py New comprehensive sample demonstrating all edge group patterns with simple arithmetic operations
test_workflow_builder.py Updated test assertion to check edge groups count instead of individual edges
test_validation.py Updated validation tests to use SingleEdgeGroup instead of raw Edge objects
test_runner.py Updated runner tests to use SingleEdgeGroup for consistency
test_edge.py Added extensive test coverage for all new edge group implementations
_workflow.py Major refactor to use edge groups, added new builder methods for conditional and partitioning patterns
_validation.py Updated validation logic to work with edge groups while maintaining type compatibility checks
_typing_utils.py Added handling for Any type in type checking utility
_runner.py Refactored to work with edge groups instead of individual edges
_executor.py Enhanced executor ID generation to include class name for better debugging
_edge.py Major expansion adding the EdgeGroup hierarchy and all concrete implementations

Comment thread python/packages/workflow/agent_framework_workflow/_edge.py
Comment thread python/packages/workflow/agent_framework_workflow/_edge.py
Comment thread python/packages/workflow/agent_framework_workflow/_edge.py Outdated
@lokitoth
Copy link
Copy Markdown
Member

lokitoth commented Aug 11, 2025

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 thread python/packages/workflow/agent_framework_workflow/_edge.py Outdated
Comment thread python/packages/workflow/agent_framework_workflow/_edge.py
Comment thread python/packages/workflow/agent_framework_workflow/_edge.py
Comment thread python/packages/workflow/agent_framework_workflow/_edge.py Outdated
Comment thread python/packages/workflow/agent_framework_workflow/_edge.py Outdated
@TaoChenOSU
Copy link
Copy Markdown
Contributor Author

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,
@property
def type(self) -> str:
    return self.__class__.__name__

@lokitoth
Copy link
Copy Markdown
Member

lokitoth commented Aug 11, 2025

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 thread python/packages/workflow/agent_framework_workflow/_workflow.py Outdated
Copy link
Copy Markdown
Member

@eavanvalkenburg eavanvalkenburg left a comment

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 thread python/packages/workflow/agent_framework_workflow/_edge.py
Comment thread python/packages/workflow/agent_framework_workflow/_edge.py
Comment thread python/packages/workflow/agent_framework_workflow/_workflow.py Outdated
Comment thread python/packages/workflow/agent_framework_workflow/_edge.py Outdated
Comment thread python/samples/getting_started/workflow/step_00_foundation_patterns.py Outdated
Comment thread python/samples/getting_started/workflow/step_00_foundation_patterns.py Outdated
Comment thread python/samples/getting_started/workflow/step_00_foundation_patterns.py Outdated
Comment thread python/packages/workflow/agent_framework_workflow/_edge.py Outdated
@eavanvalkenburg
Copy link
Copy Markdown
Member

eavanvalkenburg commented Aug 12, 2025

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

Tests Skipped Failures Errors Time
511 31 💤 0 ❌ 0 🔥 8.689s ⏱️

Comment thread python/samples/getting_started/workflow/step_00_foundation_patterns.py Outdated
@TaoChenOSU TaoChenOSU moved this to In Review in Agent Framework Aug 13, 2025
Copy link
Copy Markdown
Member

@eavanvalkenburg eavanvalkenburg left a comment

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 thread python/packages/workflow/agent_framework_workflow/_edge.py Outdated
Comment thread python/packages/workflow/agent_framework_workflow/_edge.py Outdated
@ekzhu ekzhu enabled auto-merge August 14, 2025 23:45
@ekzhu ekzhu added this pull request to the merge queue Aug 14, 2025
@github-merge-queue github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Aug 15, 2025
@TaoChenOSU TaoChenOSU added this pull request to the merge queue Aug 15, 2025
@github-merge-queue github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Aug 15, 2025
@ekzhu ekzhu added this pull request to the merge queue Aug 15, 2025
@github-merge-queue github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Aug 15, 2025
@TaoChenOSU TaoChenOSU added this pull request to the merge queue Aug 15, 2025
@github-merge-queue github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Aug 15, 2025
@eavanvalkenburg eavanvalkenburg added this pull request to the merge queue Aug 15, 2025
@github-merge-queue github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Aug 15, 2025
@eavanvalkenburg eavanvalkenburg added this pull request to the merge queue Aug 15, 2025
@github-merge-queue github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Aug 15, 2025
@TaoChenOSU TaoChenOSU added this pull request to the merge queue Aug 15, 2025
@github-merge-queue github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Aug 15, 2025
@TaoChenOSU TaoChenOSU added this pull request to the merge queue Aug 15, 2025
Merged via the queue into main with commit ed86baa Aug 15, 2025
22 checks passed
@github-project-automation github-project-automation Bot moved this from In Review to Done in Agent Framework Aug 15, 2025
@crickman crickman deleted the taochen/python-workflow-edge-groups branch August 19, 2025 17:06
@ekzhu ekzhu linked an issue Aug 19, 2025 that may be closed by this pull request
@ekzhu ekzhu mentioned this pull request Aug 19, 2025
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>
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 free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

Conditional edge group

7 participants