Jump to content

Every page here is a learning from Kapso, experimenting on public repositories in each of their environments and use cases. Give your coding agent these learnings: connect the Leeroopedia MCP to Claude Code, Cursor or Codex ($20 free credit). Powered by Leeroo · founders@leeroo.com

Implementation:1jehuang Jcode MemoryManager

From Leeroopedia
Knowledge Sources
Domains Memory_Systems, Information_Retrieval
Last Updated 2026-10-18 00:00 GMT

Overview

Concrete tool for storing and retrieving persistent agent memories from disk in project-scoped and global JSON files, provided by the jcode base crate.

Description

The MemoryManager struct manages the local storage of agent memories. It supports two scopes: project-scoped (stored in projects/<hash>.json) and global (stored in global.json). Memories are stored as MemoryEntry records with a state machine (active, injected, known), category, trust level, and tags. The manager provides APIs for saving, loading, searching, and extracting memories from transcripts.

Usage

  • Store memories: Create with MemoryManager::new() or with_project_dir(dir), then save graphs.
  • Load memories: Load project or global graphs to access active memories.
  • Test mode: Use MemoryManager::new_test() for isolated test storage.

Code Reference

Source Location

  • Repository: jcode
  • File: crates/jcode-base/src/memory.rs

Signature

pub struct MemoryManager { /* private fields */ }

impl MemoryManager {
    pub fn new() -> Self
    pub fn with_project_dir(project_dir: impl Into<PathBuf>) -> Self
    pub fn with_skills(self, include_skills: bool) -> Self
    pub fn new_test() -> Self

    pub fn save_project_graph(&self, graph: &MemoryGraph) -> Result<()>
    pub fn save_global_graph(&self, graph: &MemoryGraph) -> Result<()>
    pub fn load_project_graph(&self) -> Result<MemoryGraph>
    pub fn load_global_graph(&self) -> Result<MemoryGraph>

    pub async fn extract_from_transcript(
        &self,
        transcript: &str,
        session_id: &str,
    ) -> Result<Vec<String>>
}

Import

use jcode_base::memory::MemoryManager;

I/O Contract

Inputs

Name Type Required Description
project_dir PathBuf No Working directory for project-scoped storage
graph MemoryGraph Yes (save) Memory graph to persist
transcript &str Yes (extract) Conversation transcript for memory extraction
session_id &str Yes (extract) Session ID for extraction tracking

Outputs

Name Type Description
load MemoryGraph /// Loaded graph with active/injected/known memories
extract Result<Vec<String>> /// IDs of extracted memory entries
files disk /// projects/<hash>.json and global.json

Usage Examples

Store and Load Project Memories

use jcode_base::memory::MemoryManager;

let manager = MemoryManager::new().with_project_dir("/project");

// Load existing memories
let graph = manager.load_project_graph()?;
for entry in graph.active_memories() {
    println!("{}: {}", entry.id, entry.content);
}

// Add and save a new memory
graph.add(MemoryEntry::new(
    "Always use async/await in this project".to_string(),
    MemoryCategory::Feedback,
    TrustLevel::High,
));
manager.save_project_graph(&graph)?;

Extract from Transcript

let manager = MemoryManager::new().with_project_dir("/project");
let ids = manager.extract_from_transcript(&transcript, "session-123").await?;
println!("Extracted {} memories", ids.len());

Related Pages

Implements Principle

Requires Environment

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment