FEAGI Agent SDK (Rust)
Production-ready Rust client library for building FEAGI agents.
Features
✅ Automatic Registration - Register with FEAGI with retry/exponential backoff
✅ Background Heartbeat - Automatic keepalive to prevent agent pruning
✅ Reconnection Logic - Handle network issues gracefully
✅ Sensory Data - Send neuron activation data to FEAGI (ZMQ PUSH)
✅ Motor Data - Receive motor commands from FEAGI (ZMQ SUB)
✅ Thread-Safe - Safe concurrent access across threads
✅ Graceful Shutdown - Automatic deregistration on drop
Quick Start
use ;
// Create configuration
let config = new
.with_feagi_host
.with_vision_capability
.with_heartbeat_interval;
// Create and connect client
let mut client = new?;
client.connect?;
// Send sensory data
client.send_sensory_data?;
// Client automatically deregisters on drop
Installation
Add to your Cargo.toml:
[]
= { = "../feagi-agent" }
Configuration
Agent Types
AgentType::Sensory- Sends sensory data to FEAGI (camera, sensors, etc.)AgentType::Motor- Receives motor commands from FEAGI (servos, actuators, etc.)AgentType::Both- Bidirectional agent (both sensory input and motor output)
Capabilities
Vision Capability
config.with_vision_capability;
Motor Capability
config.with_motor_capability;
Custom Capability
use json;
config.with_custom_capability;
Network Configuration
let config = new
// Option 1: Set FEAGI host (uses default ports)
.with_feagi_host
// Option 2: Set endpoints individually
.with_registration_endpoint
.with_sensory_endpoint
.with_motor_endpoint;
Reliability Configuration
let config = new
.with_heartbeat_interval // heartbeat every 5 seconds
.with_connection_timeout_ms // 5 second timeout
.with_registration_retries; // retry 3 times before giving up
Examples
Simple Sensory Agent
See examples/simple_sensory_agent.rs for full code.
Video Camera Agent
use ;
let config = new
.with_feagi_host
.with_vision_capability;
let mut client = new?;
client.connect?;
// In your video processing loop:
for frame in video_frames
Motor Agent
use ;
let config = new
.with_feagi_host
.with_motor_capability;
let mut client = new?;
client.connect?;
// Receive motor commands
loop
Architecture
ZMQ Communication
The SDK uses ZeroMQ for all communication with FEAGI:
| Socket Type | Direction | Purpose |
|---|---|---|
| REQ/REP | Agent → FEAGI | Registration & Heartbeat |
| PUSH | Agent → FEAGI | Sensory Data |
| SUB | FEAGI → Agent | Motor Commands |
Heartbeat Service
The heartbeat service runs in a background thread and automatically sends keepalive messages to FEAGI:
- Configured via
heartbeat_interval(default: 5 seconds) - Prevents agent from being pruned due to inactivity
- Automatically stops on client drop
- Set interval to 0 to disable
Reconnection Strategy
The SDK uses exponential backoff for connection retries:
- Initial backoff:
retry_backoff_ms(default: 1000ms) - Each retry doubles the backoff: 1s → 2s → 4s → 8s → ...
- Maximum backoff: 60 seconds
- Maximum retries:
registration_retries(default: 3)
Error Handling
All operations return Result<T, SdkError>:
use SdkError;
match client.connect
Error Types
SdkError::Zmq- ZMQ communication error (retryable)SdkError::Timeout- Connection timeout (retryable)SdkError::RegistrationFailed- FEAGI rejected registrationSdkError::NotRegistered- Attempted operation before registrationSdkError::InvalidConfig- Configuration validation failedSdkError::HeartbeatFailed- Heartbeat not acknowledged
Thread Safety
AgentClient is safe to share across threads:
use Arc;
let client = new;
let client_clone = clone;
spawn;
Logging
The SDK uses the log crate. Initialize with env_logger:
from_default_env
.filter_level
.init;
Set log level via environment variable:
RUST_LOG=feagi_agent=debug
Testing
Run unit tests:
Integration tests (requires running FEAGI):
License
Apache-2.0
Contributing
See CONTRIBUTING.md for guidelines.