Overview
OneClaw’s architecture consists of 6 layers, each with a specific responsibility. Every layer is defined as a Rust trait with at least two implementations: a Noop (for testing) and a Default (for production).Layers are numbered L0-L5, with L0 being the foundation (security) and L5 being the interface (channels).
Layer 0: Security (Immune System)
Purpose & Responsibilities
Purpose & Responsibilities
Layer 0 enforces deny-by-default access control. Every action must be explicitly authorized.Core trait:
SecurityCore (defined in security/traits.rs:75)Key Methods
Action Types
Fromsecurity/traits.rs:18:- Read: Read access to a resource
- Write: Write access to a resource
- Execute: Execute a command or tool
- Network: Network access
- PairDevice: Pair a new device
Implementations
NoopSecurity (security/traits.rs:96): Allows everything. FOR TESTING ONLY.DefaultSecurity (security/default.rs:19): Production implementation with:- Device pairing with 6-digit OTP codes
- Filesystem scoping via
PathGuard - Per-command authorization
- Persistent device registry (SQLite)
- Rate limiting integration
Device Pairing Flow
Device Pairing Flow
OneClaw uses a pairing flow inspired by IoT device onboarding:
-
Generate Code: Agent generates 6-digit OTP (valid 5 minutes)
-
Verify Code: Client submits code to pair device
- Authorization: Paired device can now execute commands
security/default.rs:116, verification is atomic:Authorization Example
Authorization Example
Layer 1: Orchestrator (Heart)
Purpose & Responsibilities
Purpose & Responsibilities
Layer 1 is OneClaw’s competitive moat. It orchestrates LLM interactions with:
- Smart Routing (
ModelRouter): Choose the right model for the task - Chain Execution (
ChainExecutor): Multi-step reasoning pipelines - Context Management (
ContextManager): Prompt enrichment with memory
Smart Routing (ModelRouter)
Smart Routing (ModelRouter)
Defined in
orchestrator/router.rs:36:Complexity Analysis
Fromorchestrator/router.rs:120, complexity is determined by:- Keywords: “emergency”, “analyze”, “compare” → Critical/Complex
- Message Length: Under 5 words → Simple, over 50 words → Medium/Complex
- Memory Context: Has relevant memories → Medium+
- Explicit Hints: Caller can override
Routing Example
Chain Execution (ChainExecutor)
Chain Execution (ChainExecutor)
Multi-step reasoning for complex tasks. Defined in From
orchestrator/chain.rs:183:Chain Steps
Fromorchestrator/chain.rs:16:- LlmCall: Call LLM with prompt template
- MemorySearch: Search memory for context
- Transform: Format/transform output
- EmitEvent: Publish event to bus
- ToolCall: Execute a registered tool
Example Chain
orchestrator/chain.rs:229, the DefaultChainExecutor runs steps sequentially, passing output forward with template substitution.Context Management (ContextManager)
Context Management (ContextManager)
Enriches prompts with relevant context from memory and system state.Future implementation (currently uses inline context building in
runtime.rs:167):Layer 2: Memory (Brain)
Purpose & Responsibilities
Purpose & Responsibilities
Layer 2 provides persistent storage with hybrid search: keyword (FTS5) + semantic (vector) + temporal (B-tree).Core trait defined in
memory/traits.rs:110:Memory Entry Structure
Memory Entry Structure
From
memory/traits.rs:45:Hybrid Search
Hybrid Search
SqliteMemory implementation supports:
- FTS5 Keyword Search: Fast full-text search via SQLite FTS5
- Vector Similarity: Cosine similarity for semantic search
- RRF Fusion: Reciprocal Rank Fusion combines both scores
runtime.rs:243:Zero-config graceful degradation: If no embedding provider is configured, memory falls back to FTS5-only search. No special configuration needed.
Query Builder
Query Builder
From
memory/traits.rs:77:Layer 3: Event Bus (Nervous System)
Purpose & Responsibilities
Purpose & Responsibilities
Layer 3 provides reactive pub/sub for real-time event processing. Defined in
event_bus/traits.rs:71:Event Structure
Event Structure
From Example:
event_bus/traits.rs:10:Sync vs Async Event Bus
Sync vs Async Event Bus
OneClaw provides two implementations:
DefaultEventBus (Sync)
Fromevent_bus/bus.rs: Queue-based, processed via drain() calls.- Use case: Standard workloads where sub-second latency is acceptable
- Default: Automatically used unless overridden
AsyncEventBus (Async)
Fromevent_bus/async_bus.rs: Tokio broadcast channel for sub-10ms latency.- Use case: Real-time sensor monitoring, critical alerts
- Opt-in: Call
runtime.with_async_event_bus(capacity)
runtime.rs:150:Topic Pattern Matching
Topic Pattern Matching
Supports prefix matching:
Layer 4: Tool (Hands)
Purpose & Responsibilities
Purpose & Responsibilities
Layer 4 provides sandboxed execution of external actions. Defined in
tool/traits.rs:59:Tool Definition
Tool Definition
From
tool/traits.rs:18:Tool Registry
Tool Registry
From Security: Tools are executed AFTER authorization check in
tool/registry.rs, the ToolRegistry manages tool lifecycle:runtime.rs:720:Built-in Tools
Built-in Tools
From
README.md:152, OneClaw includes:- system_info: Get system metrics (CPU, memory, disk)
- file_write: Write files (with path validation)
- notify: Send notifications/alerts
Layer 5: Channel (Ears & Mouth)
Purpose & Responsibilities
Purpose & Responsibilities
Layer 5 handles multi-source I/O. Defined in
channel/traits.rs:27:Message Types
Message Types
From
channel/traits.rs:8:Channel Manager
Channel Manager
From From
channel/manager.rs, the ChannelManager multiplexes multiple channels:runtime.rs:969, channels are polled in round-robin:Built-in Channels
Built-in Channels
From
README.md:42, OneClaw supports:- CLI: Interactive command-line interface
- TCP: Network socket server
- Telegram: Telegram bot API
- MQTT: IoT message broker
Layer Composition Example
Here’s how all layers work together when processing a user message:Next Steps
Trait Philosophy
Why traits for each layer?
Security Model
Deep dive into Layer 0