-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Description
Summary
Remove the register_executor(factory_func, ...) and register_agent(factory_func, ...) factory methods from WorkflowBuilder (Python). Instead, introduce a helper method that handles instantiation of executors/agents and then builds the Workflow object directly.
Motivation
The current factory-based approach (register_executor(lambda: ..., name=...), register_agent(create_agent, name=...)) requires managing factory callables throughout the codebase, along with async build methods and deferred initialization patterns. This adds complexity for state isolation that can be achieved more simply.
A helper method that creates executor/agent instances upfront and constructs the Workflow object provides:
- Easier state isolation — fresh instances are created per call without needing lambda wrappers or factory registries
- Simpler API — no need to reason about deferred initialization or factory lifecycle
- Less boilerplate — users write a helper function instead of registering factories on a builder
Current API (to be removed)
# packages/core/agent_framework/_workflows/_workflow_builder.py
WorkflowBuilder.register_executor(factory_func: Callable[[], Executor], name: str | list[str]) -> Self
WorkflowBuilder.register_agent(factory_func: Callable[[], SupportsAgentRun], name: str, ...) -> SelfUsed in samples like samples/getting_started/workflows/_start-here/step4_using_factories.py.
Proposed approach
Provide a helper method (e.g. on WorkflowBuilder or as a standalone utility) that:
- Instantiates executors and agents
- Builds the
Workflowobject - Returns it ready to run
This keeps state isolation simple — each call to the helper creates fresh instances — without requiring factory management in every piece of code.
Scope
packages/core/agent_framework/_workflows/_workflow_builder.py— removeregister_executorandregister_agentfactory methods- Update or remove
samples/getting_started/workflows/_start-here/step4_using_factories.py - Update any tests referencing factory registration (e.g.
test_workflow_builder.py) - Update the
DeclarativeWorkflowBuilderandWorkflowFactoryif they depend on factory methods - Add the new helper method with documentation and examples
Metadata
Metadata
Assignees
Labels
Type
Projects
Status