Skip to content

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

@TaoChenOSU

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

epicUsed for milestone planning, please create tasks for the associated development work.pythonv1.0Features being tracked for the version 1.0 GAworkflowsRelated to Workflows in agent-framework

Projects

Status

In Progress

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions