Expand description
Workflow Module
This module provides the core workflow/graph abstractions for MoFA. Inspired by LangGraph, it provides a stateful graph-based workflow system with support for:
- Reducer Pattern: Configurable state update strategies (overwrite, append, merge, etc.)
- Command Pattern: Unified state updates and control flow
- Send Pattern: Dynamic edge creation for MapReduce scenarios
- RemainingSteps: Active recursion limit tracking
§Architecture
This module defines traits only (kernel layer). Concrete implementations
are provided in mofa-foundation.
§Example
ⓘ
use mofa_kernel::workflow::{StateGraph, Command, RuntimeContext, START, END};
// Define state
#[derive(Clone, Serialize, Deserialize)]
struct MyState {
messages: Vec<String>,
}
impl GraphState for MyState {
// ... implementation
}
// Build graph
let graph = StateGraphImpl::<MyState>::new("my_workflow")
.add_node("process", Box::new(ProcessNode))
.add_edge(START, "process")
.add_edge("process", END)
.compile()?;
// Execute
let result = graph.invoke(initial_state, None).await?;Re-exports§
pub use command::Command;pub use command::ControlFlow;pub use command::SendCommand;pub use context::GraphConfig;pub use context::RemainingSteps;pub use context::RuntimeContext;pub use graph::CompiledGraph;pub use graph::END;pub use graph::EdgeTarget;pub use graph::NodeFunc;pub use graph::START;pub use graph::StateGraph;pub use graph::StepResult;pub use graph::StreamEvent;pub use reducer::Reducer;pub use reducer::ReducerType;pub use reducer::StateUpdate;pub use state::GraphState;pub use state::JsonState;pub use state::StateSchema;