memU Agent-Driven Memory System

repository·main·Indexed 12 days ago

https://github.com/nevamind-ai/memu

A lightweight memory system providing a shared LLM wiki across sessions, agents, and devices. It enables AI agents to automatically extract, store, and retrieve reusable 'skills' from interaction history. Includes the memu-cli (v2.0.0-beta.0) for managing personal memory via local SQLite or MemU Cloud, and host-specific adapters for agents like Claude Code, Cursor, and Codex.

Tokens
63K
Snippets
184
Records
273
Agent score
95%

What's inside memU

  1. Understand Client Event Reporting provenance

    main

    Events reported by the memu-cli are categorized by their provenance using the context.reported_by field. This field is a fact about how the event was generated and is located in the context object, not in properties.

    • code: Events observed and emitted directly by the CLI logic (e.g., an unhandled exception or a successful store call).
    • agent: Events reported voluntarily by an AI agent (e.g., an agent deciding a task has failed and calling a report command).

    Distinguishing between these allows developers to separate "failures the code observed" from "failures a model reported."

  2. Understand the RecallFile and RecallEntry data model

    main

    The project uses a unified vocabulary for its memory and skill storage. The core entities are:

    • RecallFile: A top-level container (formerly MemoryCategory). It represents a category or a skill. It includes a track column to distinguish between types and a content column (formerly summary) for the body text.
    • RecallFileEntry: An item within a RecallFile (formerly CategoryItem).
    • RecallEntry: A specific piece of data (formerly MemoryItem). Note that RecallEntry still uses the field name summary for its content, even though RecallFile was renamed to content.

    Tracks:

    • track="memory": Standard categorized memory.
    • track="skill": Synthesized skills generated during the workspace memorization workflow.
  3. How pagination works in memU

    main

    Pagination in memU is designed to be identical across both local (in-process) and cloud (HTTP) execution paths.

    1. Source of Truth: The pagination logic (page size, ordering, and cursor encoding) lives in the AgenticMixin. This ensures that the cloud client and the memu-service server always see the same data shape.
    2. Keyset Resumption: To prevent data drift (skipping or duplicating rows during concurrent writes), memU uses keyset pagination. The cursor is an opaque, base64-encoded token representing the tuple (track, name, id).
    3. Efficiency: Instead of slicing a full list in memory, the repository performs a bounded query: WHERE scope AND (track,name,id) > cursor ORDER BY track,name,id LIMIT n+1. This allows the database to seek directly to the next page without scanning the entire table.
  4. How the memU bridging pipeline works

    main

    The bridging pipeline is an idempotent, incremental process that turns Hermes sessions into durable memU assets.

    Pipeline Stages

    • Prepare: Scans ~/.hermes/state.db for new messages using a per-session message-count cursor stored in ~/.memu/hosts/hermes/.session_manifest.hermes.json. It snapshots current memory/skills and writes numbered job files (e.g., 1.txt) to ~/.memu/hosts/hermes/jobs/.
    • Self-evolve: The agent acts as the engine here. It reads job files in ascending numeric order and performs the actual work: mining sessions into memory, mining sessions into skills, and describing touched files.
    • Commit: memu-hermes commit diffs the working directories against the snapshot taken during the Prepare stage and submits changes to the memU backend.

    Key Design Principles

    • Ordering: The pipeline is load-bearing; it must process memory jobs, then skill jobs, then resource-describe jobs in ascending numeric order.
    • Atomicity & Locking: A single-instance lock is used via mkdir in ~/.memu/hosts/hermes/.bridge.lock. A stale lock older than 3 hours is automatically reclaimed to prevent a crashed run from blocking the schedule forever.
    • Scope: The working tree is host-scoped under ~/.memu/hosts/hermes/. The backend storage (local vs cloud) is determined by MEMU_MEMORY_MODE in ~/.memu/config.env.
  5. Understand the three memory lines: memory, skill, and project

    main

    memU distills information from an agent's trajectory (user turns + agent actions/tool traces) into three distinct types of memory, known as 'lines'. Each line has its own folder for human-readable documents (L1) and a dedicated embedding index for searchable units (L2).

    LineWhat it capturesL0 (Source Projection)L1 (Output Folder)
    memoryUser facts, preferences, and conversational contextUser queries and agent responses onlymemory/
    skillReusable procedures and how tasks were accomplishedThe entire user–agent trajectory (turns + traces)skill/
    projectProject state and files touched during workContents of files touched in the trajectoryproject/

    Key Concept: Extraction vs. Routing Instead of you manually sorting files into folders, you provide the raw trajectory. The memU pipeline performs semantic extraction, meaning a single interaction can simultaneously yield a new memory fact, a new skill, and a project update.

  6. How the memU bridging task works

    main

    The memU bridging task is a recurring headless Claude Code run that periodically converts recent Claude Code sessions into durable memU memory, skills, and resource submissions. It operates via a three-step pipeline:

    1. Prepare: memu-claude-code prepare scans new turns in ~/.claude/projects, mirrors current memU recall files to ~/.memu/hosts/claude-code/memory and ~/.memu/hosts/claude-code/skill (using content hashes), and generates numbered job-instruction files in ~/.memu/hosts/claude-code/jobs/ (e.g., 1.txt, 2.txt).
    2. Self-evolve: The agent (Claude) processes each job file in numeric order. It mines sessions into user memory or skills and describes files touched. "Do nothing" is a valid outcome.
    3. Commit: memu-claude-code commit diffs the tracked directories against the step-1 snapshot and submits the changes to memU.

    Note: Step 2 is performed by the agent following instructions in the job files, not by executing a shell script.

  7. How memU automatic skill extraction works

    main

    memU turns agent history into reusable Markdown skills through a six-step pipeline:

    1. Capture new sessions: The host adapter reads session history (messages and tool calls).
    2. Prepare self-evolve jobs: prepare slices sessions into self-contained jobs with necessary context.
    3. Let the agent decide: The agent reads existing skills and decides whether to do nothing, patch an existing skill, or create a new one.
    4. Write readable skill Markdown: Skills are written with a name, description, and reusable workflow (including edge cases and pitfalls).
    5. Commit and index: commit submits changes via commit_results; memU embeds the name/description and stores it under the skill track.
    6. Retrieve it later: On similar future tasks, memU returns the relevant skill for the agent to use.
  8. Integrate unknown agents using the Generic Host Adapter

    main

    For agents that do not have a dedicated memU adapter, you can use the memu-agent binary (from the memu.hosts.generic package). This adapter uses a heuristic approach to integrate with agents by detecting two specific 'seams':

    1. Memorization (Record Seam): Works if the agent logs sessions in one of the ~5 supported JSONL dialects (e.g., Codex, OpenClaw, Claude Code, Cursor, or flat OpenAI-client chat rows).
    2. Retrieval (Inject Seam): Works if the agent uses recognizable instruction files (e.g., AGENTS.md, CLAUDE.md, or SOUL.md).

    Integration can be partial (only memorization or only retrieval) or full (both). The detect command is used to determine which capabilities are available for a specific agent directory.

  9. The memU bridging pipeline steps

    main

    The bridging task follows a specific four-stage lifecycle to ensure data integrity:

    1. LEFTOVERS: If ~/.memu/hosts/codex/jobs/ contains existing files, they are unfinished work from a previous crash. These must be processed and committed before starting a new run to prevent data loss.
    2. PREPARE: Run memu-codex prepare. This scans ~/.codex/sessions, mirrors current recall files, and generates numbered job instruction files (e.g., 1.txt, 2.txt) in ~/.memu/hosts/codex/jobs/.
    3. SELF-EVOLVE: The agent must list and process all ~/.memu/hosts/codex/jobs/*.txt files in ascending numeric order. For each file, the agent reads the instructions (using cat) and performs the requested work (mining memory, mining skills, or describing resources).
    4. COMMIT: Run memu-codex commit. This diffs the changes made during the Self-evolve step and submits the new/changed files and resources to memU.

    Note on Ordering: Processing jobs in ascending order is critical because later jobs (like resource description) depend on files created by earlier jobs (like skill extraction).

  10. Lifecycle events reported by the memU CLI

    main

    The memU CLI reports a fixed set of six lifecycle events to the ingest endpoint to assist in diagnosing silent failures or configuration mismatches:

    1. install completed: Triggered when the installation process finishes.
    2. uninstall: Triggered during uninstallation.
    3. bridging (remember) run finished: Triggered when a bridging task completes.
    4. retrieval: Triggered during a memory retrieval operation.
    5. listing of the store: Triggered when the store contents are listed.
    6. fatal error: Triggered when a critical error occurs.
  11. How the L0/L1/L2 layered data model works

    main

    Every memory line follows a three-layer derivation model. Data flows from raw sources to fine-grained searchable items. This hierarchy ensures that while you search at the most granular level, the results are contextually linked to their parent documents.

    1. L0 (Resource): The raw source material (e.g., raw chat corpus, raw multimodal data, or raw agent logs).
    2. L1 (Document): A coarse document derived from L0 via preprocessing (e.g., a classified memory category, a caption paragraph, or a skill markdown file).
    3. L2 (Item): Fine-grained slices or extracts of the L1 document. L2 items are the actual units used for embedding and search.

    Retrieval Flow: A query searches across L2 items using hybrid retrieval. When a match is found, the system 'rolls up' the result to its parent L1 document (and its L0 resource) to provide full context to the user or agent.

  12. How workflow pipelines work in memU

    main

    memU models its core operations—such as memorize, retrieve, and CRUD/patch operations—as named workflow pipelines. Instead of monolithic functions, these operations are composed of ordered WorkflowStep units.

    Key components of the pipeline architecture include:

    • PipelineManager: Used to register pipelines centrally within the MemoryService.
    • WorkflowRunner: The abstraction responsible for executing the pipeline (defaults to a local runner).
    • WorkflowStep: The individual units of work that make up a pipeline.
    • Interceptors: Support for before, after, and on_error hooks at the step level for instrumentation and control.

    This architecture allows for runtime customization through step-level configuration and structural mutations like inserting, replacing, or removing steps.