pub struct RoutingPolicy {
pub llm_threshold: f64,
pub always_route_alerts: bool,
pub drop_expired: bool,
/* private fields */
}Expand description
Policy for routing messages to LLM vs local processing
Implements the ECO (Energy/Token Optimization) profile logic:
- Alerts with high priority always routed to LLM
- Expired messages dropped
- Event/State messages scored using SFE and routed based on threshold
- Commands/Queries typically processed locally
§Examples
use lnmp_core::LnmpRecord;
use lnmp_envelope::EnvelopeBuilder;
use lnmp_net::{MessageKind, NetMessage, RoutingPolicy, RoutingDecision};
let policy = RoutingPolicy::default();
// Alert message -> always to LLM
let envelope = EnvelopeBuilder::new(LnmpRecord::new())
.timestamp(1000)
.build();
let alert = NetMessage::new(envelope, MessageKind::Alert);
assert_eq!(policy.decide(&alert, 2000).unwrap(), RoutingDecision::SendToLLM);Fields§
§llm_threshold: f64Minimum importance score (0.0-1.0) to route to LLM
always_route_alerts: boolAlways route Alert messages to LLM regardless of score
drop_expired: boolAutomatically drop expired messages
Implementations§
Source§impl RoutingPolicy
impl RoutingPolicy
Sourcepub fn with_always_route_alerts(self, enabled: bool) -> Self
pub fn with_always_route_alerts(self, enabled: bool) -> Self
Sets whether to always route alerts to LLM
Sourcepub fn with_drop_expired(self, enabled: bool) -> Self
pub fn with_drop_expired(self, enabled: bool) -> Self
Sets whether to drop expired messages
Sourcepub fn with_scorer_config(self, config: ContextScorerConfig) -> Self
pub fn with_scorer_config(self, config: ContextScorerConfig) -> Self
Sets custom SFE scorer configuration
Sourcepub fn decide(&self, msg: &NetMessage, now_ms: u64) -> Result<RoutingDecision>
pub fn decide(&self, msg: &NetMessage, now_ms: u64) -> Result<RoutingDecision>
Decides how to route a message
Decision flow:
- Check expiry (if enabled) -> Drop
- Check if Alert + high priority -> SendToLLM
- For Event/State: compute importance score -> threshold check
- Commands/Queries -> ProcessLocally
§Arguments
msg- The message to routenow_ms- Current time in epoch milliseconds
Sourcepub fn base_importance(&self, msg: &NetMessage, now_ms: u64) -> Result<f64>
pub fn base_importance(&self, msg: &NetMessage, now_ms: u64) -> Result<f64>
Computes base importance score for a message (0.0-1.0)
Combines:
- Priority (0-255 normalized to 0.0-1.0): 50% weight
- SFE score (freshness + importance from lnmp-sfe): 50% weight
§Formula
importance = (priority / 255.0) * 0.5 + sfe_score * 0.5Trait Implementations§
Source§impl Clone for RoutingPolicy
impl Clone for RoutingPolicy
Source§fn clone(&self) -> RoutingPolicy
fn clone(&self) -> RoutingPolicy
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for RoutingPolicy
impl Debug for RoutingPolicy
Auto Trait Implementations§
impl Freeze for RoutingPolicy
impl RefUnwindSafe for RoutingPolicy
impl Send for RoutingPolicy
impl Sync for RoutingPolicy
impl Unpin for RoutingPolicy
impl UnwindSafe for RoutingPolicy
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
Mutably borrows from an owned value. Read more