Skip to content

Python: Add factory pattern to sequential orchestration builder - #2710

Merged
Tao Chen (TaoChenOSU) merged 7 commits into
microsoft:mainfrom
TaoChenOSU:taochen/python-factory-pattern-to-sequential-builder
Dec 10, 2025
Merged

Python: Add factory pattern to sequential orchestration builder#2710
Tao Chen (TaoChenOSU) merged 7 commits into
microsoft:mainfrom
TaoChenOSU:taochen/python-factory-pattern-to-sequential-builder

Conversation

@TaoChenOSU

@TaoChenOSUTao Chen (TaoChenOSU) commented Dec 9, 2025

Copy link
Copy Markdown
Contributor

Motivation and Context

Follow up for #2486

Description

This PR adds factory to the sequential orchestration builder.

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.

@TaoChenOSUTao Chen (TaoChenOSU) added python Usage: [Issues, PRs], Target: Python workflows Usage: [Issues, PRs], Target: Workflows labels Dec 9, 2025
@github-actionsgithub-actionsBot changed the title Add factory pattern to sequential orchestration builderPython: Add factory pattern to sequential orchestration builderDec 9, 2025
@markwallace-microsoft

Mark Wallace (markwallace-microsoft) commented Dec 9, 2025

Copy link
Copy Markdown
Contributor

Python Test Coverage

Python Test Coverage Report •
FileStmtsMissCoverMissing
packages/core/agent_framework/_workflows
_sequential.py1081586%72, 76, 86, 182, 188, 234, 236–238, 253, 260, 288, 292–293, 306
_typing_utils.py1072873%56, 80, 159, 161–162, 171, 173, 180, 182, 202, 204, 206, 211–218, 221–222, 224–228, 230
TOTAL16494257184%

Python Unit Test Overview

TestsSkippedFailuresErrorsTime
2355130 💤0 ❌0 🔥58.208s ⏱️

Comment threadpython/packages/core/agent_framework/_workflows/_sequential.py Outdated
Comment threadpython/packages/core/agent_framework/_workflows/_sequential.py Outdated
Comment threadpython/packages/core/agent_framework/_workflows/_sequential.py Outdated

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 PR adds a factory pattern to the SequentialBuilder to enable proper state isolation between workflow instances. The feature allows users to register participant factories instead of participant instances, ensuring that each workflow built from the same builder gets fresh participant instances with independent state.

Key Changes:

  • Added register_participants() method to SequentialBuilder accepting factory functions
  • Updated SequentialBuilder to call factories during build() to create fresh participant instances
  • Added comprehensive test coverage for factory pattern with various scenarios

Reviewed changes

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

Show a summary per file
FileDescription
python/samples/getting_started/workflows/orchestration/sequential_participant_factory.pyNew sample demonstrating factory pattern usage with stateful accumulator showing state isolation between workflow instances
python/samples/getting_started/workflows/orchestration/sequential_custom_executors.pyRemoved unused Never import and simplified code by removing type ignore comments
python/packages/core/tests/workflow/test_sequential.pyAdded comprehensive tests for factory pattern including validation, checkpointing, builder reusability, and mixed participants
python/packages/core/agent_framework/_workflows/_typing_utils.pyRemoved unused _coerce_to_type function and its associated imports
python/packages/core/agent_framework/_workflows/_sequential.pyImplemented factory pattern support with validation, added register_participants() method, updated build logic to call factories

Comment threadpython/packages/core/agent_framework/_workflows/_sequential.py Outdated
Comment threadpython/packages/core/agent_framework/_workflows/_sequential.py Outdated
@markwallace-microsoftMark Wallace (markwallace-microsoft) added the documentation Usage: [Issues, PRs], Target: documentation in the code base and learn docs label Dec 10, 2025
@TaoChenOSU
Tao Chen (TaoChenOSU) added this pull request to the merge queueDec 10, 2025
Merged via the queue into microsoft:main with commit 523305aDec 10, 2025
24 checks passed
@TaoChenOSU
Tao Chen (TaoChenOSU) deleted the taochen/python-factory-pattern-to-sequential-builder branch December 10, 2025 18:28
Aris Nguyen (arisng) pushed a commit to arisng/agent-framework that referenced this pull request Feb 2, 2026
…osoft#2710)
* Add factory pattern to sequential orchestration builder
* Use temp list to avoid override
* Add sample and some other fixes
* Fix comments
* Small fix
* Update readme
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentationUsage: [Issues, PRs], Target: documentation in the code base and learn docspythonUsage: [Issues, PRs], Target: PythonworkflowsUsage: [Issues, PRs], Target: Workflows

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

5 participants

@TaoChenOSU@markwallace-microsoft@alliscode@moonbox3