Skip to main content

Module human_loop

Module human_loop 

Source
Expand description

Human-in-the-Loop Support

Provides pause/resume, approval gates, and interactive breakpoints for graph-based workflows.

§Features

  • Approval Gates: Pause execution for human approval before continuing
  • Breakpoints: Define nodes where execution pauses for inspection/input
  • Input Collection: Request structured input from humans during execution
  • Interrupt/Resume: Pause and resume execution at any point

§Example

use cortexai_crew::human_loop::{HumanLoop, ApprovalGate, InteractiveGraph};

// Create a graph with approval gates
let graph = GraphBuilder::new("approval_workflow")
    .add_node("generate", generate_content)
    .add_node("review", review_node)
    .add_node("publish", publish_content)
    .add_edge("generate", "review")
    .add_edge("review", "publish")
    .set_entry("generate")
    .build()?;

// Wrap with human-in-the-loop
let interactive = InteractiveGraph::new(graph)
    .with_approval_gate("review", ApprovalGate::new("Review the generated content"))
    .with_breakpoint("publish");

// Run interactively
let mut session = interactive.start(initial_state).await?;

loop {
    match session.next().await? {
        HumanLoopAction::Continue(state) => { /* auto-continues */ }
        HumanLoopAction::AwaitApproval { gate, state } => {
            // Show content to user, get approval
            if user_approves() {
                session.approve().await?;
            } else {
                session.reject("Needs more work").await?;
            }
        }
        HumanLoopAction::AwaitInput { request, state } => {
            let input = get_user_input(&request);
            session.provide_input(input).await?;
        }
        HumanLoopAction::Breakpoint { node_id, state } => {
            // Inspect state, optionally modify
            session.resume().await?;
        }
        HumanLoopAction::Complete(result) => break,
    }
}

Structs§

ApprovalGate
Approval gate configuration
HumanInputRequest
Input request for human interaction
InteractiveGraph
Interactive graph wrapper with human-in-the-loop support
InteractiveSession
Interactive execution session
InteractiveWorkflowBuilder
Builder for creating interactive workflows
SelectOption
Option for select inputs

Enums§

ApprovalResponse
Human response to an approval gate
HumanInputType
Type of input expected for human interaction
HumanLoopAction
Action required from human
SessionStatus
Session status