Skip to main content
Normalized for Mintlify from knowledge-base/neurigraph-memory-architecture/neurigraph-tool-references/06-Hierarchical-Agentic-Memory-Auto-Taxonomy.mdx.

Clean-Room Specification: Hierarchical Agentic Memory with LLM-Driven Auto-Taxonomy

Purpose of This Document

This document specifies the complete architecture of a hierarchical memory system that uses LLM agents to automatically organize, chunk, and retrieve information. Instead of fixed schemas or vector databases, the system uses LLM reasoning to: (1) chunk documents intelligently, (2) generate structured memory summaries, (3) create and maintain a hierarchical taxonomy as a directory tree, and (4) navigate that tree at query time using tool-based exploration. All memories are stored as Markdown files in a filesystem hierarchy, with README files at each level describing the contents. This specification is detailed enough that a professional AI coding model can produce a functionally identical working system without reference to any existing codebase.

1. System Overview

1.1 Core Concept

Traditional memory systems use embedding-based retrieval. This system instead leverages LLM reasoning for both storage and retrieval:
  • Storage: An LLM reads input text, generates structured memory summaries, and decides where to place them in a directory hierarchy
  • Retrieval: An LLM agent navigates the directory tree using filesystem tools (ls, cat, grep), reading README files to decide which paths to explore
The filesystem IS the memory structure. No database. No vector store. The hierarchy itself provides the organizational semantics.

1.2 Architecture

1.3 Key Design Principles

  1. LLM-native organization: The LLM decides the taxonomy structure, not hard-coded rules
  2. Filesystem as database: Directory tree = taxonomy, files = memories, READMEs = indexes
  3. Agentic retrieval: A reasoning agent navigates the tree at query time, not a similarity search
  4. Separation of concerns: Tree (read-only view), Workspace (write operations), Generator (LLM calls)
  5. Incremental updates: New content can be added without rebuilding the entire taxonomy

2. Data Model

2.1 FSNode (In-Memory Tree Node)

2.2 MemorizedChunk (Memory Unit)

Markdown serialization (each chunk becomes a .md file):

2.3 DirectoryNode (Taxonomy Planning)

Constraint: Every chunk index must appear in exactly ONE leaf directory. Parent directories have empty chunk_indices — they only contain subdirectories.

2.4 GAM Metadata File

Stored at <gam_dir>/.gam_meta.json:

2.5 ChatResult (Query Response)


3. Filesystem Storage Structure

3.1 Directory Layout

3.2 README Format

Each directory contains a README.md describing its contents:
The README serves as a navigation index for the exploration agent — it reads the README to decide which subdirectories to explore.

4. LLM Generator

4.1 Interface

4.2 OpenAI-Compatible Implementation

Retry logic: 20 attempts with 20-second exponential backoff on API errors. Batch processing: Uses concurrent.futures.ThreadPoolExecutor with configurable worker count. Structured output: When a schema parameter is provided, the generator uses OpenAI’s JSON schema response format to ensure valid structured output. On parse failure, uses a JSON repair library to fix common issues.

4.3 LLM Prompt Templates

Memory Generation Prompt

Batch Organization Prompt

Chunk Assignment Prompt (Incremental)

README Generation Prompt


5. Memory Building Pipeline (GAM Agent)

5.1 Full Build (Empty GAM)

When adding content to an empty GAM directory: Step 1 — Input Resolution:
  • Accept file paths (PDF, TXT, MD) or raw text strings
  • Extract text from PDFs using a PDF parser
  • Concatenate all input into a single text corpus
Step 2 — Chunking:
  • Count total tokens using a tokenizer (tiktoken)
  • If total tokens > max_chunk_tokens: split into chunks
  • Chunking algorithm (see Section 5.2)
Step 3 — Memory Generation (Parallel):
  • For each chunk, call LLM with memory generation prompt
  • Use ThreadPoolExecutor for parallel processing
  • Collect MemorizedChunk objects with index, title, memory, tldr
Step 4 — Taxonomy Organization:
  • Send all chunk summaries (index, title, tldr) to LLM
  • LLM returns a DirectoryNode tree
  • Validate: every chunk index appears in exactly one leaf
Step 5 — Filesystem Write:
  • Create directory structure
  • Write each chunk as {title}.md in its assigned directory
  • Generate README.md at each directory level via LLM
Step 6 — Metadata:
  • Write .gam_meta.json with creation info

5.2 Chunking Algorithm

5.3 Incremental Add (Existing GAM)

When adding new content to an existing taxonomy: Step 1-3: Same as full build (resolve input, chunk, generate memories) Step 4 — Placement Decision: For each new chunk:
  1. Load current taxonomy structure (directory tree + READMEs)
  2. Ask LLM: “Which existing directory best fits this chunk?”
  3. If good fit found: place chunk in that directory
  4. If no good fit: create new directory
Step 5 — Reorganization Check: If any directory exceeds a threshold (e.g., 10+ chunks):
  1. Ask LLM to re-plan the taxonomy for that subtree
  2. Compute file movements needed
  3. Execute movements (rename/move files)
  4. Update affected README files
Step 6: Update metadata

5.4 ReorganizeOperation


6. Retrieval Pipeline (Chat Agent)

6.1 Agent Loop

The chat agent is an LLM with access to filesystem tools. It explores the GAM tree to answer queries.

6.2 Exploration Guidelines (System Prompt)

6.3 Tool Definitions

ls — List Directory

Returns: List of files and subdirectories with types and sizes.

cat — Read File

Returns: Full file content as string.

grep — Search Files

Returns: List of matching files with line numbers and matched content.

bm25_search — Full-Text Search (Optional)

Implementation: Uses a BM25 index (Pyserini/Lucene-based) built over all .md files in the GAM directory. The index is lazily built on first search and cached. Returns: Ranked list of file paths with relevance scores and content snippets.

answer — Provide Final Answer


7. Workspace Layer

7.1 Local Workspace

7.2 Docker Workspace (Optional)

For sandboxed execution:

8. GAM Tree (Read-Only View)

8.1 Tree Construction

8.2 Tree Operations


9. Workflow API

9.1 Public Interface

9.2 CLI Entry Points


10. Configuration

10.1 Environment Variables

10.2 Chunk Configuration


11. Behavioral Test Specifications

11.1 Memory Building Tests

11.2 Retrieval Tests

11.3 Tool Execution Tests

11.4 Edge Case Tests


12. Dependencies

12.1 Required

12.2 Optional


13. Project Structure


14. Key Algorithm: Taxonomy Validation


This specification provides complete architectural and behavioral detail for independent implementation of a hierarchical agentic memory system with LLM-driven auto-taxonomy, filesystem storage, and multi-strategy retrieval.