Module workflow

Source
Expand description

§Workflow Management

This module provides the core workflow management functionality for AIMX. A workflow represents a collection of rules organized in a hierarchical structure, with support for versioning, concurrent access, and efficient rule management.

§Key Concepts

  • Workflow: A container for rules that represents a logical unit of work
  • Rule: Individual definitions with identifiers, types, expressions, and values
  • Versioning: Support for major (epoch) and minor (partial) version tracking
  • Concurrent Access: Thread-safe design supporting multiple readers and atomic writes
  • Change Tracking: Automatic detection of changes requiring partial or full saves

§Workflow Structure

Workflows maintain rules in two complementary data structures:

  • rows: A vector maintaining rule order and empty slots
  • lookup: A hash map for O(1) identifier-based rule access

This dual-structure approach provides both ordered access (for serialization) and fast lookup (for evaluation and rule management).

§Version Control

Workflows support a sophisticated version control system:

  • Epoch: Major version numbers that increment on structural changes
  • Partial: Minor version numbers for incremental updates within an epoch
  • Journaling: External journal files track version offsets for efficient loading
  • Change Tracking: Automatic detection of change types (None, Partial, Version)

§Concurrency Model

The workflow system uses a multi-version concurrency control (MVCC) model:

  • Non-blocking Reads: Unlimited concurrent readers access consistent snapshots
  • Atomic Writes: Writers operate on isolated copies before publishing changes
  • Fine-grained Locking: Per-workflow locking instead of global workspace locking

This design ensures high performance for agentic workflows where many tasks may need to evaluate expressions simultaneously without blocking.

§Usage Examples

use aimx::{Workflow, WorkflowLike, Rule, Typedef, Expression, Literal, Value};

// Create a new workflow
let mut workflow = Workflow::new();

// Add rules to the workflow
let rule = Rule::new("temperature".to_string(), Typedef::Number, 
    Expression::Empty, Value::Literal(Literal::Number(72.0)));
workflow.append_or_update(Some(rule));

// Access rules by identifier
let temp_rule = workflow.get_rule("temperature").unwrap();
let temp = temp_rule.value().to_literal();
assert_eq!(temp, &Literal::Number(72.0));

// Check that we have rules
assert!(workflow.rule_count() > 0);

Structs§

Workflow
Represents a workflow containing rules with version control and change tracking.

Enums§

Changes
Represents the types of changes that can be made to an AIM structure.

Traits§

WorkflowLike
The central trait for interacting with workflow content.