Skip to main content

merlion_memory/
lib.rs

1//! Persistent markdown memory store for the Merlion Agent.
2//!
3//! Manages a directory of small markdown files that the agent uses to
4//! remember things across sessions. Each memory is a single file with YAML
5//! front-matter and a markdown body; an index file (`MEMORY.md`) lists the
6//! memories along with a one-line "hook" used to decide relevance.
7//!
8//! See the crate README / parent project docs for the on-disk format.
9
10use std::path::PathBuf;
11
12use chrono::{DateTime, Utc};
13use serde::{Deserialize, Serialize};
14
15mod parse;
16mod store;
17
18/// Handle to a memory directory on disk.
19pub struct MemoryStore {
20    pub(crate) dir: PathBuf,
21}
22
23/// The "type" tag stored in each memory's front-matter `metadata.type` field.
24#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
25#[serde(rename_all = "lowercase")]
26pub enum MemoryType {
27    User,
28    Feedback,
29    Project,
30    Reference,
31}
32
33/// A single memory: front-matter fields plus the markdown body.
34#[derive(Debug, Clone, Serialize, Deserialize)]
35pub struct Memory {
36    pub name: String,
37    pub description: String,
38    pub kind: MemoryType,
39    pub body: String,
40    pub created_at: DateTime<Utc>,
41    pub updated_at: DateTime<Utc>,
42}
43
44/// One row parsed out of `MEMORY.md`.
45#[derive(Debug, Clone)]
46pub struct MemoryRow {
47    pub name: String,
48    pub title: String,
49    pub hook: String,
50    pub file: String,
51}