diqierjia/StrataGate-AgentMemory74

stratagate-dsh

Recent conversations stay vivid. Older ones fade into summaries, not oblivion. StrataGate gives DeepSeek Harness six-layer, time-decaying memory, while lasting events and relationships settle into a knowledge graph. Bring your memories from other AIs with you—no need to start over.

包名
stratagate-dsh
版本
0.2.64
许可证
MIT
最近更新
2026年9月12日

安装

$npx -p @deepseek-ai/dsh dsh plugin --profile web add github:diqierjia/StrataGate-AgentMemory

StrataGate Agent Memory banner

StrataGate

Long-term memory that keeps the original evidence.

StrataGate helps long-running AI agents remember across sessions without turning every remembered detail into an unquestioned fact.

CI npm version npm downloads License: MIT TypeScript Awesome DSH Plugin Contributions welcome

中文说明 · DeepSeek Harness guide · Architecture · Full evaluation

Current public result: on LoCoMo conv-26, StrataGate averaged 80.46% across 10 independent Judge runs, versus 63.22% for Mem0 base. See the scope and protocol.

In plain words: StrataGate remembers what happened, keeps where it came from, and checks whether the recalled information is enough before an agent relies on it.

Why StrataGate?

  • Automatic, local-first memory across sessions. Completed main-agent conversations and tool results are captured in a local SQLite database without a separate memory server. → Quick start
  • Layered context that stays small. Recent history remains detailed; older history becomes a compact index and expands only when the agent needs more evidence. → Layered memory
  • Events that keep source and time. A lasting memory records where it came from and separates when something was mentioned from when it happened. → Event cards
  • A knowledge graph for what is true now. Traceable Events can be projected into the current state of people, projects, organizations, tools, and places. → Current-state graph
  • Evidence checked before answering. A relevant result is not automatically treated as sufficient; the agent may need to search again, expand a result, or inspect the original messages. → Evidence gate
  • No self-reinforcing search loop. Merely retrieving a memory does not strengthen it; only evidence actually used in the final answer can update long-term weight. → Use-only reinforcement
  • Memory import without losing the original text. Structured memory exported by another AI can become traceable Events while the imported source remains preserved. → External memory import

Choose your path

PathBest forStart here
DeepSeek Harness pluginUsers who want automatic, local-first memory with a visual Memory UIInstall stratagate-dsh
Core TypeScript libraryDevelopers building a custom agent or memory integrationLibrary entry points

Quick start: DeepSeek Harness

If DeepSeek Harness is already installed, add StrataGate to the profile you use:

dsh plugin --profile web add stratagate-dsh

Restart that profile, then keep using DSH normally. StrataGate will capture completed main-agent turns, build searchable memory in the background, and expose its Memory UI under DSH Settings → StrataGate-AgentMemory.

By default, the database is stored at:

DSH_HOME/stratagate/memory.db

Removing the plugin does not delete the database. For screenshots, configuration, memory tools, and the exact automatic-capture rules, see the DeepSeek Harness plugin guide.

The problem behind the design

A long-running agent needs more than a way to “store more.” When it answers, it must retrieve evidence that is correct, complete, and verifiable.

Keeping only summaries can lose dates, qualifications, and original wording. Similarity search can return related material that belongs to a different event. Treating every search hit as useful memory can also create a self-reinforcing retrieval loop.

StrataGate designs long-term memory around four core problems:

Common problemHow StrataGate handles it
History keeps growing and no longer fits in contextStore conversations as L0–L5 layered views; older memories default to shallower levels
A summary omits a date, exact wording, or qualificationPreserve the L5 source messages permanently, so every derived memory can return to its source
Search finds related material, but not enough evidence to answerUse an evidence gate to judge sufficiency; if evidence is incomplete, change strategy, expand an event, or inspect the source
Frequently retrieved results keep reinforcing themselvesUpdate long-term weight only for memories that the final answer actually uses

StrataGate is not designed to make an agent retrieve more on every turn. It is designed to make the agent know whether the current evidence is sufficient and where to look next.

Experimental results

The current public comparison covers LoCoMo conv-26:

  • 419 messages;
  • 35 sessions;
  • 152 category 1–4 questions;
  • 10 independent Judge evaluations per question.
MetricStrataGateMem0 baseDifference
Mean accuracy across 10 Judge runs80.46%63.22%+17.24 percentage points
Majority-correct121 / 152 (79.61%)96 / 152 (63.16%)+25 questions
Temporal74.86%34.59%+40.27 percentage points
Single-hop89.29%75.14%+14.14 percentage points
Multi-hop66.56%61.56%+5.00 percentage points
Open-domain83.08%84.62%-1.54 percentage points

The largest difference is in temporal questions. This is consistent with StrataGate's design—explicit event occurrence times, preserved source timestamps, and raw-source verification—but it is not a single-component ablation, so the full gap cannot be attributed to one field or retrieval step.

Both systems used the same questions, order, answer model, Judge model, Judge prompt, parser, and repeat count, and both rebuilt memory from scratch. Their memory extraction, retrieval implementation, embedding, and answer context differed, so this comparison is between two complete system configurations.

This is a single-conversation comparison on conv-26, not a full LoCoMo score. For the complete protocol, per-question results, Judge variation, and artifact hashes, see:

How it works

StrataGate workflow: layered memory, event cards, and the evidence gate

The normal path is deliberately simple:

  1. Keep the source. Completed messages and tool results are stored locally before anything is summarized.
  2. Build smaller views. StrataGate creates layered summaries, Events that describe what happened, and graph facts that describe the current state.
  3. Search small records first. The agent starts with compact results and expands an Event, graph node, or source Block only when it needs more detail.
  4. Check before answering. The evidence gate decides whether the result is sufficient. If not, the agent searches again or returns to the original messages.
  5. Reinforce only what helped. A memory gains long-term weight only after the final answer actually uses it.

For example, if a user says “Use pnpm for this project,” StrataGate keeps the original turn, creates a traceable Event, and can later expose “the project uses pnpm” as compact context. If an answer depends on the exact wording or surrounding discussion, the agent can expand that Event back to the source instead of trusting the shortened version alone. See a complete retrieval example.

Core design

1. Layered memory: compressed views without losing the source

By default, every 12 complete conversation turns are sealed into one memory block. Messages that have not yet reached the boundary remain in the open tail and are not compressed or extracted early.

This is the core-library default. The DeepSeek Harness plugin defaults to 6 turns per Block so Event extraction becomes available sooner, and exposes blockTurnSize as a user setting. Block age is the distance from the latest ready Block in the same thread, so open-tail and model-pending Blocks do not cause decay. The default Block-decay coefficient is 0.30.

Each sealed block contains six levels of detail:

LevelContentsPrimary use
L0Title and tagsA lightweight index for distant memories
L1Short summaryQuickly judge whether a piece of history is relevant
L2Key factsA compact factual list
L3Deterministically pruned conversationRemove narrowly defined redundancy without free-form semantic rewriting
L4Readable near-verbatim conversationVerify natural-language context and tool results
L5Complete messages and tool recordsFinal source

At the boundary, StrataGate first seals permanent L5 together with deterministic L4 and L3, before any model call. The Block remains model-pending—and cannot replace native conversation history or participate in decay—until validated L0–L2 and Event processing complete. Ready Blocks then decay toward shallower levels as more ready Blocks follow; deeper detail can be expanded again when needed.

L0–L4 are derived views of the same source. They never overwrite or rewrite L5. Event cards likewise reference their source blocks and cannot modify them.

This lets StrataGate satisfy two goals at once:

  • old memories remain lightweight;
  • every important conclusion can still be verified against the original messages.

2. Event cards: store content, source, and time together

Decisions, preferences, plans, corrections, and temporal events that are worth finding later are organized into event cards.

Each event card stores more than a summary:

{
  sourceBlockId,
  sourceMessageIds,

  mentionedAt,
  happenedStart,
  happenedEnd,

  status,
  participants,
  eventType,

  supersedesEventIds,
  conflictsWithEventIds
}

In this structure:

  • mentionedAt is when the event was mentioned in the conversation;
  • happenedStart / happenedEnd describe when it actually happened or is expected to happen;
  • status distinguishes completed, planned, cancelled, and ongoing events;
  • supersedesEventIds and conflictsWithEventIds preserve corrections and conflicts.

Separating mention time from occurrence time prevents the system from treating a message timestamp as the event timestamp. It also gives the system enough information to resolve relative expressions such as “last week” and “next month.”

After L0–L2 validates, Event extraction runs independently without waiting for block N+1. The extractor may read the previous Block and the nearest available later ready Block as context, but every new fact and source reference must come from target block N.

3. Current-state graph and auditable retrieval

Event cards preserve what happened. StrataGate can derive the current state of people, projects, organizations, tools, and places as Graph Nodes and directed Graph Edges. The DeepSeek Harness integration uses this graph-native path.

Graph projection runs as an independent, persisted job. A failed projection can be retried without extracting its Events again. A proposed fact or relationship is accepted only when its cited Events belong to the projection batch, so a derived claim cannot lose its source. State changes close or supersede the earlier derived fact without rewriting the Event that produced it.

searchEvents() combines deterministic BM25 lexical ranking with structured rankings for participants, types, names, and time; reciprocal-rank fusion combines those lists. searchGraphNodes() uses field-weighted BM25 across names, aliases, tags, state, facts, and relations. Searches return compact facts rather than entire large records, and a zero lexical match does not produce arbitrary candidates. These paths use deterministic lexical and structured signals rather than vector or semantic retrieval.

4. Evidence gate: relevant does not mean sufficient

A conventional retrieval system often hands several similar results directly to the answer model. StrataGate inserts a fixed protocol between retrieval and answering:

verdict · evidence_refs · fit · missing · next_strategy

After every retrieval, the system must answer five questions explicitly:

  • is the current evidence sufficient, partial, or wrong;
  • which results actually support that judgment;
  • how the evidence matches the question;
  • what is still missing;
  • should the next step answer, continue searching, expand an event, or inspect the original messages.

The system accepts sufficient only when all of the following are true:

  1. at least one evidence item comes from the selected retrieval batch;
  2. next_strategy is explicitly answer;
  3. the judgment uses a fixed, bounded structure instead of an ever-growing private retrieval scratchpad.

If the judgment is partial or wrong, the system can choose:

search_events
expand_event
search_graph
expand_graph_node
search_raw_memory
expand_block

The evidence gate does not run the entire agent loop for the application. StrataGate supplies state, constraints, and validation; the integrating application still controls model calls, tool iteration, and the maximum retrieval budget.

5. Separate retrieval from reinforcement

An event being retrieved does not mean that it helped the answer.

Search therefore updates only observable retrieval records; it does not directly increase memory weight. After the answer is complete, the application explicitly calls:

await memory.recordMemoryUse({ eventIds, elementIds });

Only Events, or the source Events behind adopted graph evidence, update their long-term weight. Legacy Element evidence remains supported by integrations that still use it.

This avoids a common feedback loop:

A memory happens to rank highly
        ↓
It is retrieved frequently
        ↓
Its weight keeps increasing
        ↓
It becomes even more likely to rank highly

A new event can supersede an old one, while the old event and its source remain available. Forgetting can remove an event from search without breaking the provenance chain.

6. Import memory from another AI

importExternalMemory() can migrate a structured memory summary produced by another AI. The core API extracts candidate Events, compares each candidate with a bounded set of existing Events, and lets a model choose one of five actions: add, merge, supersede, mark a conflict, or ignore. Imported text is also retained as a permanent source Block, so every accepted Event remains traceable to the exact import.

The exported prompt and parser use the stratagate.external-memory.v2 format. Unknown dates remain unknown: the importer pre