Overview
MoFA’s workflow engine is inspired by LangGraph and provides a stateful, graph-based workflow system for orchestrating complex agent processes. Key Features:- State Management: Reducers for configurable state updates
- Control Flow: Conditional edges, loops, branching
- Persistence: Checkpoint/restore workflow state
- Telemetry: Debug sessions with step-by-step replay
- MapReduce: Dynamic edge creation for parallel tasks
Core Concepts
StateGraph
TheStateGraph is the main abstraction for building workflows:
Graph State Trait
All workflow states must implementGraphState:
mofa-kernel/src/workflow/state.rs
Node Functions
Nodes are async functions that process state:Reducer System
Reducers control how state updates are merged:- Overwrite
- Append
- Prepend
- Merge
- Custom
Replace the entire field:
Command Pattern
Nodes returnCommand objects for control flow:
mofa-kernel/src/workflow/command.rs
Send Pattern (MapReduce)
Dynamically create edges for parallel task distribution:Recursion Limit
Prevent infinite loops withRemainingSteps:
- Each step decrements the counter
- When counter reaches 0, workflow stops
- Prevents runaway loops
Telemetry & Debug Sessions
Record workflow execution for debugging:NodeEnter: Node execution startedNodeExit: Node execution completedStateUpdate: State changedEdgeTraversal: Graph edge followedError: Execution error
Streaming Execution
Stream intermediate steps during execution:Persistence (Checkpointing)
Save and restore workflow state:- Long-running workflows (resume after crash)
- Human-in-the-loop (wait for approval, resume later)
- Time travel debugging (restore to previous state)
Workflow DSL
Define workflows in YAML/JSON:workflow.yaml
Complete Example
Scenario: Multi-step code generation workflowWorkflow Visualization
Generate Mermaid diagrams from workflows:Performance Tips
Minimize State Size
Large states slow serialization. Keep only necessary data.
Use Parallel Edges
When nodes are independent, use
ControlFlow::Parallel.Batch Updates
Update state once per node instead of incrementally.
Async All The Way
Ensure all node functions are truly async for concurrency.
Next Steps
Examples
See workflow examples in action
API Reference
Complete workflow API documentation