Overview
MoFA (Modular Framework for Agents) implements a layered microkernel architecture with a revolutionary dual-layer plugin system that achieves the perfect balance between raw performance and dynamic flexibility. Unlike traditional agent frameworks that sacrifice performance for flexibility or vice versa, MoFA’s architecture enables:- Extreme Performance: Zero-cost abstractions through Rust and compile-time plugins
- Unlimited Extensibility: Hot-reloadable runtime plugins without recompilation
- Multi-Language Support: Write once in Rust, use everywhere via UniFFI
- Production-Grade: Battle-tested microkernel design with clear separation of concerns
Architecture Layers
MoFA follows a strict layered architecture with unidirectional dependencies:Layer Breakdown
1. Microkernel (mofa-kernel)
1. Microkernel (mofa-kernel)
The minimalist core containing only essential primitives:
- Lifecycle Management: Agent initialization, execution, and shutdown
- Metadata System: Configuration, capabilities, and discovery
- Communication Bus: Message passing and event distribution
- Task Scheduling: Priority-based execution coordination
2. Compile-time Plugin Layer
2. Compile-time Plugin Layer
Performance-critical implementations in Rust/WASM:
- LLM Plugins: Native inference, API integration (OpenAI, Anthropic, Ollama)
- Tool Plugins: File system, HTTP, database operations
- Storage Plugins: PostgreSQL, MySQL, SQLite persistence
- WASM Plugins: Sandboxed secure execution for untrusted code
- Zero runtime overhead
- Type safety at compile time
- Native system integration
- Memory safety without garbage collection
3. Runtime Plugin Layer (Rhai)
3. Runtime Plugin Layer (Rhai)
Dynamic business logic via embedded Rhai scripting:
- Script Task Nodes: Execute logic without recompilation
- Dynamic Tool Registration: Add tools at runtime
- Rule Engine: Priority-based decision making
- Hot Reload: Update logic instantly in production
- Instant deployment
- User-defined extensions
- A/B testing without downtime
- Secure sandbox with resource limits
4. Business Layer
4. Business Layer
User-defined agents, workflows, and application logic:
- Custom agent implementations
- Workflow orchestration
- Domain-specific rules
- Integration glue code
Complete Architecture Diagram
The full MoFA architecture showing all major components:Crate Structure
MoFA’s workspace is organized into focused crates following the architecture layers:Key Architecture Principles
Trait-Based Design
All core abstractions are traits in
mofa-kernel, allowing multiple implementations and easy testingZero Circular Dependencies
Strict layering prevents circular dependencies. Foundation depends on kernel, never vice versa
Plugin Isolation
Plugins cannot directly depend on each other. All communication through the kernel bus
Async by Default
Native Rust async/await using Tokio for high-concurrency workloads
Architecture Validation: The layered design is enforced through Rust’s module system and dependency declarations in
Cargo.toml. Violations cause compilation errors.Cross-Language Architecture
MoFA’s Rust core supports multiple languages through UniFFI: Benefits:- Near-Zero Overhead: Direct FFI calls, no serialization
- Type Safety: Automatic binding generation with type checking
- Consistent API: Same interface across all languages
Actor-Based Concurrency
MoFA uses the Ractor actor framework for agent concurrency:- Isolated State: Each agent runs in its own actor
- Message Passing: Communication via channels, no shared state
- Fault Tolerance: Actor supervision trees for resilience
- Scalability: Thousands of concurrent agents
Distributed Architecture (Optional)
With thedora feature enabled, MoFA supports distributed dataflow:
- Cross-Process Communication: Agents on different machines
- Low-Latency: Optimized dataflow protocol
- Edge Ready: Deploy to resource-constrained devices
Performance Characteristics
| Component | Performance | Use Case |
|---|---|---|
| Rust Core | <1ms overhead | Critical path operations |
| Compile-time Plugins | Zero-cost abstractions | LLM inference, data processing |
| Runtime Plugins | ~1-5ms script execution | Business rules, workflows |
| UniFFI Bindings | <100μs FFI overhead | Python/Java integration |
Next Steps
Microkernel Design
Deep dive into the microkernel’s lifecycle and trait system
Dual-Layer Plugins
Learn how compile-time and runtime plugins work together
Agent Coordination
Understand multi-agent collaboration patterns
Workflow Engine
Explore the LangGraph-inspired workflow system