Nested Flows
View SourceOverview
A Flow module used in a step becomes a canonical Jido.Flow.Subflow. This is
the only implicit Subflow derivation.
Run the cells from top to bottom.
Install The Package
Mix.install([{:jido_action, "~> 3.0.0-beta.11"}])Define A Child Flow
defmodule NestedFlows.AddOne do
use Jido.Action, name: "nested_flows_add_one"
@impl true
def run(%{value: value}, _context), do: {:ok, %{value: value + 1}}
end
defmodule NestedFlows.Child do
use Jido.Flow, name: "nested_flows_child"
flow do
step "add",
action: NestedFlows.AddOne,
params: %{value: input(:value)}
output(%{value: result("add", :value)})
end
endUse The Child In A Step
defmodule NestedFlows.Parent do
use Jido.Flow, name: "nested_flows_parent"
flow do
step "child",
action: NestedFlows.Child,
params: %{value: input(:value)}
step "finish",
action: NestedFlows.AddOne,
params: %{value: result("child", :value)}
output(%{value: result("finish", :value)})
end
end%Jido.Flow.Subflow{} =
NestedFlows.Parent.flow().components
|> List.first()
{:ok, %{value: 3}} =
Jido.Exec.run(NestedFlows.Parent, %{value: 1})The DSL shape stays step ... action: ChildFlow. The lowerer resolves the
target through Jido.Executable and stores Jido.Flow.Subflow.
Native Execution Boundary
A Subflow lowers to a nested native Runic Workflow. Step-wise execution can show child validators, child Steps, InputBinding, and connection work. Jido does not hide these native runnables.
The child inherits the parent context, max_concurrency, task_supervisor routing, and
execution ID. Its Action calls share the parent execution budget.
Child output uses the same caller context as root Flow output. This includes
context references inside expressions, maps, and lists. Input references read
the validated child input. Result references read components in that child.
A missing context key returns a reference error. A key with a nil value is
present and resolves to nil. These rules also apply to step-wise execution.
An Action failure keeps its typed error and leaf details. Its
details.node_path identifies the authored Subflow path, for example
["child", "add"]. Child input and output validation failures identify the
Subflow boundary instead, for example ["child"]. Errors before Action
validation can lack this path. See
Read Failures
for single and concurrent failure inspection.
Limits
Only step derives Subflow. Choice options, Choice fallback, Map, Reduce, and
Iterate target slots require Actions. A canonical Subflow stores a Flow module,
not an arbitrary runtime Flow value.
Validate the complete boundary without running work:
NestedFlows.Parent.flow()
|> Jido.Flow.validate_executable()