Skip to main content

workflow

Function workflow 

Source
pub async fn workflow<R, F, Fut>(
    ctx: &WorkflowCtx,
    _name: impl Into<String>,
    body: F,
) -> Result<R, Error>
where F: FnOnce(WorkflowCtx) -> Fut, Fut: Future<Output = Result<R, Error>>,
Expand description

Run body as a nested sub-workflow sharing this run’s budget, journal, concurrency cap, runaway backstop, and cancellation. Exactly one level of nesting is allowed: calling workflow() from inside a body returns Error::Config.

The child receives a fresh WorkflowCtx whose default-phase is independent of the parent’s, but whose limits and journal are the same shared state, so a child’s spend counts against the parent budget and a child’s breach halts the whole run.

let summary = workflow(&ctx, "research", |child| async move {
    let findings = parallel(&child, finders).await;
    agent(&child, summarize(findings)).run().await
}).await?;