tycode_core/modules/memory/
mod.rs1use std::sync::Arc;
6
7use schemars::schema::RootSchema;
8use schemars::schema_for;
9
10use crate::module::ContextComponent;
11use crate::module::Module;
12use crate::module::PromptComponent;
13use crate::module::SlashCommand;
14pub mod config;
15
16use crate::settings::manager::SettingsManager;
17use crate::tools::r#trait::ToolExecutor;
18pub use config::MemoryConfig;
19
20pub mod background;
21pub mod command;
22pub mod compaction;
23pub mod context;
24pub mod log;
25pub mod prompt;
26pub mod tool;
27
28use command::MemorySlashCommand;
29use context::MemoriesManager;
30use log::MemoryLog;
31use prompt::CompactionPromptComponent;
32use tool::AppendMemoryTool;
33
34pub struct MemoryModule {
40 memory_log: Arc<MemoryLog>,
41 settings: SettingsManager,
42}
43
44impl MemoryModule {
45 pub fn new(memory_log: Arc<MemoryLog>, settings: SettingsManager) -> Self {
46 Self {
47 memory_log,
48 settings,
49 }
50 }
51
52 pub fn memory_log(&self) -> &Arc<MemoryLog> {
53 &self.memory_log
54 }
55}
56
57impl Module for MemoryModule {
58 fn prompt_components(&self) -> Vec<Arc<dyn PromptComponent>> {
59 vec![Arc::new(CompactionPromptComponent::new(
60 self.memory_log.clone(),
61 ))]
62 }
63
64 fn context_components(&self) -> Vec<Arc<dyn ContextComponent>> {
65 vec![Arc::new(MemoriesManager::new(
66 self.memory_log.clone(),
67 self.settings.clone(),
68 ))]
69 }
70
71 fn tools(&self) -> Vec<Arc<dyn ToolExecutor>> {
72 vec![Arc::new(AppendMemoryTool::new(self.memory_log.clone()))]
73 }
74
75 fn slash_commands(&self) -> Vec<Arc<dyn SlashCommand>> {
76 vec![Arc::new(MemorySlashCommand)]
77 }
78
79 fn settings_namespace(&self) -> Option<&'static str> {
80 Some(MemoryConfig::NAMESPACE)
81 }
82
83 fn settings_json_schema(&self) -> Option<RootSchema> {
84 Some(schema_for!(MemoryConfig))
85 }
86}