RoutingPolicy

Struct RoutingPolicy 

Source
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: f64

Minimum importance score (0.0-1.0) to route to LLM

§always_route_alerts: bool

Always route Alert messages to LLM regardless of score

§drop_expired: bool

Automatically drop expired messages

Implementations§

Source§

impl RoutingPolicy

Source

pub fn new(llm_threshold: f64) -> Self

Creates a new routing policy with custom threshold

Source

pub fn with_always_route_alerts(self, enabled: bool) -> Self

Sets whether to always route alerts to LLM

Source

pub fn with_drop_expired(self, enabled: bool) -> Self

Sets whether to drop expired messages

Source

pub fn with_scorer_config(self, config: ContextScorerConfig) -> Self

Sets custom SFE scorer configuration

Source

pub fn decide(&self, msg: &NetMessage, now_ms: u64) -> Result<RoutingDecision>

Decides how to route a message

Decision flow:

  1. Check expiry (if enabled) -> Drop
  2. Check if Alert + high priority -> SendToLLM
  3. For Event/State: compute importance score -> threshold check
  4. Commands/Queries -> ProcessLocally
§Arguments
  • msg - The message to route
  • now_ms - Current time in epoch milliseconds
Source

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.5

Trait Implementations§

Source§

impl Clone for RoutingPolicy

Source§

fn clone(&self) -> RoutingPolicy

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for RoutingPolicy

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for RoutingPolicy

Source§

fn default() -> Self

Returns the “default value” for a 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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.