Skip to main content

WorkflowBuilder

Struct WorkflowBuilder 

Source
pub struct WorkflowBuilder { /* private fields */ }
Expand description

Fluent builder for a Workflow. Rust equivalent of WorkflowBuilder.

Implementations§

Source§

impl WorkflowBuilder

Source

pub fn new() -> WorkflowBuilder

Create a new, empty builder.

Source

pub fn add_executor(self, executor: Arc<dyn Executor>) -> WorkflowBuilder

Register an executor. Executors are keyed by their Executor::id.

Source

pub fn set_start(self, id: impl Into<String>) -> WorkflowBuilder

Set the entry-point executor (by id). The initial message is delivered here.

Source

pub fn add_edge( self, source: impl Into<String>, target: impl Into<String>, ) -> WorkflowBuilder

Add a single directed edge.

Source

pub fn add_conditional_edge<R>( self, source: impl Into<String>, target: impl Into<String>, condition: impl Fn(&Value) -> R + Send + Sync + 'static, ) -> WorkflowBuilder

Add a single directed edge guarded by a synchronous condition.

Source

pub fn add_conditional_edge_async<F, Fut, R>( self, source: impl Into<String>, target: impl Into<String>, condition: F, ) -> WorkflowBuilder
where F: Fn(&Value) -> Fut + Send + Sync + 'static, Fut: Future<Output = R> + Send + 'static, R: IntoConditionResult,

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).

Source

pub fn add_fan_out( self, source: impl Into<String>, targets: impl IntoIterator<Item = String>, ) -> WorkflowBuilder

Broadcast from source to all targets.

Source

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 targets is a routing error. A selection naming an executor outside its own group would otherwise be dropped silently and the run would still report Idle.
  • 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,
);
Source

pub fn add_fan_in( self, sources: impl IntoIterator<Item = String>, target: impl Into<String>, ) -> WorkflowBuilder

Fan in from sources to target (barrier).

Source

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.

Source

pub fn add_chain(self, ids: impl IntoIterator<Item = String>) -> WorkflowBuilder

Chain executors sequentially (sugar for consecutive edges).

Source

pub fn set_max_iterations(self, n: usize) -> WorkflowBuilder

Set the maximum number of supersteps before the run fails.

Source

pub fn name(self, name: impl Into<String>) -> WorkflowBuilder

Set the workflow name.

Source

pub fn description(self, description: impl Into<String>) -> WorkflowBuilder

Set the workflow description.

Source

pub fn with_checkpointing( self, storage: Arc<dyn CheckpointStorage>, ) -> WorkflowBuilder

Enable automatic checkpointing to storage at each superstep boundary.

Source

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.

Source

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.

Source

pub fn build(self) -> Result<Workflow, Error>

Validate and build the workflow.

Trait Implementations§

Source§

impl Default for WorkflowBuilder

Source§

fn default() -> WorkflowBuilder

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more