Skip to main content

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

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
Design Principle: Keep the kernel stable and minimal. All features are extensions.
// mofa-kernel defines ONLY traits
pub trait MoFAAgent: Send + Sync {
    fn id(&self) -> &str;
    async fn execute(&mut self, input: AgentInput) -> AgentResult<AgentOutput>;
    async fn initialize(&mut self, ctx: &CoreAgentContext) -> AgentResult<()>;
}
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
Advantages:
  • Zero runtime overhead
  • Type safety at compile time
  • Native system integration
  • Memory safety without garbage collection
// Compile-time plugin example
#[async_trait]
impl AgentPlugin for LLMPlugin {
    async fn execute(&mut self, input: String) -> PluginResult<String> {
        // Zero-cost abstraction, directly compiled
        self.client.generate(&input).await
    }
}
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
Advantages:
  • Instant deployment
  • User-defined extensions
  • A/B testing without downtime
  • Secure sandbox with resource limits
// Runtime plugin - hot reloadable
fn process_order(order) {
    if order.amount > 1000 {
        return "manager_approval";
    }
    return "auto_approve";
}
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:
mofa/
├── crates/
│   ├── mofa-kernel/        # Microkernel core
│   ├── mofa-foundation/    # Concrete implementations
│   ├── mofa-runtime/       # Execution system
│   ├── mofa-plugins/       # Dual-layer plugins
│   ├── mofa-sdk/           # Standard API
│   ├── mofa-ffi/           # Multi-language bindings
│   ├── mofa-cli/           # CLI tool
│   └── mofa-monitoring/    # Observability
└── examples/               # 27+ examples

Key Architecture Principles

Trait-Based Design

All core abstractions are traits in mofa-kernel, allowing multiple implementations and easy testing

Zero 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
import mofa

agent = mofa.Agent("my-agent")
result = await agent.execute("Hello")

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
pub struct ReactAgent {
    state: RactorState<Self>,
    tool_registry: Arc<dyn ToolRegistry>,
}

impl Actor for ReactAgent {
    async fn handle(&self, msg: AgentMessage) -> AgentResult<()> {
        // Isolated execution
    }
}

Distributed Architecture (Optional)

With the dora 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
The distributed layer is optional. Enable with cargo build --features dora when needed.

Performance Characteristics

ComponentPerformanceUse Case
Rust Core<1ms overheadCritical path operations
Compile-time PluginsZero-cost abstractionsLLM inference, data processing
Runtime Plugins~1-5ms script executionBusiness rules, workflows
UniFFI Bindings<100μs FFI overheadPython/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

Build docs developers (and LLMs) love