mofa_kernel/workflow/mod.rs
1//! Workflow Module
2//!
3//! This module provides the core workflow/graph abstractions for MoFA.
4//! Inspired by LangGraph, it provides a stateful graph-based workflow system
5//! with support for:
6//!
7//! - **Reducer Pattern**: Configurable state update strategies (overwrite, append, merge, etc.)
8//! - **Command Pattern**: Unified state updates and control flow
9//! - **Send Pattern**: Dynamic edge creation for MapReduce scenarios
10//! - **RemainingSteps**: Active recursion limit tracking
11//!
12//! # Architecture
13//!
14//! This module defines traits only (kernel layer). Concrete implementations
15//! are provided in `mofa-foundation`.
16//!
17//! # Example
18//!
19//! ```rust,ignore
20//! use mofa_kernel::workflow::{StateGraph, Command, RuntimeContext, START, END};
21//!
22//! // Define state
23//! #[derive(Clone, Serialize, Deserialize)]
24//! struct MyState {
25//! messages: Vec<String>,
26//! }
27//!
28//! impl GraphState for MyState {
29//! // ... implementation
30//! }
31//!
32//! // Build graph
33//! let graph = StateGraphImpl::<MyState>::new("my_workflow")
34//! .add_node("process", Box::new(ProcessNode))
35//! .add_edge(START, "process")
36//! .add_edge("process", END)
37//! .compile()?;
38//!
39//! // Execute
40//! let result = graph.invoke(initial_state, None).await?;
41//! ```
42
43pub mod command;
44pub mod context;
45pub mod graph;
46pub mod reducer;
47pub mod state;
48
49// Re-export public API
50pub use command::{Command, ControlFlow, SendCommand};
51pub use context::{GraphConfig, RemainingSteps, RuntimeContext};
52pub use graph::{
53 CompiledGraph, END, EdgeTarget, NodeFunc, START, StateGraph, StepResult, StreamEvent,
54};
55pub use reducer::{Reducer, ReducerType, StateUpdate};
56pub use state::{GraphState, JsonState, StateSchema};