Skip to main content

ShortTermMemory

Trait ShortTermMemory 

Source
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§

Source

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.

Source

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

Source

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,

Drop all messages for thread.

Provided Methods§

Source

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

Implementors§