pub struct AgentClient { /* private fields */ }Expand description
Main FEAGI Agent Client
This client handles:
- Registration with FEAGI
- Automatic heartbeat
- Sending sensory data
- Receiving motor data (for motor agents)
- Automatic deregistration on drop
§Example
use feagi_agent::{AgentClient, AgentConfig, AgentType};
let config = AgentConfig::new("my_camera", AgentType::Sensory)
.with_feagi_host("localhost")
.with_vision_capability("camera", (640, 480), 3, "i_vision");
let mut client = AgentClient::new(config)?;
client.connect()?;
// Send sensory data
client.send_sensory_data(vec![(0, 50.0), (1, 75.0)])?;
// Client auto-deregisters on dropImplementations§
Source§impl AgentClient
impl AgentClient
Sourcepub fn new(config: AgentConfig) -> Result<Self>
pub fn new(config: AgentConfig) -> Result<Self>
Sourcepub fn registration_body_json(&self) -> Option<&Value>
pub fn registration_body_json(&self) -> Option<&Value>
Get the last successful registration response body (JSON), if available.
This is only set after a successful connect() / registration step.
Sourcepub fn connect(&mut self) -> Result<()>
pub fn connect(&mut self) -> Result<()>
Connect to FEAGI and register the agent
This will:
- Create ZMQ control sockets (registration/control)
- Register with FEAGI
- Create ZMQ data sockets (sensory/motor/viz)
- Start heartbeat service (ONLY after successful registration)
IMPORTANT: Background threads are ONLY started AFTER successful registration. This prevents thread interference with GUI event loops (e.g., MuJoCo, Godot). If registration fails, NO threads are spawned.
TIMING: FEAGI starts its ZMQ data stream services asynchronously after processing the registration message. Data socket connection uses retry/backoff to handle stream readiness delays.
Sourcepub fn reconnect_data_streams(&mut self) -> Result<()>
pub fn reconnect_data_streams(&mut self) -> Result<()>
Reconnect data sockets (sensory/motor/viz) using configured retry/backoff.
Sourcepub fn send_sensory_bytes(&self, bytes: Vec<u8>) -> Result<()>
pub fn send_sensory_bytes(&self, bytes: Vec<u8>) -> Result<()>
Send pre-serialized sensory bytes to FEAGI (real-time semantics).
This is intended for high-performance clients (e.g., Python SDK brain_input) that already produce FeagiByteContainer bytes via Rust-side encoding caches.
Real-time policy:
- Uses ZMQ DONTWAIT to avoid blocking the caller.
- On backpressure (EAGAIN), the message is dropped (latest-only semantics).
Sourcepub fn try_send_sensory_bytes(&self, bytes: &[u8]) -> Result<bool>
pub fn try_send_sensory_bytes(&self, bytes: &[u8]) -> Result<bool>
Try sending pre-serialized sensory bytes to FEAGI (non-blocking), returning whether it was sent.
Returns:
Ok(true)if the message was sent.Ok(false)if dropped due to backpressure (EAGAIN).Err(...)for other failures (not registered, socket errors).
Sourcepub fn receive_motor_data(
&self,
) -> Result<Option<CorticalMappedXYZPNeuronVoxels>>
pub fn receive_motor_data( &self, ) -> Result<Option<CorticalMappedXYZPNeuronVoxels>>
Receive motor data from FEAGI (non-blocking)
Returns None if no data is available. Motor data is in binary XYZP format (CorticalMappedXYZPNeuronVoxels).
§Example
use feagi_structures::neuron_voxels::xyzp::CorticalMappedXYZPNeuronVoxels;
if let Some(motor_data) = client.receive_motor_data()? {
// Process binary motor data
for (cortical_id, neurons) in motor_data.iter() {
println!("Motor area {:?}: {} neurons", cortical_id, neurons.len());
}
}Sourcepub fn control_request(
&self,
method: &str,
route: &str,
data: Option<Value>,
) -> Result<Value>
pub fn control_request( &self, method: &str, route: &str, data: Option<Value>, ) -> Result<Value>
Make a REST API request to FEAGI over ZMQ
§Arguments
method- HTTP method (GET, POST, PUT, DELETE)route- API route (e.g., “/v1/system/health_check”)data- Optional request body for POST/PUT requests
§Example
// GET request
let health = client.control_request("GET", "/v1/system/health_check", None)?;
// POST request
let data = serde_json::json!({"key": "value"});
let response = client.control_request("POST", "/v1/some/endpoint", Some(data))?;Sourcepub fn is_registered(&self) -> bool
pub fn is_registered(&self) -> bool
Check if agent is registered
Trait Implementations§
Auto Trait Implementations§
impl !Freeze for AgentClient
impl !RefUnwindSafe for AgentClient
impl Send for AgentClient
impl Sync for AgentClient
impl Unpin for AgentClient
impl !UnwindSafe for AgentClient
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more