Skip to main content

AgentClient

Struct AgentClient 

Source
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 drop

Implementations§

Source§

impl AgentClient

Source

pub fn new(config: AgentConfig) -> Result<Self>

Create a new FEAGI agent client

§Arguments
  • config - Agent configuration
Source

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.

Source

pub fn connect(&mut self) -> Result<()>

Connect to FEAGI and register the agent

This will:

  1. Create ZMQ control sockets (registration/control)
  2. Register with FEAGI
  3. Create ZMQ data sockets (sensory/motor/viz)
  4. 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.

Source

pub fn reconnect_data_streams(&mut self) -> Result<()>

Reconnect data sockets (sensory/motor/viz) using configured retry/backoff.

Source

pub fn send_sensory_data(&self, neuron_pairs: Vec<(i32, f64)>) -> Result<()>

Send sensory data to FEAGI

§Arguments
  • neuron_pairs - Vector of (neuron_id, potential) pairs
§Example
client.send_sensory_data(vec![
    (0, 50.0),
    (1, 75.0),
    (2, 30.0),
])?;
Source

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).
Source

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).
Source

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());
    }
}
Source

pub fn receive_visualization_data(&self) -> Result<Option<Vec<u8>>>

Receive visualization data from FEAGI (non-blocking)

Returns None if no data is available.

§Example
if let Some(viz_data) = client.receive_visualization_data()? {
    // Process neural activity data
    println!("Visualization data size: {} bytes", viz_data.len());
}
Source

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))?;
Source

pub fn is_registered(&self) -> bool

Check if agent is registered

Source

pub fn agent_id(&self) -> &str

Get agent ID

Trait Implementations§

Source§

impl Drop for AgentClient

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more