lnmp_net/
lib.rs

1#![warn(missing_docs)]
2#![warn(clippy::all)]
3
4//! # lnmp-net
5//!
6//! Network behavior standardization for LNMP agent networks.
7//!
8//! LNMP-Net provides semantic message classification, QoS primitives, and intelligent
9//! routing decisions for LLM/agent networks. It builds on top of the LNMP ecosystem
10//! (lnmp-core, lnmp-envelope, lnmp-transport) without replacing them.
11//!
12//! ## Core Concepts
13//!
14//! - **MessageKind**: Semantic classification (Event/State/Command/Query/Alert)
15//! - **NetMessage**: Wraps LNMP envelope with network metadata (priority, TTL, class)
16//! - **RoutingPolicy**: Decides whether messages go to LLM, local processing, or are dropped
17//!
18//! ## Quick Start
19//!
20//! ```
21//! use lnmp_core::{LnmpRecord, LnmpField, LnmpValue};
22//! use lnmp_envelope::EnvelopeBuilder;
23//! use lnmp_net::{MessageKind, NetMessage, RoutingPolicy, RoutingDecision};
24//!
25//! // Create a record
26//! let mut record = LnmpRecord::new();
27//! record.add_field(LnmpField { fid: 12, value: LnmpValue::Int(42) });
28//!
29//! // Wrap with envelope
30//! let envelope = EnvelopeBuilder::new(record)
31//!     .timestamp(1700000000000)
32//!     .source("sensor-01")
33//!     .build();
34//!
35//! // Create network message
36//! let msg = NetMessage::new(envelope, MessageKind::Event);
37//!
38//! // Make routing decision
39//! let policy = RoutingPolicy::default();
40//! let decision = policy.decide(&msg, 1700000001000).unwrap();
41//!
42//! match decision {
43//!     RoutingDecision::SendToLLM => println!("Sending to LLM"),
44//!     RoutingDecision::ProcessLocally => println!("Processing locally"),
45//!     RoutingDecision::Drop => println!("Dropping message"),
46//! }
47//! ```
48//!
49//! ## Message Kinds
50//!
51//! - **Event**: Sensor data, telemetry, user actions
52//! - **State**: System state snapshots, health status
53//! - **Command**: Imperative actions ("start motor")
54//! - **Query**: Information requests ("get temperature")
55//! - **Alert**: Critical warnings (health/safety/security)
56//!
57//! Each kind has default priority and TTL values tuned for typical use cases.
58//!
59//! ## Routing Logic (ECO Profile)
60//!
61//! The `RoutingPolicy` implements Energy/Token Optimization:
62//!
63//! 1. **Expired messages** → Drop (wasteful to process)
64//! 2. **Alerts** with high priority → Always send to LLM
65//! 3. **Events/State**: Compute importance score (priority + SFE) → threshold check
66//! 4. **Commands/Queries** → Process locally (unless complex)
67//!
68//! This reduces LLM API calls by 90%+ while maintaining decision quality.
69//!
70//! ## Features
71//!
72//! - `serde`: Enable serde serialization support (optional)
73
74pub mod error;
75pub mod kind;
76pub mod message;
77pub mod routing;
78
79#[cfg(feature = "transport")]
80pub mod transport;
81
82pub use error::{NetError, Result};
83pub use kind::MessageKind;
84pub use message::{NetMessage, NetMessageBuilder};
85pub use routing::{RoutingDecision, RoutingPolicy};
86
87// Re-export commonly used types for convenience
88pub use lnmp_core::{LnmpField, LnmpRecord, LnmpValue};
89pub use lnmp_envelope::{EnvelopeBuilder, LnmpEnvelope};