Goto step
A pipeline step that enables dynamic flow control by jumping to specified nodes.
GoToStep(name, target, input_map=None, output_state=None, allow_end=True, retry_config=None, error_handler=None, cache=None)
Bases: BasePipelineStep, HasInputsMixin
A pipeline step that enables dynamic flow control by jumping to specified nodes.
This step allows for dynamic routing in pipelines by jumping to different nodes based on runtime conditions. The target can be a static node name, a state key, or a callable that determines the target at runtime.
Attributes:
| Name | Type | Description |
|---|---|---|
name |
str
|
A unique identifier for the pipeline step. |
target |
str | Val | Callable[[dict[str, Any]], str]
|
The target node specification. |
input_map |
dict[str, str | Val]
|
Mapping of argument names to either a state/config key (str) or a fixed value (Val). Inherited from HasInputsMixin. |
output_state |
str | None
|
The state key to store the resolved target. |
allow_end |
bool
|
Whether jumping to 'END' is allowed. |
retry_policy |
RetryPolicy | None
|
Configuration for retry behavior using LangGraph's RetryPolicy. Inherited from BasePipelineStep. |
cache_store |
Any | None
|
The cache store used for caching step results, if configured. Inherited from BasePipelineStep. |
is_cache_enabled |
bool
|
Property indicating whether caching is enabled for this step. Inherited from BasePipelineStep. |
Initializes a new GoToStep.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
A unique identifier for this pipeline step. |
required |
target
|
str | Val | Callable[[dict[str, Any]], str]
|
The target node to jump to. Can be a literal string node name, a Val containing the node name, or a callable that takes the resolved inputs and returns the target node name. |
required |
input_map
|
InputMapSpec | None
|
Unified input map. Can be a dict (arg -> str|Val) or a list with elements: 1. str for identity mapping 2. dict[str, str] for state/config mapping 3. dict[str, Val] for fixed args. Defaults to None. |
None
|
output_state
|
str | None
|
Key to store the target node name in the pipeline state. Defaults to None. |
None
|
allow_end
|
bool
|
Whether to allow jumping to the END node. Defaults to True. |
True
|
retry_config
|
RetryConfig | None
|
Configuration for retry behavior using GLLM Core's RetryConfig. Defaults to None, in which case no retry config is applied. |
None
|
error_handler
|
BaseStepErrorHandler | None
|
Strategy to handle errors during execution. Defaults to None, in which case the RaiseStepErrorHandler is used. |
None
|
cache
|
CacheConfig | None
|
Configuration for the cache store including the cache store instance and its settings. Defaults to None, in which case no caching will be used. |
None
|
add_to_graph(graph, previous_endpoints, retry_policy=None)
Adds the GoToStep to the graph and creates edges.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
graph
|
Any
|
The LangGraph graph to add the step to. |
required |
previous_endpoints
|
list[str]
|
List of source node names to connect from. |
required |
retry_policy
|
RetryPolicy | None
|
Optional retry policy to override the step's default. Defaults to None. |
None
|
Returns:
| Type | Description |
|---|---|
list[str]
|
list[str]: List of endpoint names after adding this step. |
apply_exclusions(exclusions)
Applies exclusions to this goto step.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
exclusions
|
ExclusionSet
|
The exclusion set to apply. |
required |
execute(state, runtime, config=None)
async
Executes the goto step and returns a LangGraph Command.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
state
|
PipelineState
|
The current pipeline state. |
required |
runtime
|
Runtime
|
The runtime context containing config. |
required |
config
|
RunnableConfig | None
|
Optional runnable configuration. Defaults to None. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
Command |
Command
|
A LangGraph Command with goto parameter for routing. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the resolved target is invalid. |
KeyError
|
If state key is missing for string targets. |
execute_direct(state, runtime, config=None)
async
Executes the goto step and returns a state update.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
state
|
PipelineState
|
The current pipeline state. |
required |
runtime
|
Runtime
|
The runtime context containing config. |
required |
config
|
RunnableConfig | None
|
Optional runnable configuration. Defaults to None. |
None
|
Returns:
| Type | Description |
|---|---|
dict[str, Any] | None
|
dict[str, Any] | None: State update with resolved target if output_state is specified, None otherwise. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the resolved target is invalid. |
KeyError
|
If state key is missing for string targets. |
get_mermaid_diagram(indent=0)
Generates a Mermaid diagram representation of this goto step.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
indent
|
int
|
Number of spaces to indent the diagram. Defaults to 0. |
0
|
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
The Mermaid diagram string. |