pub struct ShortTermMemory { /* private fields */ }Expand description
Short-term memory - stores recent conversation history Uses a fixed-size ring buffer per user for memory efficiency Persists to disk (JSON) to allow restarts without losing context.
Implementations§
Source§impl ShortTermMemory
impl ShortTermMemory
Sourcepub async fn new(
max_messages: usize,
max_users: usize,
path: impl Into<PathBuf>,
) -> Self
pub async fn new( max_messages: usize, max_users: usize, path: impl Into<PathBuf>, ) -> Self
Create with custom capacity and persistence path
Sourcepub async fn default_capacity() -> Self
pub async fn default_capacity() -> Self
Create with default capacity (100 messages per user, 1000 active users)
Sourcepub fn message_count(&self, user_id: &str, agent_id: Option<&str>) -> usize
pub fn message_count(&self, user_id: &str, agent_id: Option<&str>) -> usize
Get current message count for a user/agent pair
Sourcepub fn prune_inactive(&self, duration: Duration)
pub fn prune_inactive(&self, duration: Duration)
Prune inactive users (older than duration) - Useful for manual cleanup
Trait Implementations§
Source§impl Memory for ShortTermMemory
impl Memory for ShortTermMemory
Source§fn store<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
user_id: &'life1 str,
agent_id: Option<&'life2 str>,
message: Message,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
fn store<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
user_id: &'life1 str,
agent_id: Option<&'life2 str>,
message: Message,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
Store a message
Source§fn retrieve<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
user_id: &'life1 str,
agent_id: Option<&'life2 str>,
limit: usize,
) -> Pin<Box<dyn Future<Output = Vec<Message>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
fn retrieve<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
user_id: &'life1 str,
agent_id: Option<&'life2 str>,
limit: usize,
) -> Pin<Box<dyn Future<Output = Vec<Message>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
Retrieve recent messages
Source§fn store_knowledge<'life0, 'life1, 'life2, 'life3, 'life4, 'life5, 'async_trait>(
&'life0 self,
user_id: &'life1 str,
agent_id: Option<&'life2 str>,
title: &'life3 str,
content: &'life4 str,
collection: &'life5 str,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
'life3: 'async_trait,
'life4: 'async_trait,
'life5: 'async_trait,
fn store_knowledge<'life0, 'life1, 'life2, 'life3, 'life4, 'life5, 'async_trait>(
&'life0 self,
user_id: &'life1 str,
agent_id: Option<&'life2 str>,
title: &'life3 str,
content: &'life4 str,
collection: &'life5 str,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
'life3: 'async_trait,
'life4: 'async_trait,
'life5: 'async_trait,
Store a specific piece of knowledge (not just a message)
Source§fn clear<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
user_id: &'life1 str,
agent_id: Option<&'life2 str>,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
fn clear<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
user_id: &'life1 str,
agent_id: Option<&'life2 str>,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
Clear memory for a user
Source§fn undo<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
user_id: &'life1 str,
agent_id: Option<&'life2 str>,
) -> Pin<Box<dyn Future<Output = Result<Option<Message>>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
fn undo<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
user_id: &'life1 str,
agent_id: Option<&'life2 str>,
) -> Pin<Box<dyn Future<Output = Result<Option<Message>>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
Undo last message
Source§fn search<'life0, 'life1, 'life2, 'life3, 'async_trait>(
&'life0 self,
user_id: &'life1 str,
agent_id: Option<&'life2 str>,
query: &'life3 str,
limit: usize,
) -> Pin<Box<dyn Future<Output = Result<Vec<Document>>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
'life3: 'async_trait,
fn search<'life0, 'life1, 'life2, 'life3, 'async_trait>(
&'life0 self,
user_id: &'life1 str,
agent_id: Option<&'life2 str>,
query: &'life3 str,
limit: usize,
) -> Pin<Box<dyn Future<Output = Result<Vec<Document>>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
'life3: 'async_trait,
Search the memory for relevant content
Source§fn store_batch<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
user_id: &'life1 str,
agent_id: Option<&'life2 str>,
messages: Vec<Message>,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
fn store_batch<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
user_id: &'life1 str,
agent_id: Option<&'life2 str>,
messages: Vec<Message>,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
Store multiple messages efficiently
Source§fn update_summary<'life0, 'life1, 'life2, 'life3, 'async_trait>(
&'life0 self,
collection: &'life1 str,
path: &'life2 str,
summary: &'life3 str,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
'life3: 'async_trait,
fn update_summary<'life0, 'life1, 'life2, 'life3, 'async_trait>(
&'life0 self,
collection: &'life1 str,
path: &'life2 str,
summary: &'life3 str,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
'life3: 'async_trait,
Update summary for a piece of knowledge
Source§fn link_scheduler(&self, _scheduler: Weak<Scheduler>)
fn link_scheduler(&self, _scheduler: Weak<Scheduler>)
Link a scheduler for background tasks
Source§fn fetch_document<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
collection: &'life1 str,
path: &'life2 str,
) -> Pin<Box<dyn Future<Output = Result<Option<Document>>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
fn fetch_document<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
collection: &'life1 str,
path: &'life2 str,
) -> Pin<Box<dyn Future<Output = Result<Option<Document>>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
Fetch a full document by path
Source§fn store_session<'life0, 'async_trait>(
&'life0 self,
_session: AgentSession,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn store_session<'life0, 'async_trait>(
&'life0 self,
_session: AgentSession,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Store an agent session state
Auto Trait Implementations§
impl Freeze for ShortTermMemory
impl !RefUnwindSafe for ShortTermMemory
impl Send for ShortTermMemory
impl Sync for ShortTermMemory
impl Unpin for ShortTermMemory
impl UnwindSafe for ShortTermMemory
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
Source§impl<T> GetSetFdFlags for T
impl<T> GetSetFdFlags for T
Source§fn get_fd_flags(&self) -> Result<FdFlags, Error>where
T: AsFilelike,
fn get_fd_flags(&self) -> Result<FdFlags, Error>where
T: AsFilelike,
Query the “status” flags for the
self file descriptor.Source§fn new_set_fd_flags(&self, fd_flags: FdFlags) -> Result<SetFdFlags<T>, Error>where
T: AsFilelike,
fn new_set_fd_flags(&self, fd_flags: FdFlags) -> Result<SetFdFlags<T>, Error>where
T: AsFilelike,
Source§fn set_fd_flags(&mut self, set_fd_flags: SetFdFlags<T>) -> Result<(), Error>where
T: AsFilelike,
fn set_fd_flags(&mut self, set_fd_flags: SetFdFlags<T>) -> Result<(), Error>where
T: AsFilelike,
Set the “status” flags for the
self file descriptor. Read moreSource§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>
Converts
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>
Converts
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 moreSource§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
Wrap the input message
T in a tonic::RequestSource§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
Wrap the input message
T in a tonic::Request