Skip to main content

agentlib_core/
memory.rs

1use crate::types::ModelMessage;
2use anyhow::Result;
3use async_trait::async_trait;
4
5#[derive(Debug, Clone, Default)]
6pub struct MemoryReadOptions {
7    pub session_id: Option<String>,
8    pub limit: Option<usize>,
9    pub query: Option<String>,
10    pub tags: Option<std::collections::HashMap<String, String>>,
11}
12
13#[derive(Debug, Clone, Default)]
14pub struct MemoryWriteOptions {
15    pub session_id: Option<String>,
16    pub agent_name: Option<String>,
17    pub tags: Option<std::collections::HashMap<String, String>>,
18}
19
20#[async_trait]
21pub trait MemoryProvider: Send + Sync {
22    async fn read(&self, options: MemoryReadOptions) -> Result<Vec<ModelMessage>>;
23    async fn write(&self, messages: Vec<ModelMessage>, options: MemoryWriteOptions) -> Result<()>;
24    async fn clear(&self, _session_id: Option<&str>) -> Result<()> {
25        Ok(())
26    }
27}