How the Top Memory Layer (L3) Is Stored in TencentDB Agent Memory: Architecture and Design
The top L3 memory layer in TencentDB Agent Memory persists as a single, time-agnostic document blob (the core persona) in the Memory Hub's backend storage, enabling instant system prompt injection without vector search overhead.
The TencentDB-Agent-Memory repository implements a four-tier hierarchical memory architecture (L0→L3) that manages conversation context with increasing abstraction levels. Understanding how this top memory layer storage mechanism functions is essential for developers configuring agent personalities and long-term organizational knowledge.
Storage Model for the L3 Core Memory Layer
Single Document Architecture
Unlike lower layers that store fragmented, timestamped memories, L3 is stored as a single, whole-document asset. According to the repository's README.md (lines 985-1002), L3 represents "沉淀的核心准则 / 模板 / 决策" (precipitated core principles, templates, and decisions) and functions as an aggregated product without a time dimension. The system treats this layer as an immutable content blob—typically a markdown file—that contains the agent's core persona and decision frameworks.
Backend Storage Implementation
The L3 document lives in the Memory Hub's backend storage (supporting Cos, SQLite, FS, or in-process memory) within the same VDB table as other memory assets. It is distinguished from L0/L1 layers by its layer value and its time-agnostic nature, explicitly lacking the timestamps or pagination markers present in lower layers. The backend simply stores the full content blob and retrieves it on demand without indexing individual segments.
Design Rationale: Why L3 Uses Whole-Document Storage
Stability and Immutability
L3 captures long-term principles and organizational decisions that rarely change. By storing the top memory layer as a single immutable document, the system avoids the overhead of incremental updates, merge conflicts, and version fragmentation that would occur with granular storage models.
Fast Bootstrapping for Agent Initialization
When a new agent starts, the L3 persona is injected directly into the system prompt. This design enables the agent to "remember" the team's core knowledge instantly without requiring additional retrieval steps or database queries during the initialization phase, significantly reducing cold-start latency.
Eliminating Retrieval Costs
Since L3 exists as a single cohesive piece, the system bypasses expensive vector similarity searches or BM25 lookups entirely. The storage layer simply reads the blob and inserts it directly into the prompt context, reducing computational overhead for retrieving stable, high-level knowledge.
How to Read and Write L3 Memory
Reading the Core Persona via API
Agents obtain L3 content through the GET /v3/core/read endpoint. Internally, the TdaiL3Core client in MemoryProxy/src/tdai/client.ts invokes the readL3() method to fetch the stored content from the Memory Hub.
// Front-end component (MemoryPanel)
const persona = await api.readCore({ layer: 'L3' });
// `persona.content` now holds the whole core memory text
The underlying client implementation handles the HTTP request to the core service:
// MemoryProxy/src/tdai/client.ts
async readL3(identity: TdaiIdentity): Promise<TdaiL3Core | null> {
if (!this.isEnabled() || !this.config.injectL2L3) return null;
return this.http.get<TdaiL3Core>(`${ROOT}/core/read`, { identity });
}
Writing and Updating L3 Content
Updates to the core persona use the POST /v3/core/write endpoint with a JSON payload containing { content: "…" }. The Memory Panel's backend processes these requests in MemoryPanel/src/panel/http/routes/chat-memory.ts (approximately lines 1560-1570), forwarding the payload to the core storage service after sanitization.
// Replace entire core persona
await api.writeCore({
layer: 'L3',
content: '# New Persona\nYou are a senior engineer …'
});
// The API call hits `/v3/core/write` and the backend stores the blob
The backend route handler validates the layer type and processes the content:
// MemoryPanel/src/panel/http/routes/chat-memory.ts
if (layerRaw === 'L3') {
const content = stripL3SceneTail(data.content ?? '');
await coreClient.writeCore({ memory_id: memId, content });
}
Front-end implementations in MemoryPanel/web/src/pages/memory/ChatMemoryPage/components/useChatMemory.ts provide the UI hooks that invoke these API endpoints, abstracting the layer-specific logic from the user interface.
Summary
- L3 uses whole-document storage: The top layer is stored as a single markdown blob rather than fragmented records, distinguishing it from timestamped L0/L1 layers.
- Time-agnostic architecture: Unlike lower layers, L3 contains no temporal metadata or pagination, treating core persona as permanent organizational knowledge.
- Direct prompt injection: The storage model enables immediate retrieval and injection into system prompts without vector search overhead.
- Simple CRUD operations: Reading uses
GET /v3/core/readviareadL3(), while writing usesPOST /v3/core/writewith full-content replacement. - Backend flexibility: L3 persists in Cos, SQLite, FS, or in-memory backends through the Memory Hub's unified VDB table structure.
Frequently Asked Questions
What distinguishes L3 from L0 and L1 memory layers?
L0 and L1 store fragmented, timestamped conversation snippets requiring vector or BM25 search for retrieval. L3 stores a single, time-agnostic document containing core principles and persona definitions that are injected directly into prompts without search operations.
Why doesn't L3 support incremental updates or partial edits?
The architecture treats L3 as an immutable snapshot of organizational knowledge. Full-document replacement ensures atomic updates to the persona and eliminates complexity around merging conflicting principles or managing partial state corruption in long-term memory storage.
How does the system handle L3 content formatting?
The storage layer accepts the content as a raw string blob—typically formatted as markdown—and persists it without structural parsing. The stripL3SceneTail() utility in the write pipeline (used in chat-memory.ts) sanitizes the payload before storage to remove extraneous formatting markers.
What happens if the L3 read operation fails during agent startup?
According to the readL3() implementation in MemoryProxy/src/tdai/client.ts, the method returns null when the service is disabled or when injectL2L3 configuration is false. The agent initializes without the core persona, falling back to default behavioral parameters defined in the base system configuration.
Have a question about this repo?
These articles cover the highlights, but your codebase questions are specific. Give your agent direct access to the source. Share this with your agent to get started:
curl -s "https://instagit.com/install.md" Maintain an open-source project? Get it listed too →