Skip to main content

Module workflow

Module workflow 

Source
Expand description

DAG-based Workflow System

Provides a directed acyclic graph (DAG) based workflow execution system with support for conditional branching, human-in-the-loop patterns, and complex task orchestration.

§Example

use cortexai_crew::workflow::{Workflow, WorkflowBuilder, NextAction};

let workflow = WorkflowBuilder::new("approval_flow")
    .add_node("validate", validate_task)
    .add_node("approve", approve_task)
    .add_node("execute", execute_task)
    .add_node("reject", reject_task)
    .connect("validate", "approve", Some(Condition::when("valid", true)))
    .connect("validate", "reject", Some(Condition::when("valid", false)))
    .connect("approve", "execute", None)
    .set_entry("validate")
    .build();

let mut runner = WorkflowRunner::new(workflow);
loop {
    match runner.step(context).await? {
        NextAction::Continue => continue,
        NextAction::WaitForInput(prompt) => {
            let input = get_user_input(&prompt);
            runner.provide_input(input);
        }
        NextAction::Complete(result) => break result,
    }
}

Structs§

Condition
Condition for edge traversal
InputRequest
Request for external input
NodeExecution
Record of a node execution
Workflow
Workflow definition
WorkflowBuilder
Builder for creating workflows
WorkflowContext
Execution context for workflows
WorkflowEdge
An edge connecting two nodes
WorkflowNode
A node in the workflow graph
WorkflowResult
Result of a completed workflow
WorkflowRunner
Workflow execution runner

Enums§

ConditionOperator
Comparison operators for conditions
InputType
Type of input expected
NextAction
Action to take after a workflow step
NodeResult
Result of a single node execution
NodeType
Type of workflow node
WorkflowStatus
Workflow execution status

Traits§

NodeExecutor
Trait for custom node executors