System Architecture
ZeroClaw is a Rust-first autonomous agent runtime built on a trait-driven, modular architecture designed for high performance, security, and extensibility.Design Principles
The architecture is guided by these core principles:- Trait + Factory Pattern: Extension points are intentionally explicit and swappable
- Security-First: Defaults lean secure-by-default with pairing, bind safety, limits, and secret handling
- Performance Goals: Binary size and execution speed are product goals, not nice-to-haves
- Config as API: Schema and CLI commands are effectively public interfaces
- Deterministic Behavior: Reliable CI and reproducibility are mandatory
High-Level Component View
Module Structure
The codebase follows a clear module hierarchy:Agent Orchestration Loop
The agent loop (src/agent/loop_.rs) coordinates the execution cycle:
- Message Reception: Channel delivers user message
- Context Assembly: Load conversation history and system prompt
- Provider Invocation: LLM generates response with optional tool calls
- Tool Execution: Validate and execute requested tools
- Security Gates: Apply policy checks at each boundary
- Memory Storage: Persist important facts and decisions
- Response Delivery: Send result back through channel
Extension Points
The architecture defines explicit extension points through traits:Security Architecture
Security is layered and defense-in-depth: Key security components:- AutonomyLevel: Controls agent action permissions (ReadOnly, Supervised, Full)
- SecurityPolicy: Enforces command allowlists, path validation, rate limiting
- PairingGuard: Device authentication for channel access
- SecretStore: Encrypted credential storage with age encryption
- Sandbox: OS-level isolation (Docker, Firejail, Bubblewrap, Landlock)
Configuration System
Configuration is loaded from:zeroclaw.toml(workspace config)~/.config/zeroclaw/config.toml(user config)- Environment variables (overrides)
- CLI flags (highest priority)
src/config/schema.rs and treated as a public API contract.
Performance Characteristics
- Binary Size: Optimized for minimal size (release profile, careful dependencies)
- Startup Time: Sub-second cold start for CLI commands
- Memory Usage: Efficient async runtime with bounded concurrency
- Throughput: Concurrent message processing across channels
Observability
The observability subsystem provides:- Structured Logging:
tracingcrate with configurable levels - Audit Trail: Security-relevant events logged to
AuditLogger - Runtime Traces: Performance and execution flow tracking
- Health Checks: Provider, channel, and memory health status