OpenFang Installation and Initialization Guide: From Zero to Your First Agent
Slug: openfang-install-setup-guide
Category: usage-guides
Target Keywords: OpenFang installation, OpenFang configuration tutorial, OpenFang getting started guide
Search Intent: Informational (user wants to deploy OpenFang)
Target Word Count: ~1800 words
Language: en
What is OpenFang?
OpenFang is a production-grade Agent operating system built on Rust. Unlike traditional AI chat frameworks, OpenFang provides a complete Agent runtime environment—featuring 180ms cold starts, 40MB memory footprint, 16 layers of security, and 40+ channel adapters. Whether you want to run a simple automation task locally or build a cross-platform 24/7 autonomous Agent cluster, OpenFang is up to the task.
This article will guide you through the installation, initialization, and running of your first Agent from scratch.
System Requirements
Before you begin, please ensure your system meets the following minimum requirements:
| Component | Minimum Requirement | Recommended Configuration |
|---|---|---|
| OS | Linux / macOS / Windows (WSL2) | Ubuntu 22.04+ |
| Memory | 512 MB | 2 GB+ |
| Disk Space | 100 MB | 1 GB+ |
| Runtime | Rust 1.75+ | Rust 1.80+ |
| Network | Outbound HTTPS | Stable internet connection |
OpenFang's design philosophy is "lightweight first"—it runs smoothly even on a Raspberry Pi 4 (4GB version).
Step 1: Install the Rust Toolchain
OpenFang is written in Rust, so you first need to install the Rust toolchain:
# Install Rustup (Rust toolchain manager)curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh# Reload environment variablessource "$HOME/.cargo/env"# Verify installationrustc --versioncargo --versionIf you already have Rust installed, we recommend updating to the latest stable version:
rustup update stableStep 2: Install OpenFang
OpenFang offers multiple installation methods; installing directly via Cargo is recommended:
# Install the latest version from crates.iocargo install openfang# Verify installationopenfang --versionIf you prefer building from source (suitable for advanced users needing custom configurations):
git clone https://github.com/openfang/openfang.gitcd openfangcargo build --release./target/release/openfang --versionDocker users can also use the official image:
docker pull openfang/openfang:latestdocker run -d --name openfang -v ./config:/app/config openfang/openfangStep 3: Initialize Configuration
Once installed, run the initialization command to create the configuration file:
# Create default configuration directoryopenfang init# Configuration file location# Linux/macOS: ~/.config/openfang/config.toml# Windows: %APPDATA%\openfang\config.tomlAfter initialization, a config.toml file will be generated. Key configuration items include:
[core]name = "my-first-agent" # Agent nameworkspace = "./workspace" # Workspace directorylog_level = "info" # Log level: trace, debug, info, warn, error[claude]api_key = "${ANTHROPIC_API_KEY}" # Read from environment variablesmodel = "claude-sonnet-5" # Default modelmax_tokens = 4096[security]sandbox_mode = "strict" # Sandbox mode: off, basic, strictnetwork_policy = "allowlist" # Network policyallowed_domains = ["api.anthropic.com"][channels]# Configure at least one channel adapterKey configuration notes:
- api_key: Supports environment variable references (format
${VAR_NAME}); do not write the API key directly into the configuration file. - sandbox_mode:
strictmode is recommended for production environments. - network_policy:
allowlistmode only allows access to whitelisted domains, whileblocklistmode blocks blacklisted domains. - channels: At least one channel adapter is required; otherwise, the Agent cannot interact with the outside world.
Step 4: Configure Anthropic API Key
OpenFang relies on the Claude API (via Anthropic), which requires an API key:
# Set environment variableexport ANTHROPIC_API_KEY="sk-ant-..."# Recommended: Add to your shell profileecho 'export ANTHROPIC_API_KEY="sk-ant-..."' >> ~/.bashrcsource ~/.bashrcYou can obtain your API key from the Anthropic Console.
Step 5: Select and Configure Channel Adapters
OpenFang supports over 40 channel adapters, allowing Agents to interact with users across different platforms. Common ones include:
| Adapter | Purpose | Configuration Complexity |
|---|---|---|
| CLI | Command-line interaction | ⭐ |
| Use Agent via WhatsApp | ⭐⭐ | |
| Telegram | Telegram Bot integration | ⭐⭐ |
| Discord | Discord Bot integration | ⭐⭐⭐ |
| Slack | Slack workspace integration | ⭐⭐⭐ |
| Web Chat | Web chat widget | ⭐⭐ |
Example configuration for Telegram:
[channels.telegram]enabled = truebot_token = "${TELEGRAM_BOT_TOKEN}"allowed_users = ["@your_username"]Step 6: Launch Your First Agent
Once configured, start the Agent:
# Basic startopenfang start# Specify configuration fileopenfang start --config ./my-config.toml# Run in backgroundopenfang start --daemon# View logsopenfang logs --followUpon successful startup, you will see:
⚡ OpenFang v1.0.0├─ Agent: my-first-agent├─ Model: claude-sonnet-5├─ Sandbox: strict├─ Channels: cli└─ Ready. Type /help for commands.In the CLI channel, you can chat directly with the Agent:
> /help> Check the weather for me today> Analyze the code structure of this GitHub repositoryStep 7: Verify Installation
Run the built-in diagnostic command to ensure everything is working correctly:
# Health checkopenfang doctor# Should output something like:# ✅ Rust toolchain: 1.80.0# ✅ Config file: valid# ✅ API key: configured# ✅ Network: ok (latency 45ms)# ✅ Workspace: writable# All checks passed.FAQ
What should I do if I encounter "error: linker `cc` not found" during installation?
``bash`
sudo apt update && sudo apt install build-essential
On macOS, install the Xcode Command Line Tools:
`bash``
xcode-select --install
What if I get an "API key not configured" error on startup?
1. Ensure the
ANTHROPIC_API_KEY environment variable is set: echo $ANTHROPIC_API_KEY2. Ensure you used the
"${ANTHROPIC_API_KEY}" reference format (with quotes) in the configuration file.3. Reload the configuration:
openfang reloadHow do I run OpenFang on a Raspberry Pi?
``bash
# Install Rust on Raspberry Pi
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
# Install dependencies
sudo apt install libssl-dev pkg-config
# Compile and install (ARM optimized)``
cargo install openfang --features arm-optimized
A Raspberry Pi 4 (4GB) can run 3-5 lightweight Agents simultaneously.
Can I use YAML for the configuration file?
How do I upgrade OpenFang to the latest version?
bash
cargo install openfang --force
openfang migrate # If there are configuration format changes
``Next Steps
Congratulations on completing your OpenFang installation and initialization! We recommend reading the following next:
- OpenFang Hands Configuration Guide: Learn how to configure Agent capability modules for different use cases.
- OpenFang Multi-Channel Adapter Configuration: Configure multiple channels simultaneously to make your Agent accessible everywhere.
- OpenFang Security Best Practices: Protect your Agents from attacks.