Overview
OpenFang is built from the ground up in Rust as a true Agent Operating System — not a framework, not a library, but a complete OS for autonomous agents. The system compiles to a single ~32MB binary with 137,728 lines of code across 14 specialized crates.The entire architecture is designed around zero external dependencies at runtime. No Python interpreter, no Node.js, no Docker required. One binary runs everything.
The 14-Crate Architecture
OpenFang uses a modular kernel design where each crate has a single, well-defined responsibility. This creates clear boundaries and allows independent testing of each subsystem.Core Crates
openfang-kernel
Orchestration hub managing agent lifecycles, permissions, scheduling, budget tracking, and RBAC. The kernel never calls LLMs directly — it delegates to the runtime.
openfang-runtime
Agent execution environment with the main loop, 3 LLM drivers (Anthropic, Gemini, OpenAI-compatible), 53 built-in tools, WASM sandbox, MCP client, and A2A protocol.
openfang-memory
Unified memory substrate over SQLite providing structured KV storage, semantic search, knowledge graphs, session persistence, and automatic memory consolidation.
openfang-types
Core type definitions, trait bounds, and data structures shared across all crates. Contains taint tracking, Ed25519 manifest signing, and the model catalog.
Interface Crates
openfang-api
HTTP/WebSocket/SSE server with 140+ REST endpoints, OpenAI-compatible API, dashboard serving, rate limiting, and channel bridge.
openfang-cli
Command-line interface with daemon management, TUI dashboard, interactive chat mode, and MCP server mode for tool exposure.
openfang-desktop
Tauri 2.0 native desktop app with system tray integration, native notifications, global shortcuts, and offline-first architecture.
openfang-channels
40 messaging platform adapters (Telegram, Discord, Slack, WhatsApp, etc.) with per-channel rate limiting, DM/group policies, and output formatting.
Agent Subsystems
openfang-hands
Autonomous capability packages with 7 bundled Hands, HAND.toml parser, lifecycle management, settings schema, and requirement validation.
openfang-skills
60 bundled domain expertise files (SKILL.md), parser, FangHub marketplace integration, and prompt injection scanning.
openfang-extensions
25 MCP server templates, AES-256-GCM credential vault with Argon2 key derivation, OAuth2 PKCE flow handler.
openfang-wire
OFP peer-to-peer protocol with HMAC-SHA256 mutual authentication, nonce-based replay protection, and distributed agent discovery.
Utility Crates
openfang-migrate
Migration engine for importing from OpenClaw, LangChain, AutoGPT with agent manifest conversion, session history mapping, and config translation.
xtask
Build automation, release packaging, cross-compilation targets, and development workflow scripts.
Crate Dependency Graph
Types Layer
openfang-types defines all core data structures with zero dependencies. Everything else builds on this foundation.Substrate Layer
Memory, runtime, wire protocol, and extensions implement core subsystems using only the types layer.
Kernel Layer
The kernel orchestrates all subsystems without knowing about I/O boundaries (API, CLI, desktop).
Key Architectural Patterns
KernelHandle Trait
The runtime needs to call back into the kernel (e.g., to spawn child agents, check permissions) but cannot directly depend onopenfang-kernel (circular dependency). Solution: KernelHandle trait.
Arc<dyn KernelHandle> and can make upward calls without compile-time coupling.
Memory Trait Abstraction
All memory operations go through a single async trait, allowing the runtime to be storage-agnostic:MemorySubstrate implements this by delegating to specialized stores (structured, semantic, knowledge, session) backed by a shared SQLite connection.
Channel Bridge Pattern
The API server includes a channel bridge that routes messages from external platforms to agents without blocking HTTP threads:Build & Deployment
Release Build Configuration
Release Build Configuration
Cross-Compilation Targets
Cross-Compilation Targets
OpenFang supports:
x86_64-unknown-linux-gnu(primary)x86_64-apple-darwin(macOS Intel)aarch64-apple-darwin(macOS Apple Silicon)x86_64-pc-windows-msvc(Windows)aarch64-unknown-linux-gnu(Linux ARM64)
rustls instead of OpenSSL to avoid linking against system libraries.Docker Deployment
Docker Deployment
Testing Strategy
OpenFang has 1,767+ tests across all crates:- Unit tests: Every crate has inline
#[test]functions for pure logic - Integration tests:
tests/directories verify cross-crate interactions - Live API tests:
openfang-api/tests/api_integration_test.rsboots a real daemon and hits endpoints - Property tests: Critical security code (taint tracking, audit chain) uses property-based testing
The project enforces zero Clippy warnings in CI. Every commit must pass
cargo clippy --workspace --all-targets -- -D warnings.Performance Characteristics
| Metric | Value | Comparison |
|---|---|---|
| Cold start | 180ms | 28× faster than OpenClaw (5.98s) |
| Idle memory | 40MB | 10× smaller than OpenClaw (394MB) |
| Binary size | 32MB | 16× smaller than OpenClaw (500MB) |
| Test suite | 1,767+ | Most comprehensive in category |
- Rust’s zero-cost abstractions and ahead-of-time compilation
- No JIT warmup, no garbage collection pauses
- Static linking of all dependencies
- Aggressive LTO and stripping in release builds
Next Steps
Agent Lifecycle
Learn how agents are spawned, scheduled, and managed by the kernel
Hands System
Explore autonomous capability packages and how they work
Memory Substrate
Deep dive into the three-layer memory system
Security
Understand the 16 independent security layers