pub trait ShortTermMemory: Send + Sync {
// Required methods
fn append<'life0, 'async_trait>(
&'life0 self,
thread: ThreadId,
msg: Message,
) -> Pin<Box<dyn Future<Output = Result<(), MemoryError>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait;
fn load<'life0, 'async_trait>(
&'life0 self,
thread: ThreadId,
max_tokens: usize,
) -> Pin<Box<dyn Future<Output = Result<Vec<Message>, MemoryError>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait;
fn clear<'life0, 'async_trait>(
&'life0 self,
thread: ThreadId,
) -> Pin<Box<dyn Future<Output = Result<(), MemoryError>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait;
// Provided method
fn append_batch<'life0, 'async_trait>(
&'life0 self,
thread: ThreadId,
messages: Vec<Message>,
) -> Pin<Box<dyn Future<Output = Result<(), MemoryError>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait { ... }
}Expand description
Conversation buffer scoped to a single thread.
use klieo_core::test_utils::InMemoryShortTerm;
use klieo_core::{ShortTermMemory, Message, Role, ThreadId};
let m = InMemoryShortTerm::default();
let thread = ThreadId::new("t1");
m.append(thread.clone(), Message {
role: Role::User, content: "hi".into(),
tool_calls: vec![], tool_call_id: None,
}).await.unwrap();
let loaded = m.load(thread, 1024).await.unwrap();
assert_eq!(loaded.len(), 1);Required Methods§
Sourcefn append<'life0, 'async_trait>(
&'life0 self,
thread: ThreadId,
msg: Message,
) -> Pin<Box<dyn Future<Output = Result<(), MemoryError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn append<'life0, 'async_trait>(
&'life0 self,
thread: ThreadId,
msg: Message,
) -> Pin<Box<dyn Future<Output = Result<(), MemoryError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Append a message to the thread’s history.
Sourcefn load<'life0, 'async_trait>(
&'life0 self,
thread: ThreadId,
max_tokens: usize,
) -> Pin<Box<dyn Future<Output = Result<Vec<Message>, MemoryError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn load<'life0, 'async_trait>(
&'life0 self,
thread: ThreadId,
max_tokens: usize,
) -> Pin<Box<dyn Future<Output = Result<Vec<Message>, MemoryError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Load up to max_tokens of the most-recent messages, oldest first.
Implementations approximate token counts (provider-specific).
Provided Methods§
Sourcefn append_batch<'life0, 'async_trait>(
&'life0 self,
thread: ThreadId,
messages: Vec<Message>,
) -> Pin<Box<dyn Future<Output = Result<(), MemoryError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn append_batch<'life0, 'async_trait>(
&'life0 self,
thread: ThreadId,
messages: Vec<Message>,
) -> Pin<Box<dyn Future<Output = Result<(), MemoryError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Append a batch of messages, oldest first. The default appends each in turn; backends with bulk-insert support should override to collapse the N writes into one round-trip (the resume path replays a full history).
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".