use std::sync::Arc;
use agent_base::{Tool, ToolContext};
use crate::memory::MemoryStore;
mod memory_delete;
mod memory_list;
mod memory_read;
mod memory_write;
pub use memory_delete::MemoryDeleteTool;
pub use memory_list::MemoryListTool;
pub use memory_read::MemoryReadTool;
pub use memory_write::MemoryWriteTool;
pub const MEMORY_TOOLS_DESCRIPTION: &str = "\
- `memory_write(name, description, type, body)` — create or update one memory and sync the index.
- `memory_read(name, offset_chars?, limit_chars?)` — read one memory's content (paginated; use offset_chars to continue).
- `memory_list()` — return the current index (refreshes the stale startup snapshot).
- `memory_delete(name)` — delete a memory and remove its index line.";
pub fn create_memory_tools(store: Arc<MemoryStore>) -> Vec<Arc<dyn Tool>> {
vec![
Arc::new(MemoryWriteTool::new(Arc::clone(&store))),
Arc::new(MemoryReadTool::new(Arc::clone(&store))),
Arc::new(MemoryListTool::new(Arc::clone(&store))),
Arc::new(MemoryDeleteTool::new(store)),
]
}
fn session_ref(ctx: &ToolContext) -> String {
ctx.session_id
.external_id
.clone()
.unwrap_or_else(|| ctx.session_id.id.to_string())
}
#[cfg(test)]
pub(crate) mod test_support {
use super::*;
use agent_base::Content;
pub(crate) fn first_text(out: &[Content]) -> String {
match out.first() {
Some(Content::Text { text }) => text.clone(),
_ => String::new(),
}
}
pub(crate) fn ctx_with_external_id(id: &str) -> ToolContext {
let mut ctx = ToolContext::for_test();
ctx.session_id.external_id = Some(id.to_string());
ctx
}
}