Skip to content

While do step

A composite pipeline step that executes a do-while loop construct.

WhileDoStep(name, body, condition, input_map=None, output_state=None, retry_config=None, error_handler=None, cache=None)

Bases: BaseCompositeStep, HasInputsMixin

A pipeline step that executes a do-while loop construct.

The loop body executes at least once and a condition node appended at the end determines whether to jump back to the loop's entry point.

Attributes:

Name Type Description
name str

A unique identifier for the pipeline step.

body BasePipelineStep | list[BasePipelineStep]

The step(s) to execute in the loop body.

condition LoopConditionType

The condition to evaluate after each iteration.

input_map InputMapSpec | None

Unified input map for the condition.

output_state str | None

Key to store the condition result in the pipeline state.

retry_policy RetryPolicy | None

Configuration for retry behavior.

error_handler BaseStepErrorHandler | None

Strategy to handle errors during execution.

Initialize a WhileDoStep.

Parameters:

Name Type Description Default
name str

A unique identifier for this pipeline step.

required
body BasePipelineStep | list[BasePipelineStep]

The loop body to execute.

required
condition LoopConditionType

The condition to evaluate at the end of each iteration.

required
input_map InputMapSpec | None

Unified input map for the condition. Defaults to None.

None
output_state str | None

Key to store the condition result in the state. Defaults to None.

None
retry_config RetryConfig | None

Retry config applied to the condition node. Defaults to None.

None
error_handler BaseStepErrorHandler | None

Error handling strategy for condition. Defaults to None.

None
cache CacheConfig | None

Caching config for the condition. Defaults to None.

None

Raises:

Type Description
TypeError

If body is empty or condition is invalid.

apply_exclusions(exclusions)

Apply exclusions to this composite step and its children.

Parameters:

Name Type Description Default
exclusions ExclusionSet

The exclusion set to apply.

required

execute(state, runtime, config=None) async

Evaluate the condition and route back or exit the loop.

Parameters:

Name Type Description Default
state PipelineState

The current state of the pipeline workflow.

required
runtime Runtime

The runtime context of the pipeline workflow execution.

required
config RunnableConfig | None

Execution configuration for the node. Defaults to None.

None

Returns:

Type Description
Command | dict[str, Any] | None

Command | dict[str, Any] | None: A LangGraph command directing execution back to the loop entry, an update payload when the loop exits, or None when there is no state update.

execute_direct(state, runtime, config=None) async

Reject direct execution for WhileDoStep.

Parameters:

Name Type Description Default
state dict[str, Any]

The initial state data.

required
runtime Runtime

The runtime context of the pipeline execution.

required
config RunnableConfig | None

Configuration for the runnable. Defaults to None.

None

Returns:

Type Description
dict[str, Any] | None

dict[str, Any] | None: This method does not return normally.

Raises:

Type Description
NotImplementedError

Always raised since loop routing requires a graph.