pub struct MemoryManager { /* private fields */ }Expand description
Orchestrates all registered MemoryProviders.
The chat loop interacts exclusively with MemoryManager; individual
providers are invisible to the rest of the codebase. Provider errors are
caught and logged so one failure never blocks others.
Implementations§
Source§impl MemoryManager
impl MemoryManager
pub fn new() -> Self
Sourcepub fn add_provider(&mut self, p: impl MemoryProvider + 'static)
pub fn add_provider(&mut self, p: impl MemoryProvider + 'static)
Register a provider. Providers are consulted in registration order.
Sourcepub async fn initialize_all(&mut self, ctx: &SessionContext)
pub async fn initialize_all(&mut self, ctx: &SessionContext)
Initialize all providers. Called once at session start.
Sourcepub fn build_system_prompt_additions(&self) -> String
pub fn build_system_prompt_additions(&self) -> String
Assemble the frozen system-prompt contribution from all providers. Call once at session start and cache the result.
Sourcepub async fn prefetch_all(&self, query: &str) -> String
pub async fn prefetch_all(&self, query: &str) -> String
Collect recalled context from all providers before a turn.
Sourcepub fn build_messages(
&self,
system_prompt: &str,
new_task: &str,
) -> Vec<MemMessage>
pub fn build_messages( &self, system_prompt: &str, new_task: &str, ) -> Vec<MemMessage>
Build the message list for the next API call.
Uses the first provider that implements build_messages to a
non-empty result. Falls back to a minimal [system, user] pair.
Sourcepub async fn sync_all(
&mut self,
user: &str,
assistant: &str,
metrics: &TurnMetrics,
)
pub async fn sync_all( &mut self, user: &str, assistant: &str, metrics: &TurnMetrics, )
Persist a completed turn to all providers.
Sourcepub fn restore_turns(&mut self, turns: &[ConversationTurn])
pub fn restore_turns(&mut self, turns: &[ConversationTurn])
Replace conversation-local history in every provider from durable turns.
Sourcepub fn take_compaction_record(&mut self) -> Option<String>
pub fn take_compaction_record(&mut self) -> Option<String>
Drain the first pending compaction record from any provider — the
TUI’s save site calls this after sync_all and persists the result
as a turn record (Step 18.5, #247).
Sourcepub async fn on_pre_compress(&self, messages: &[MemMessage]) -> String
pub async fn on_pre_compress(&self, messages: &[MemMessage]) -> String
Notify all providers before old messages are dropped.
Sourcepub async fn on_session_end(&mut self, messages: &[MemMessage])
pub async fn on_session_end(&mut self, messages: &[MemMessage])
Notify all providers at session end.
Sourcepub fn add_note(&mut self, fact: &str) -> Result<()>
pub fn add_note(&mut self, fact: &str) -> Result<()>
Add a fact to the first provider that accepts it (first Ok wins).
No name-based special-casing: every provider is offered the note via
the trait’s add_note. Providers whose default returns
NotesUnsupported are skipped; the first real rejection (e.g.
NoteStore’s over-budget curator error) is surfaced if no provider
accepts the note.
Sourcepub fn replace_note(
&mut self,
old_substring: &str,
new_text: &str,
) -> Result<()>
pub fn replace_note( &mut self, old_substring: &str, new_text: &str, ) -> Result<()>
Replace the single persisted note containing old_substring —
same first-note-capable-provider routing as Self::add_note.
Sourcepub fn remove_note(&mut self, substring: &str) -> Result<()>
pub fn remove_note(&mut self, substring: &str) -> Result<()>
Remove the single persisted note containing substring —
same first-note-capable-provider routing as Self::add_note.
Trait Implementations§
Auto Trait Implementations§
impl !RefUnwindSafe for MemoryManager
impl !UnwindSafe for MemoryManager
impl Freeze for MemoryManager
impl Send for MemoryManager
impl Sync for MemoryManager
impl Unpin for MemoryManager
impl UnsafeUnpin for MemoryManager
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
impl<T> ErasedDestructor for Twhere
T: 'static,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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