rexis_rag/agent/memory/
config.rs

1//! Memory configuration for agents
2
3use crate::storage::Memory;
4use std::sync::Arc;
5
6/// Configuration for agent memory system
7#[derive(Clone)]
8pub struct MemoryConfig {
9    /// Storage backend (InMemoryStorage, DatabaseStorage, etc.)
10    pub backend: Arc<dyn Memory>,
11
12    /// Unique agent identifier (for agent-scoped memory)
13    pub agent_id: String,
14
15    /// Optional session identifier (for session-scoped memory)
16    pub session_id: Option<String>,
17
18    /// Whether to persist conversation history to storage
19    pub persist_conversations: bool,
20
21    /// Enable semantic memory (facts/knowledge storage)
22    pub enable_semantic: bool,
23
24    /// Enable episodic memory (summarized history)
25    pub enable_episodic: bool,
26
27    /// Enable working memory (temporary scratchpad)
28    pub enable_working: bool,
29
30    /// Maximum conversation length before pruning
31    pub max_conversation_length: usize,
32
33    /// Auto-generate session IDs if not provided
34    pub auto_generate_session_id: bool,
35}
36
37impl MemoryConfig {
38    /// Create a new memory configuration
39    pub fn new(backend: Arc<dyn Memory>, agent_id: impl Into<String>) -> Self {
40        Self {
41            backend,
42            agent_id: agent_id.into(),
43            session_id: None,
44            persist_conversations: false,
45            enable_semantic: false,
46            enable_episodic: false,
47            enable_working: false,
48            max_conversation_length: 50,
49            auto_generate_session_id: true,
50        }
51    }
52
53    /// Set session ID
54    pub fn with_session_id(mut self, session_id: impl Into<String>) -> Self {
55        self.session_id = Some(session_id.into());
56        self
57    }
58
59    /// Enable conversation persistence
60    pub fn with_persistence(mut self, persist: bool) -> Self {
61        self.persist_conversations = persist;
62        self
63    }
64
65    /// Enable semantic memory
66    pub fn with_semantic_memory(mut self, enable: bool) -> Self {
67        self.enable_semantic = enable;
68        self
69    }
70
71    /// Enable episodic memory
72    pub fn with_episodic_memory(mut self, enable: bool) -> Self {
73        self.enable_episodic = enable;
74        self
75    }
76
77    /// Enable working memory
78    pub fn with_working_memory(mut self, enable: bool) -> Self {
79        self.enable_working = enable;
80        self
81    }
82
83    /// Set max conversation length
84    pub fn with_max_conversation_length(mut self, length: usize) -> Self {
85        self.max_conversation_length = length;
86        self
87    }
88
89    /// Enable/disable auto session ID generation
90    pub fn with_auto_session_id(mut self, auto: bool) -> Self {
91        self.auto_generate_session_id = auto;
92        self
93    }
94}
95
96impl Default for MemoryConfig {
97    fn default() -> Self {
98        use crate::storage::InMemoryStorage;
99
100        Self {
101            backend: Arc::new(InMemoryStorage::new()),
102            agent_id: "default".to_string(),
103            session_id: None,
104            persist_conversations: false,
105            enable_semantic: false,
106            enable_episodic: false,
107            enable_working: false,
108            max_conversation_length: 50,
109            auto_generate_session_id: true,
110        }
111    }
112}