Development Environment
Prerequisites
Rust 1.75+
Install via rustup
Git
Version control for source code
Python 3.8+
Optional, for Python runtime and skills
LLM API Key
For end-to-end testing (Groq, OpenAI, Anthropic)
Clone and Build
The first build takes a few minutes because it compiles SQLite (bundled) and Wasmtime. Subsequent builds are incremental.
Environment Variables
For running integration tests that hit a real LLM, set at least one provider key:Tests that require a real LLM key will skip gracefully if the env var is absent.
Building and Testing
Build the Entire Workspace
Run All Tests
Run Tests for a Single Crate
Check for Clippy Warnings
The CI pipeline enforces zero clippy warnings.
Format Code
Run the Doctor Check
After building, verify your local setup:Code Style
Formatting
- Use
rustfmtwith default settings - Run
cargo fmt --allbefore every commit
Linting
cargo clippy --workspace -- -D warningsmust pass with zero warnings
Documentation
- All public types and functions must have doc comments (
///)
Error Handling
- Use
thiserrorfor error types - Avoid
unwrap()in library code; prefer?propagation
Naming Conventions
| Type | Convention | Example |
|---|---|---|
| Types | PascalCase | OpenFangKernel, AgentManifest |
| Functions/methods | snake_case | spawn_agent, get_status |
| Constants | SCREAMING_SNAKE_CASE | MAX_RETRIES, DEFAULT_PORT |
| Crate names | kebab-case | openfang-kernel, openfang-api |
Dependencies
Workspace dependencies are declared in the root
Cargo.toml. Prefer reusing workspace deps over adding new ones. If you need a new dependency, justify it in the PR.Testing
- Every new feature must include tests
- Use
tempfile::TempDirfor filesystem isolation - Use random port binding for network tests
Serde
- All config structs use
#[serde(default)]for forward compatibility with partial TOML
Architecture Overview
OpenFang is organized as a Cargo workspace with 14 crates:openfang-types
openfang-types
Shared type definitions, taint tracking, manifest signing (Ed25519), model catalog, MCP/A2A config types
openfang-memory
openfang-memory
SQLite-backed memory substrate with vector embeddings, usage tracking, canonical sessions, JSONL mirroring
openfang-runtime
openfang-runtime
Agent loop, 3 LLM drivers (Anthropic/Gemini/OpenAI-compat), 38 built-in tools, WASM sandbox, MCP client/server, A2A protocol
openfang-hands
openfang-hands
Hands system (curated autonomous capability packages), 7 bundled hands
openfang-extensions
openfang-extensions
Integration registry (25 bundled MCP templates), AES-256-GCM credential vault, OAuth2 PKCE
openfang-kernel
openfang-kernel
Assembles all subsystems: workflow engine, RBAC auth, heartbeat monitor, cron scheduler, config hot-reload
openfang-api
openfang-api
REST/WS/SSE API (Axum 0.8), 76 endpoints, 14-page SPA dashboard, OpenAI-compatible
/v1/chat/completionsopenfang-channels
openfang-channels
40 channel adapters (Telegram, Discord, Slack, WhatsApp, and 36 more), formatter, rate limiter
openfang-wire
openfang-wire
OFP (OpenFang Protocol): TCP P2P networking with HMAC-SHA256 mutual authentication
openfang-cli
openfang-cli
Clap CLI with daemon auto-detect (HTTP mode vs. in-process fallback), MCP server
openfang-migrate
openfang-migrate
Migration engine for importing from OpenClaw (and future frameworks)
openfang-skills
openfang-skills
Skill system: 60 bundled skills, FangHub marketplace, OpenClaw compatibility, prompt injection scanning
openfang-desktop
openfang-desktop
Tauri 2.0 native desktop app (WebView + system tray + single-instance + notifications)
xtask
xtask
Build automation tasks
Key Architectural Patterns
KernelHandle trait: Defined in openfang-runtime, implemented on OpenFangKernel in openfang-kernel. This avoids circular crate dependencies while enabling inter-agent tools.Shared memory: A fixed UUID (
AgentId(Uuid::from_bytes([0..0, 0x01]))) provides a cross-agent KV namespace.Daemon detection: The CLI checks
~/.openfang/daemon.json and pings the health endpoint. If a daemon is running, commands use HTTP; otherwise, they boot an in-process kernel.Capability-based security: Every agent operation is checked against the agent’s granted capabilities before execution.
How to Add a New Agent Template
Agent templates live in theagents/ directory. Each template is a folder containing an agent.toml manifest.
Steps
- Create a new directory under
agents/:
- Write the manifest:
- Include a system prompt if needed by adding it to the
[model]section:
- Test by spawning:
- Submit a PR with the new template.
How to Add a New Channel Adapter
Channel adapters live incrates/openfang-channels/src/. Each adapter implements the ChannelAdapter trait.
Steps
-
Create a new file:
crates/openfang-channels/src/myplatform.rs -
Implement the
ChannelAdaptertrait:
- Register the module in
crates/openfang-channels/src/lib.rs:
- Wire it up in the channel bridge so the daemon starts it alongside other adapters.
-
Add configuration support in
openfang-typesconfig structs. - Add CLI setup wizard instructions.
- Write tests and submit a PR.
How to Add a New Tool
Built-in tools are defined incrates/openfang-runtime/src/tool_runner.rs.
Steps
- Add the tool implementation function:
- Register it in the
execute_toolmatch block:
- Add the tool definition to
builtin_tool_definitions():
- Agents that need the tool must list it in their manifest:
- Write tests for the tool function.
-
If the tool requires kernel access (e.g., inter-agent communication), accept
Option<&Arc<dyn KernelHandle>>and handle theNonecase gracefully.
Pull Request Process
1. Fork and Branch
Create a feature branch frommain. Use descriptive names:
feat/add-matrix-adapterfix/session-restore-crashdocs/improve-installation-guide
2. Make Your Changes
Follow the code style guidelines above.3. Test Thoroughly
4. Write a Clear PR Description
Explain what changed and why. Include before/after examples if applicable.5. One Concern per PR
Keep PRs focused. A single PR should address one feature, one bug fix, or one refactor - not all three.
6. Review Process
At least one maintainer must approve before merge. Address review feedback promptly.7. CI Must Pass
All automated checks must be green before merge.Commit Messages
Use clear, imperative-mood messages:Code of Conduct
This project follows the Contributor Covenant Code of Conduct. By participating, you agree to uphold a welcoming, inclusive, and harassment-free environment for everyone. Please report unacceptable behavior to the maintainers.Questions?
GitHub Discussions
Ask questions and share ideas
GitHub Issues
Report bugs or request features
Discord
Chat with the community
Documentation
Read detailed guides
Thank you for contributing to OpenFang. Every contribution, no matter how small, helps make the project better for everyone.