Skip to content

Python: Improve workflow builder API to discourage inline executor instantiation #429

Description

@TaoChenOSU

The current workflow builder makes it very easy for users and AI to mistakenly instantiate executors inline. For example,

workflow = (
  WorkflowBuilder()
  .add_edge(AddOneExecutor(), AddOneExecutor())
  .add_edge(AddOneExecutor(), AggregateResultExecutor())
  .set_start_executor(AddOneExecutor())
  .build()
)

This is problematic because the nodes created are never connected the way users may expect them to.

A recommended way to improve the API to prevent this from happening:

builder = WorkflowBuilder()
add_one_executor = builder.register(AddOneExecutor(), name="AddOne")
aggregate_result_executor = builder.register(AggregateResultExecutor(), name="AggregateResult")

workflow = (
  builder
  .add_edge(add_one_executor, add_one_executor)
  .add_edge(add_one_executor, aggregate_result_executor)
  .set_start_executor(add_one_executor)
  .build()
)

Metadata

Metadata

Assignees

Labels

epicUsage: [Issues], Target: milestone planningpythonUsage: [Issues, PRs], Target: PythonworkflowsUsage: [Issues, PRs], Target: Workflows
No fields configured for Feature.

Projects

Status
Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions