Crate runtara_workflows

Crate runtara_workflows 

Source
Expand description

Runtara Workflows - Workflow Compilation to Native Binaries

This crate compiles workflow definitions (DSL scenarios) into native Linux binaries. The compiled binaries are standalone executables that communicate with runtara-core via the SDK for durability, checkpointing, and signal handling.

§Architecture

┌─────────────────────────────────────────────────────────────────────────┐
│                        Workflow Compilation Pipeline                     │
└─────────────────────────────────────────────────────────────────────────┘

    ┌─────────────┐      ┌─────────────┐      ┌─────────────┐
    │    DSL      │      │    Rust     │      │   Native    │
    │  Scenario   │─────▶│    AST      │─────▶│   Binary    │
    │  (JSON)     │      │  (codegen)  │      │  (rustc)    │
    └─────────────┘      └─────────────┘      └─────────────┘
          │                                         │
          ▼                                         ▼
    ┌─────────────┐                          ┌─────────────┐
    │ Dependency  │                          │ OCI Image   │
    │  Analysis   │                          │ (optional)  │
    └─────────────┘                          └─────────────┘

§Compilation Pipeline

  1. Parse: Load the DSL scenario from JSON
  2. Analyze Dependencies: Identify child scenarios and agent dependencies
  3. Generate AST: Convert the execution graph to Rust AST using codegen
  4. Write Source: Write generated Rust code to temp directory
  5. Invoke rustc: Compile with musl target for static linking
  6. Package: Optionally create OCI image for containerized execution

§Usage

use runtara_workflows::{compile_scenario, CompilationInput};

// Load scenario from JSON
let scenario: Scenario = serde_json::from_str(&json)?;

// Compile to native binary
let input = CompilationInput {
    scenario: &scenario,
    tenant_id: "tenant-1",
    scenario_id: "scenario-1",
    version: 1,
    output_dir: PathBuf::from("./output"),
    child_scenarios: vec![],
};

let result = compile_scenario(&input).await?;
println!("Binary at: {:?}", result.binary_path);

§Important Notes

  • This crate has NO database dependencies. Child workflows must be loaded by the caller and passed to compilation functions.
  • Compilation requires rustc and musl-tools to be installed.
  • The generated binary is statically linked for maximum portability.

§Modules

  • agents_library: Pre-compiled agents library management
  • codegen: AST code generation from execution graphs
  • compile: Compilation orchestration and rustc invocation
  • dependency_analysis: Dependency resolution for child scenarios
  • paths: File path utilities for scenarios and data

Re-exports§

pub use agents_library::NativeLibraryInfo;
pub use agents_library::get_native_library;
pub use agents_library::get_stdlib_name;
pub use compile::ChildDependency;
pub use compile::ChildScenarioInput;
pub use compile::CompilationInput;
pub use compile::NativeCompilationResult;
pub use compile::compile_scenario;
pub use compile::translate_scenario;
pub use compile::workflow_has_side_effects;
pub use dependency_analysis::DependencyGraph;
pub use dependency_analysis::ScenarioReference;
pub use validation::ValidationError;
pub use validation::validate_workflow;

Modules§

agents_library
Pre-compiled agents library management. Native library management
codegen
AST code generation from execution graphs. Code generation modules for workflow compilation.
compile
Compilation orchestration and rustc invocation. Rustc-based scenario compilation to native binaries
dependency_analysis
Dependency analysis for child scenarios. Dependency analysis utilities for workflow compilation.
paths
File path utilities for scenarios and data.
validation
Workflow validation for security and correctness. Workflow validation for security and correctness.

Structs§

ExecutionGraph
The execution graph containing all steps and control flow
Scenario
Complete scenario definition

Functions§

get_data_dir
Get the base data directory path from environment variable or default
get_scenario_dir
Construct the scenario directory path
get_scenario_json_path
Construct the scenario JSON file path