pub struct WorkflowBuilder { /* private fields */ }Expand description
Fluent builder for a Workflow. Rust equivalent of WorkflowBuilder.
Implementations§
Source§impl WorkflowBuilder
impl WorkflowBuilder
Sourcepub fn new() -> WorkflowBuilder
pub fn new() -> WorkflowBuilder
Create a new, empty builder.
Sourcepub fn add_executor(self, executor: Arc<dyn Executor>) -> WorkflowBuilder
pub fn add_executor(self, executor: Arc<dyn Executor>) -> WorkflowBuilder
Register an executor. Executors are keyed by their Executor::id.
Sourcepub fn set_start(self, id: impl Into<String>) -> WorkflowBuilder
pub fn set_start(self, id: impl Into<String>) -> WorkflowBuilder
Set the entry-point executor (by id). The initial message is delivered here.
Sourcepub fn add_edge(
self,
source: impl Into<String>,
target: impl Into<String>,
) -> WorkflowBuilder
pub fn add_edge( self, source: impl Into<String>, target: impl Into<String>, ) -> WorkflowBuilder
Add a single directed edge.
Sourcepub fn add_conditional_edge<R>(
self,
source: impl Into<String>,
target: impl Into<String>,
condition: impl Fn(&Value) -> R + Send + Sync + 'static,
) -> WorkflowBuilderwhere
R: IntoConditionResult,
pub fn add_conditional_edge<R>(
self,
source: impl Into<String>,
target: impl Into<String>,
condition: impl Fn(&Value) -> R + Send + Sync + 'static,
) -> WorkflowBuilderwhere
R: IntoConditionResult,
Add a single directed edge guarded by a synchronous condition.
Sourcepub fn add_conditional_edge_async<F, Fut, R>(
self,
source: impl Into<String>,
target: impl Into<String>,
condition: F,
) -> WorkflowBuilder
pub fn add_conditional_edge_async<F, Fut, R>( self, source: impl Into<String>, target: impl Into<String>, condition: F, ) -> WorkflowBuilder
Add a single directed edge guarded by an async condition.
Equivalent to WorkflowBuilder::add_conditional_edge but for a
predicate that itself needs to .await (e.g. an I/O check); the
condition is awaited at routing time (see UPSTREAM_DRIFT.md §10,
Edge.should_route becoming async upstream).
Sourcepub fn add_fan_out(
self,
source: impl Into<String>,
targets: impl IntoIterator<Item = String>,
) -> WorkflowBuilder
pub fn add_fan_out( self, source: impl Into<String>, targets: impl IntoIterator<Item = String>, ) -> WorkflowBuilder
Broadcast from source to all targets.
Sourcepub fn add_multi_selection(
self,
source: impl Into<String>,
targets: impl IntoIterator<Item = String>,
selection: Arc<dyn Fn(&Value, &[String]) -> Pin<Box<dyn Future<Output = Result<Vec<String>, Error>> + Send>> + Sync + Send>,
) -> WorkflowBuilder
pub fn add_multi_selection( self, source: impl Into<String>, targets: impl IntoIterator<Item = String>, selection: Arc<dyn Fn(&Value, &[String]) -> Pin<Box<dyn Future<Output = Result<Vec<String>, Error>> + Send>> + Sync + Send>, ) -> WorkflowBuilder
Fan out from source to the subset of targets a selection function
picks per message. Rust analogue of upstream’s
WorkflowBuilder.add_multi_selection_edge_group.
The selection is handed the message and the group’s target ids, and
returns the ids that should receive it — zero, one, or several. Unlike
add_switch, which picks exactly one branch, this
is the multi-target form: a message tagged for two reviewers goes to
both in the same superstep.
Two rules are enforced when the selection runs, not when it is registered, because its result is only known per message:
- An id that is not one of
targetsis a routing error. A selection naming an executor outside its own group would otherwise be dropped silently and the run would still reportIdle. - A repeated id is delivered once. A selection may name the same target twice — two tags on a message routing to the same executor — and running that executor twice on one message is never what was meant, besides double-counting toward a fan-in barrier downstream.
Build the selection with wrap_selection (or
wrap_async_selection). The closure may
return the ids directly, or a Result when choosing them can fail —
an Err aborts the run rather than being read as “picked nothing”.
let urgent = wrap_selection(|msg: &Value, candidates: &[String]| {
if msg["urgent"].as_bool().unwrap_or(false) {
candidates.to_vec()
} else {
candidates.first().cloned().into_iter().collect()
}
});
let builder = WorkflowBuilder::new().add_multi_selection(
"triage",
vec!["reviewer_a".to_string(), "reviewer_b".to_string()],
urgent,
);Sourcepub fn add_fan_in(
self,
sources: impl IntoIterator<Item = String>,
target: impl Into<String>,
) -> WorkflowBuilder
pub fn add_fan_in( self, sources: impl IntoIterator<Item = String>, target: impl Into<String>, ) -> WorkflowBuilder
Fan in from sources to target (barrier).
Sourcepub fn add_switch(
self,
source: impl Into<String>,
cases: Vec<Case>,
default: Default,
) -> WorkflowBuilder
pub fn add_switch( self, source: impl Into<String>, cases: Vec<Case>, default: Default, ) -> WorkflowBuilder
Add a switch/case group: evaluate cases in order, falling back to
default.
Sourcepub fn add_chain(self, ids: impl IntoIterator<Item = String>) -> WorkflowBuilder
pub fn add_chain(self, ids: impl IntoIterator<Item = String>) -> WorkflowBuilder
Chain executors sequentially (sugar for consecutive edges).
Sourcepub fn set_max_iterations(self, n: usize) -> WorkflowBuilder
pub fn set_max_iterations(self, n: usize) -> WorkflowBuilder
Set the maximum number of supersteps before the run fails.
Sourcepub fn name(self, name: impl Into<String>) -> WorkflowBuilder
pub fn name(self, name: impl Into<String>) -> WorkflowBuilder
Set the workflow name.
Sourcepub fn description(self, description: impl Into<String>) -> WorkflowBuilder
pub fn description(self, description: impl Into<String>) -> WorkflowBuilder
Set the workflow description.
Sourcepub fn with_checkpointing(
self,
storage: Arc<dyn CheckpointStorage>,
) -> WorkflowBuilder
pub fn with_checkpointing( self, storage: Arc<dyn CheckpointStorage>, ) -> WorkflowBuilder
Enable automatic checkpointing to storage at each superstep boundary.
Sourcepub fn output_from(
self,
ids: impl IntoIterator<Item = impl Into<String>>,
) -> WorkflowBuilder
pub fn output_from( self, ids: impl IntoIterator<Item = impl Into<String>>, ) -> WorkflowBuilder
Designate ids as workflow-level output sources: their yield_output
calls become terminal WorkflowEvent::Output events and are recorded
in WorkflowRun::last_output/WorkflowRun::outputs.
Once any executor is designated with output_from, executors not
named here (and not named via WorkflowBuilder::intermediate_output_from)
have their yields demoted to non-terminal WorkflowEvent::Intermediate
events rather than dropped — see WorkflowEvent::Intermediate for the
full precedence rule. Leaving both designation lists empty preserves the
default behavior: every yield is a terminal Output.
Rejected at WorkflowBuilder::build if any id is unknown or overlaps
WorkflowBuilder::intermediate_output_from.
Sourcepub fn intermediate_output_from(
self,
ids: impl IntoIterator<Item = impl Into<String>>,
) -> WorkflowBuilder
pub fn intermediate_output_from( self, ids: impl IntoIterator<Item = impl Into<String>>, ) -> WorkflowBuilder
Designate ids as intermediate-output sources: their yield_output
calls become non-terminal WorkflowEvent::Intermediate events and are
never recorded as the run’s final output.
Rejected at WorkflowBuilder::build if any id is unknown or overlaps
WorkflowBuilder::output_from.