Control Flow

Conditional and logical operators for controlling execution flow in workflows and visitors.

Keywords

  • if - Logical condition (in visitor contexts)
  • when - Temporal/state condition (in visitor contexts)
  • while - Loop condition
  • for - Iteration
  • in - Collection membership
  • of - Collection iteration
  • and - Logical AND
  • or - Logical OR
  • not - Logical NOT

State-Based Control Flow

In Aexol, control flow is primarily managed through:

  1. Workflow state transitions - Define explicit paths between states
  2. Visitor nested blocks - Represent state changes in user journeys
  3. Named state blocks - Show available capabilities in different contexts

Workflow State Transitions

workflow OrderFlow {
    state pending -> processing, cancelled
    state processing -> shipped, failed
    state shipped -> delivered
    state failed -> retry, refunded
}
✨ Edit in Studio

Visitor State Blocks

visitor {
    "browse"
    "login" {
        logged_in {
            "view profile"
            "manage account"
            "logout"
        }
    }
}
✨ Edit in Studio

Conditional Blocks in Visitors

Basic Conditional Patterns

visitor {
    "start process" {
        processing {
            "validate data"
            "transform data"
            "complete process" {
                completed {
                    "view results"
                    "export data"
                }
            }
        }
    }
}
✨ Edit in Studio

Branching Paths

visitor {
    "submit application" {
        reviewing {
            "check status"
            "approve application" {
                approved {
                    "access benefits"
                }
            }
            "reject application" {
                rejected {
                    "resubmit"
                }
            }
        }
    }
}
✨ Edit in Studio

Logical Keywords (Conceptual)

While the new Aexol syntax uses string-based capabilities, logical concepts still apply to workflow design:

and - Multiple Requirements

Express with nested blocks - all parent capabilities must be available:

visitor {
    "login" {
        authenticated {
            "verify email" {
                verified {
                    "access premium features"
                }
            }
        }
    }
}
✨ Edit in Studio

or - Alternative Paths

Express with multiple workflow transitions:

workflow AccessFlow {
    state start -> login, oauth
    state login -> dashboard
    state oauth -> dashboard
    state dashboard
}
✨ Edit in Studio

Loop and Iteration Patterns

Retry Loops in Workflows

workflow ProcessFlow {
    state processing -> success, failed
    state failed -> retry
    state retry -> processing
    state success
}
✨ Edit in Studio

Iterative Processing

visitor {
    "process batch" {
        processing {
            "process item"
            "mark complete"
            "continue to next"
        }
    }
}
✨ Edit in Studio

Real-World Examples

Access Control

workflow AccessFlow {
    state anonymous -> authenticated
    state authenticated -> authorized, unauthorized
    state authorized -> access_granted
    state unauthorized -> denied
}

visitor {
    "view public content"
    "login" {
        authenticated {
            "view protected content"
            "verify permissions" {
                authorized {
                    "access admin panel"
                    "manage resources"
                }
            }
        }
    }
}
✨ Edit in Studio

Order Processing

workflow OrderFlow {
    state cart -> checkout
    state checkout -> payment
    state payment -> confirmed, failed
    state failed -> retry, cancelled
    state retry -> payment
    state confirmed -> shipped
    state shipped -> delivered
}

visitor {
    "browse products"
    "add to cart"
    "checkout" {
        checking_out {
            "enter shipping"
            "enter payment"
            "confirm order" {
                order_placed {
                    "track order"
                    "view order details"
                }
            }
        }
    }
}
✨ Edit in Studio

Content Moderation

workflow ModerationFlow {
    state submitted -> review
    state review -> approved, rejected, flagged
    state flagged -> human_review
    state human_review -> approved, rejected
    state approved -> published
    state rejected -> archived
}

agent ContentModerator {
    "receive content"
    "analyze content"
    "approve safe content"
    "reject violations"
    "flag uncertain content"
    "escalate to human review"
}
✨ Edit in Studio

Workflow Automation

workflow AutomationFlow {
    state triggered -> validating
    state validating -> processing, error
    state processing -> complete, error
    state error -> retry, failed
    state retry -> validating
    state complete
    state failed
}

agent AutomationRunner {
    "trigger workflow"
    "validate inputs"
    "process task"
    "handle errors"
    "retry on failure"
    "report completion"
}
✨ Edit in Studio

Best Practices

Condition Clarity

  1. Use descriptive state names

    • Good: payment_verified, user_authenticated
    • Avoid: state1, check1
  2. Model conditions as states

    workflow ValidationFlow {
        state pending -> validating
        state validating -> valid, invalid
        state valid -> processing
        state invalid -> rejected
    }
    
    ✨ Edit in Studio
  3. Use nested blocks for context

    visitor {
        "login" {
            authenticated {
                "access features"  # Only available when authenticated
            }
        }
    }
    
    ✨ Edit in Studio

Workflow Design Patterns

Guard Pattern

workflow GuardedFlow {
    state start -> validation
    state validation -> authorized, unauthorized
    state authorized -> processing
    state unauthorized -> denied
    state processing -> complete
}
✨ Edit in Studio

Fallback Pattern

workflow FallbackFlow {
    state primary -> success, fallback
    state fallback -> success, emergency
    state emergency -> success, failed
    state success
    state failed
}
✨ Edit in Studio

Progressive Enhancement

visitor {
    # Basic access
    "view content"
    
    "login" {
        logged_in {
            # Enhanced access
            "save favorites"
            "comment"
            
            "upgrade" {
                premium {
                    # Premium access
                    "download content"
                    "access archive"
                }
            }
        }
    }
}
✨ Edit in Studio

Control Flow Summary

ConceptImplementation
ConditionsWorkflow states
BranchingMultiple transitions
LoopsCircular state transitions
SequentialLinear workflow states
ContextVisitor nested blocks
GuardsValidation states

Related Keywords

  • workflow - State machines for flow control
  • visitor - User journey definitions
  • agent - Autonomous actions

Next Steps