Python: WorkflowBuilder registry#2486
Merged
moonbox3 merged 15 commits intomicrosoft:mainfrom Dec 5, 2025
Merged
Conversation
TaoChenOSU
commented
Nov 26, 2025
python/packages/core/agent_framework/_workflows/_workflow_builder.py
Outdated
Show resolved
Hide resolved
moonbox3
reviewed
Nov 27, 2025
python/packages/core/agent_framework/_workflows/_workflow_builder.py
Outdated
Show resolved
Hide resolved
python/packages/core/agent_framework/_workflows/_workflow_builder.py
Outdated
Show resolved
Hide resolved
moonbox3
reviewed
Nov 27, 2025
Contributor
|
Also, is this truly breaking? It should be additive, right? |
Member
Contributor
There was a problem hiding this comment.
Pull request overview
This PR introduces a factory-based registration pattern for executors and agents in the WorkflowBuilder, enabling lazy initialization and isolated workflow instances. Key changes include new register_executor() and register_agent() methods, deprecation warnings for direct instance addition, and comprehensive sample updates demonstrating the new pattern.
- Factory-based registration via
register_executor()andregister_agent()for deferred instantiation - Backward compatibility maintained with deprecation warnings on
add_agent()and direct executor addition - All 25+ sample files migrated to use the factory pattern
- Comprehensive test coverage for new registration patterns
- New sample file (
step4_using_factories.py) demonstrating best practices
Reviewed changes
Copilot reviewed 33 out of 33 changed files in this pull request and generated 16 comments.
Show a summary per file
| File | Description |
|---|---|
_workflow_builder.py |
Implements executor/agent factory registration with deferred edge resolution |
_workflow.py |
Simplifies start executor handling to require Executor instance |
_validation.py |
Updates validation to accept Executor instance instead of union type |
_edge.py |
Allows Case and Default targets to be strings for deferred resolution |
test_workflow_builder.py |
Adds 13 new tests for factory registration patterns |
| Sample files (25+) | Migrated to factory pattern with agent/executor factory functions |
python/samples/getting_started/workflows/agents/custom_agent_executors.py
Show resolved
Hide resolved
python/samples/getting_started/workflows/agents/custom_agent_executors.py
Show resolved
Hide resolved
python/samples/getting_started/workflows/_start-here/step4_using_factories.py
Outdated
Show resolved
Hide resolved
python/samples/getting_started/workflows/state-management/shared_states_with_agents.py
Outdated
Show resolved
Hide resolved
python/samples/getting_started/workflows/state-management/shared_states_with_agents.py
Outdated
Show resolved
Hide resolved
python/samples/getting_started/workflows/checkpoint/sub_workflow_checkpoint.py
Outdated
Show resolved
Hide resolved
python/samples/getting_started/workflows/checkpoint/sub_workflow_checkpoint.py
Outdated
Show resolved
Hide resolved
python/samples/getting_started/workflows/checkpoint/sub_workflow_checkpoint.py
Outdated
Show resolved
Hide resolved
python/samples/getting_started/workflows/checkpoint/sub_workflow_checkpoint.py
Outdated
Show resolved
Hide resolved
moonbox3
approved these changes
Dec 5, 2025
alliscode
approved these changes
Dec 5, 2025
This was referenced Dec 5, 2025
4 tasks
arisng
pushed a commit
to arisng/agent-framework
that referenced
this pull request
Feb 2, 2026
* Add workflow builder factory pattern * Add internal edge groups to registered executors; next samples * Update samples: Part 1 * register -> register_executor * update hil samples * Update other samples * Update agent samples * Update doc string * Add new sample * Fix mypy * Address comments * Fix mypy
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Motivation and Context
Closing #429
Description
Add support for providing factories to create executors and agents to the workflow builder to allow the workflow builder to create isolated workflow instances.
builder.register_executor().builder.register_agent().Contribution Checklist