Skip to main content

distri_workflow/
lib.rs

1//! distri-workflow — workflow engine for Distri.
2//!
3//! Define multi-step workflows as data, execute them step by step,
4//! with support for sequential/parallel execution, conditions, agent runs,
5//! tool calls, and persistent state tracking.
6//!
7//! # Architecture
8//!
9//! Two layers, deliberately separated:
10//!
11//! - **Definition** — the workflow as a DAG of steps. Static template;
12//!   no runtime state. (`WorkflowDefinition`, `WorkflowStep`).
13//! - **Run** — execution state for one invocation: status, shared
14//!   context, per-step status / result / error / timestamps.
15//!   (`WorkflowRun`, `WorkflowStepRun`).
16//!
17//! Other key types:
18//!
19//! - `StepRequirement` — what a step needs to run (native skills, connections)
20//! - `StepExecutor` trait — executes a step (implement for your runtime)
21//! - `WorkflowStateStore` trait — persists `WorkflowRun`s (Redis, DB, in-memory)
22//! - `WorkflowRunner` — orchestrates execution with requirement checking
23//!
24//! # Example
25//!
26//! ```rust,no_run
27//! use distri_workflow::*;
28//!
29//! let steps = vec![
30//!     WorkflowStep::api_call("read", "Read document", "GET", "/api/docs/{id}")
31//!         .with_requires(vec![
32//!             StepRequirement::native("network"),
33//!             StepRequirement::connection("google", "drive").with_permissions(vec!["drive.readonly"]),
34//!         ]),
35//!     WorkflowStep::tool_call("process", "Process data", "analyze_doc", serde_json::json!({"format": "markdown"})),
36//!     WorkflowStep::script("test", "Run tests", "cargo test")
37//!         .with_cwd("/project")
38//!         .with_timeout(300),
39//! ];
40//!
41//! let definition = WorkflowDefinition::new(steps);
42//! let run = WorkflowRun::new(definition);
43//! ```
44
45pub mod executor;
46pub mod resolve;
47pub mod step_executions;
48pub mod store;
49pub mod types;
50
51pub use executor::{EventSink, NoopEventSink, StepExecutor, TracingEventSink, WorkflowRunner};
52pub use resolve::{
53    build_execution_context, evaluate_skip_condition, resolve_step_input, resolve_template,
54    resolve_value,
55};
56pub use step_executions::{
57    InMemoryWorkflowStepExecutionStore, WorkflowStepExecution, WorkflowStepExecutionStore,
58    WorkflowStepExecutionUpdate,
59};
60pub use store::{InMemoryStore, WorkflowStateStore};
61pub use types::*;
62
63#[cfg(test)]
64mod tests;