Skip to main content

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

openfang-types (base layer — no dependencies)

   ┌───┴────────┬──────────┬──────────┐
   ↓            ↓          ↓          ↓
memory      runtime     wire     extensions
   ↓            ↓          ↓          ↓
   └────────────┴──────────┴──────────┘

             kernel
          ↓     ↓     ↓
        api   cli  desktop

     channels
1

Types Layer

openfang-types defines all core data structures with zero dependencies. Everything else builds on this foundation.
2

Substrate Layer

Memory, runtime, wire protocol, and extensions implement core subsystems using only the types layer.
3

Kernel Layer

The kernel orchestrates all subsystems without knowing about I/O boundaries (API, CLI, desktop).
4

Interface Layer

API, CLI, and desktop apps expose the kernel to users through different interfaces.

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 on openfang-kernel (circular dependency). Solution: KernelHandle trait.
// In openfang-runtime
pub trait KernelHandle: Send + Sync {
    fn spawn_agent(&self, manifest: AgentManifest) -> Result<AgentId>;
    fn check_capability(&self, agent_id: AgentId, cap: Capability) -> bool;
    fn get_budget_remaining(&self, agent_id: AgentId) -> Option<f64>;
}

// In openfang-kernel
impl KernelHandle for OpenFangKernel {
    fn spawn_agent(&self, manifest: AgentManifest) -> Result<AgentId> {
        // actual implementation
    }
}
The runtime receives an 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:
#[async_trait]
pub trait Memory: Send + Sync {
    async fn recall(&self, query: &str, limit: usize) -> Vec<MemoryFragment>;
    async fn store(&self, agent_id: AgentId, content: &str, source: MemorySource);
    async fn get(&self, agent_id: AgentId, key: &str) -> Option<Value>;
    async fn set(&self, agent_id: AgentId, key: &str, value: Value);
    // ... knowledge graph operations
}
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:
Telegram Webhook → API Route → Channel Bridge → Kernel Event Bus → Agent Runtime

                              Response Queue

                            Telegram Bot API ← HTTP Client
This allows agents to respond through the same channel they were messaged on, creating a unified conversational experience.

Build & Deployment

[profile.release]
lto = true              # Link-time optimization
codegen-units = 1       # Single codegen unit for max optimization
strip = true            # Strip debug symbols
opt-level = 3           # Maximum optimization
This produces a ~32MB binary on Linux x86_64 with all 14 crates linked.
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)
All builds use rustls instead of OpenSSL to avoid linking against system libraries.
FROM rust:1.75 as builder
WORKDIR /build
COPY . .
RUN cargo build --release -p openfang-cli

FROM debian:bookworm-slim
RUN apt-get update && apt-get install -y ca-certificates && rm -rf /var/lib/apt/lists/*
COPY --from=builder /build/target/release/openfang /usr/local/bin/
EXPOSE 4200
CMD ["openfang", "start"]
Final image is ~80MB (binary + minimal Debian base).

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.rs boots a real daemon and hits endpoints
  • Property tests: Critical security code (taint tracking, audit chain) uses property-based testing
# Run all tests (currently 1,767+ passing)
cargo test --workspace

# Run only kernel tests
cargo test -p openfang-kernel

# Run integration tests with real LLM calls (requires API keys)
GROQ_API_KEY=xxx cargo test --test api_integration_test -- --ignored
The project enforces zero Clippy warnings in CI. Every commit must pass cargo clippy --workspace --all-targets -- -D warnings.

Performance Characteristics

MetricValueComparison
Cold start180ms28× faster than OpenClaw (5.98s)
Idle memory40MB10× smaller than OpenClaw (394MB)
Binary size32MB16× smaller than OpenClaw (500MB)
Test suite1,767+Most comprehensive in category
These numbers come from:
  • 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