Skip to main content

DemotingPolicyMemory

Struct DemotingPolicyMemory 

Source
pub struct DemotingPolicyMemory<M, P, H> { /* private fields */ }
Expand description

Applies a policy and delivers newly demoted prefixes to a hook before returning retained history. The policy must report demotions through MemoryPolicy::apply_with_demoted.

Only one delivery per tracked conversation runs at a time. Concurrent loads return retained history immediately without waiting for the hook, so success does not guarantee durable demotion. Hook errors reach only the delivering caller; unchanged watermarks allow later loads to retry.

Watermarks are process-local. Hooks must tolerate redelivery after restarts, cancellation, or discarded tracking state, following DemotionHook.

use rig_memory::{
    DemotingPolicyMemory, DemotionHook, InMemoryConversationMemory,
    MemoryError, NoopDemotionHook, SlidingWindowMemory,
};

let memory = DemotingPolicyMemory::new(
    InMemoryConversationMemory::new(),
    SlidingWindowMemory::last_messages(20),
    NoopDemotionHook,
);

Implementations§

Source§

impl<M, P, H> DemotingPolicyMemory<M, P, H>

Source

pub fn new(inner: M, policy: P, hook: H) -> Self

Wrap inner so every load runs through policy and demoted messages flow into hook.

Source§

impl<M, P, H> DemotingPolicyMemory<M, P, H>

Source

pub fn inner(&self) -> &M

Return a reference to the wrapped backend.

Source

pub fn policy(&self) -> &P

Return a reference to the wrapped policy.

Source

pub fn hook(&self) -> &H

Return a reference to the third component.

Source

pub fn into_inner(self) -> (M, P, H)

Consume the wrapper and return its three components.

Source

pub fn forget(&self, conversation_id: &ConversationId)

Drop the in-process state for conversation_id.

Entries otherwise persist for the wrapper’s lifetime. Does nothing if the state lock is poisoned. In-flight work is not cancelled.

Source

pub fn tracked_conversations(&self) -> usize

Number of conversations currently tracked in the state map. Useful for telemetry and leak detection. Returns 0 if the internal state lock is poisoned.

Trait Implementations§

Source§

impl<M, P, H> ConversationMemory for DemotingPolicyMemory<M, P, H>

Source§

fn load<'a>( &'a self, conversation_id: &'a ConversationId, ) -> WasmBoxedFuture<'a, Result<Vec<Message>, MemoryError>>

Load the full conversation history for conversation_id. Read more
Source§

fn append<'a>( &'a self, conversation_id: &'a ConversationId, messages: Vec<Message>, ) -> WasmBoxedFuture<'a, Result<(), MemoryError>>

Append messages to the conversation identified by conversation_id. Read more
Source§

fn clear<'a>( &'a self, conversation_id: &'a ConversationId, ) -> WasmBoxedFuture<'a, Result<(), MemoryError>>

Remove all stored messages for conversation_id.
Source§

impl<M, P, H> Debug for DemotingPolicyMemory<M, P, H>
where M: Debug, P: Debug,

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<M, P, H> !Freeze for DemotingPolicyMemory<M, P, H>

§

impl<M, P, H> RefUnwindSafe for DemotingPolicyMemory<M, P, H>

§

impl<M, P, H> Send for DemotingPolicyMemory<M, P, H>
where M: Send, P: Send, H: Send,

§

impl<M, P, H> Sync for DemotingPolicyMemory<M, P, H>
where M: Sync, P: Sync, H: Sync,

§

impl<M, P, H> Unpin for DemotingPolicyMemory<M, P, H>
where M: Unpin, P: Unpin, H: Unpin,

§

impl<M, P, H> UnsafeUnpin for DemotingPolicyMemory<M, P, H>

§

impl<M, P, H> UnwindSafe for DemotingPolicyMemory<M, P, H>
where M: UnwindSafe, P: UnwindSafe, H: UnwindSafe,

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> 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 = !

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

fn try_from(value: U) -> Result<T, !>

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<T> WasmCompatSend for T
where T: Send,

Source§

impl<T> WasmCompatSync for T
where T: Sync,

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