Skip to content

Python: Add factory pattern to concurrent orchestration builder - #2738

Merged
Tao Chen (TaoChenOSU) merged 13 commits into
microsoft:mainfrom
TaoChenOSU:taochen/python-factory-pattern-to-concurrent-builder
Dec 11, 2025
Merged

Tao Chen (TaoChenOSU) merged 13 commits into
microsoft:mainfrom
TaoChenOSU:taochen/python-factory-pattern-to-concurrent-builder

Conversation

@TaoChenOSU

@TaoChenOSU Tao Chen (TaoChenOSU) commented Dec 10, 2025 •

Copy link
Copy Markdown
Contributor

Motivation and Context

Follow up for #2486

Description

This PR adds factory to the concurrent orchestration builder.

This PR also fixes a bug where executors with the same ID created by different factories can pass validation undetected.

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
  • Is this a breaking change? If yes, add "[BREAKING]" prefix to the title of the PR.

@TaoChenOSU Tao Chen (TaoChenOSU) self-assigned this Dec 10, 2025
Copilot AI review requested due to automatic review settings December 10, 2025 00:46
@TaoChenOSU Tao Chen (TaoChenOSU) added python Usage: [Issues, PRs], Target: Python workflows Usage: [Issues, PRs], Target: Workflows labels Dec 10, 2025
@github-actions github-actions Bot changed the title Add factory pattern to concurrent orchestration builder Python: Add factory pattern to concurrent orchestration builder Dec 10, 2025

Copilot AI 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 PR adds factory pattern support to the ConcurrentBuilder class, allowing participants and aggregators to be created through factory functions rather than requiring pre-instantiated objects. This enhancement enables better state isolation between workflow instances created from the same builder.

Key changes:

  • Added register_participants() method accepting factory functions for creating participants
  • Enhanced with_aggregator() to accept executor factories in addition to instances and callbacks
  • Updated build() method to handle both direct instances and factories

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 8 comments.

File Description
python/packages/core/agent_framework/_workflows/_concurrent.py Core implementation adding factory pattern support with new register_participants() method and enhanced with_aggregator() to handle executor factories
python/packages/core/tests/workflow/test_concurrent.py Comprehensive test coverage for factory patterns including tests for executor instance aggregators, executor factory aggregators, and participant factories
python/samples/getting_started/workflows/orchestration/concurrent_participant_factories.py New sample demonstrating concurrent orchestration using participant factories and custom aggregator with proper state isolation across workflow instances
python/samples/getting_started/workflows/orchestration/concurrent_custom_aggregator.py Updated documentation comment to reflect method rename from with_custom_aggregator to with_aggregator

@markwallace-microsoft Mark Wallace (markwallace-microsoft) added the documentation Usage: [Issues, PRs], Target: documentation in the code base and learn docs label Dec 10, 2025
@markwallace-microsoft

Mark Wallace (markwallace-microsoft) commented Dec 10, 2025 •

Copy link
Copy Markdown
Contributor

Python Test Coverage

Python Test Coverage Report •
FileStmtsMissCoverMissing
packages/core/agent_framework/_workflows
   _concurrent.py1913681%52, 61–62, 70–71, 90–91, 96, 101, 126, 131, 136–137, 143, 165, 175, 182, 349–353, 355, 383, 439, 451, 480–481, 508, 538, 548, 552–553, 564–566
   _workflow_builder.py2903886%259, 596, 694, 700–701, 798–799, 805, 808, 810, 812, 819, 822–826, 828, 892, 959, 969, 1028–1029, 1172, 1186–1193, 1195, 1198, 1200–1202, 1210
TOTAL16543257684% 

Python Unit Test Overview

Tests Skipped Failures Errors Time
2369 130 💤 0 ❌ 0 🔥 57.995s ⏱️

Copilot AI 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

Copilot reviewed 7 out of 7 changed files in this pull request and generated 5 comments.

@TaoChenOSU
Tao Chen (TaoChenOSU) added this pull request to the merge queue Dec 11, 2025
Merged via the queue into microsoft:main with commit 191779c Dec 11, 2025
24 checks passed